| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/security_key/gnubby_extension_session.h" | 5 #include "remoting/host/security_key/gnubby_extension_session.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "remoting/base/logging.h" | 13 #include "remoting/base/logging.h" |
| 14 #include "remoting/host/client_session_details.h" |
| 14 #include "remoting/host/security_key/gnubby_auth_handler.h" | 15 #include "remoting/host/security_key/gnubby_auth_handler.h" |
| 15 #include "remoting/proto/control.pb.h" | 16 #include "remoting/proto/control.pb.h" |
| 16 #include "remoting/protocol/client_stub.h" | 17 #include "remoting/protocol/client_stub.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // Used as the type attribute of all Security Key protocol::ExtensionMessages. | 21 // Used as the type attribute of all Security Key protocol::ExtensionMessages. |
| 21 const char kExtensionMessageType[] = "gnubby-auth"; | 22 const char kExtensionMessageType[] = "gnubby-auth"; |
| 22 | 23 |
| 23 // Gnubby extension message data members. | 24 // Gnubby extension message data members. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 53 } | 54 } |
| 54 } | 55 } |
| 55 return true; | 56 return true; |
| 56 } | 57 } |
| 57 | 58 |
| 58 } // namespace | 59 } // namespace |
| 59 | 60 |
| 60 namespace remoting { | 61 namespace remoting { |
| 61 | 62 |
| 62 GnubbyExtensionSession::GnubbyExtensionSession( | 63 GnubbyExtensionSession::GnubbyExtensionSession( |
| 64 ClientSessionDetails* client_session_details, |
| 63 protocol::ClientStub* client_stub) | 65 protocol::ClientStub* client_stub) |
| 64 : client_stub_(client_stub) { | 66 : client_stub_(client_stub), |
| 67 client_session_details_(client_session_details) { |
| 65 DCHECK(client_stub_); | 68 DCHECK(client_stub_); |
| 69 DCHECK(client_session_details_); |
| 66 | 70 |
| 67 gnubby_auth_handler_ = remoting::GnubbyAuthHandler::Create(base::Bind( | 71 gnubby_auth_handler_ = remoting::GnubbyAuthHandler::Create( |
| 68 &GnubbyExtensionSession::SendMessageToClient, base::Unretained(this))); | 72 base::Bind(&GnubbyExtensionSession::SendMessageToClient, |
| 73 base::Unretained(this)), |
| 74 base::Bind(&GnubbyExtensionSession::GetDesktopSessionId, |
| 75 base::Unretained(this))); |
| 69 } | 76 } |
| 70 | 77 |
| 71 GnubbyExtensionSession::~GnubbyExtensionSession() {} | 78 GnubbyExtensionSession::~GnubbyExtensionSession() {} |
| 72 | 79 |
| 73 // Returns true if the |message| is a Security Key ExtensionMessage. | 80 // Returns true if the |message| is a Security Key ExtensionMessage. |
| 74 // This is done so the host does not pass |message| to other HostExtensions. | 81 // This is done so the host does not pass |message| to other HostExtensions. |
| 75 // TODO(joedow): Use |client_session_details| to disconnect the session if we | 82 // TODO(joedow): Use |client_session_details| to disconnect the session if we |
| 76 // receive an invalid extension message. | 83 // receive an invalid extension message. |
| 77 bool GnubbyExtensionSession::OnExtensionMessage( | 84 bool GnubbyExtensionSession::OnExtensionMessage( |
| 78 ClientSessionDetails* client_session_details, | 85 ClientSessionDetails* client_session_details, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 std::string request_json; | 195 std::string request_json; |
| 189 CHECK(base::JSONWriter::Write(request, &request_json)); | 196 CHECK(base::JSONWriter::Write(request, &request_json)); |
| 190 | 197 |
| 191 protocol::ExtensionMessage message; | 198 protocol::ExtensionMessage message; |
| 192 message.set_type(kExtensionMessageType); | 199 message.set_type(kExtensionMessageType); |
| 193 message.set_data(request_json); | 200 message.set_data(request_json); |
| 194 | 201 |
| 195 client_stub_->DeliverHostMessage(message); | 202 client_stub_->DeliverHostMessage(message); |
| 196 } | 203 } |
| 197 | 204 |
| 205 uint32_t GnubbyExtensionSession::GetDesktopSessionId() const { |
| 206 return client_session_details_->desktop_session_id(); |
| 207 } |
| 208 |
| 198 void GnubbyExtensionSession::SetGnubbyAuthHandlerForTesting( | 209 void GnubbyExtensionSession::SetGnubbyAuthHandlerForTesting( |
| 199 std::unique_ptr<GnubbyAuthHandler> gnubby_auth_handler) { | 210 std::unique_ptr<GnubbyAuthHandler> gnubby_auth_handler) { |
| 200 DCHECK(gnubby_auth_handler); | 211 DCHECK(gnubby_auth_handler); |
| 201 | 212 |
| 202 gnubby_auth_handler_ = std::move(gnubby_auth_handler); | 213 gnubby_auth_handler_ = std::move(gnubby_auth_handler); |
| 203 gnubby_auth_handler_->SetSendMessageCallback(base::Bind( | 214 gnubby_auth_handler_->SetSendMessageCallback(base::Bind( |
| 204 &GnubbyExtensionSession::SendMessageToClient, base::Unretained(this))); | 215 &GnubbyExtensionSession::SendMessageToClient, base::Unretained(this))); |
| 216 gnubby_auth_handler_->SetSessionIdCallback(base::Bind( |
| 217 &GnubbyExtensionSession::GetDesktopSessionId, base::Unretained(this))); |
| 205 } | 218 } |
| 206 | 219 |
| 207 } // namespace remoting | 220 } // namespace remoting |
| OLD | NEW |