OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromoting_host.h" | 5 #include "remoting/host/chromoting_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "remoting/base/constants.h" | 12 #include "remoting/base/constants.h" |
13 #include "remoting/base/encoder.h" | 13 #include "remoting/base/encoder.h" |
14 #include "remoting/base/encoder_row_based.h" | 14 #include "remoting/base/encoder_row_based.h" |
15 #include "remoting/base/encoder_vp8.h" | 15 #include "remoting/base/encoder_vp8.h" |
16 #include "remoting/host/chromoting_host_context.h" | 16 #include "remoting/host/chromoting_host_context.h" |
17 #include "remoting/host/curtain.h" | 17 #include "remoting/host/curtain.h" |
18 #include "remoting/host/desktop_environment.h" | 18 #include "remoting/host/desktop_environment.h" |
19 #include "remoting/host/event_executor.h" | 19 #include "remoting/host/event_executor.h" |
20 #include "remoting/host/host_config.h" | 20 #include "remoting/host/host_config.h" |
21 #include "remoting/host/host_key_pair.h" | |
22 #include "remoting/host/screen_recorder.h" | 21 #include "remoting/host/screen_recorder.h" |
23 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 22 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
24 #include "remoting/protocol/connection_to_client.h" | 23 #include "remoting/protocol/connection_to_client.h" |
25 #include "remoting/protocol/client_stub.h" | 24 #include "remoting/protocol/client_stub.h" |
26 #include "remoting/protocol/host_stub.h" | 25 #include "remoting/protocol/host_stub.h" |
27 #include "remoting/protocol/input_stub.h" | 26 #include "remoting/protocol/input_stub.h" |
28 #include "remoting/protocol/jingle_session_manager.h" | 27 #include "remoting/protocol/jingle_session_manager.h" |
29 #include "remoting/protocol/session_config.h" | 28 #include "remoting/protocol/session_config.h" |
| 29 #include "remoting/protocol/v1_authenticator.h" |
30 | 30 |
31 using remoting::protocol::ConnectionToClient; | 31 using remoting::protocol::ConnectionToClient; |
32 using remoting::protocol::InputStub; | 32 using remoting::protocol::InputStub; |
33 | 33 |
34 namespace remoting { | 34 namespace remoting { |
35 | 35 |
36 // static | 36 // static |
37 ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context, | 37 ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context, |
38 MutableHostConfig* config, | 38 MutableHostConfig* config, |
39 DesktopEnvironment* environment, | 39 DesktopEnvironment* environment, |
(...skipping 30 matching lines...) Expand all Loading... |
70 } | 70 } |
71 | 71 |
72 LOG(INFO) << "Starting host"; | 72 LOG(INFO) << "Starting host"; |
73 DCHECK(!signal_strategy_.get()); | 73 DCHECK(!signal_strategy_.get()); |
74 | 74 |
75 // Make sure this object is not started. | 75 // Make sure this object is not started. |
76 if (state_ != kInitial) | 76 if (state_ != kInitial) |
77 return; | 77 return; |
78 state_ = kStarted; | 78 state_ = kStarted; |
79 | 79 |
| 80 // Assign key and certificate to server. |
| 81 if (!key_pair_.Load(config_)) { |
| 82 LOG(ERROR) << "Failed to load key pair for the host."; |
| 83 return; |
| 84 } |
| 85 |
80 // Use an XMPP connection to the Talk network for session signalling. | 86 // Use an XMPP connection to the Talk network for session signalling. |
81 std::string xmpp_login; | 87 std::string xmpp_login; |
82 std::string xmpp_auth_token; | 88 std::string xmpp_auth_token; |
83 std::string xmpp_auth_service; | 89 std::string xmpp_auth_service; |
84 if (!config_->GetString(kXmppLoginConfigPath, &xmpp_login) || | 90 if (!config_->GetString(kXmppLoginConfigPath, &xmpp_login) || |
85 !config_->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token) || | 91 !config_->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token) || |
86 !config_->GetString(kXmppAuthServiceConfigPath, &xmpp_auth_service)) { | 92 !config_->GetString(kXmppAuthServiceConfigPath, &xmpp_auth_service)) { |
87 LOG(ERROR) << "XMPP credentials are not defined in the config."; | 93 LOG(ERROR) << "XMPP credentials are not defined in the config."; |
88 return; | 94 return; |
89 } | 95 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } else { | 154 } else { |
149 ShutdownFinish(); | 155 ShutdownFinish(); |
150 } | 156 } |
151 } | 157 } |
152 | 158 |
153 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { | 159 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { |
154 DCHECK_EQ(state_, kInitial); | 160 DCHECK_EQ(state_, kInitial); |
155 status_observers_.push_back(observer); | 161 status_observers_.push_back(observer); |
156 } | 162 } |
157 | 163 |
| 164 void ChromotingHost::SetSharedSecret(const std::string& shared_secret) { |
| 165 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 166 session_manager_->set_authenticator_factory( |
| 167 new protocol::V1HostAuthenticatorFactory( |
| 168 key_pair_.GenerateCertificate(), key_pair_.CopyPrivateKey(), |
| 169 shared_secret)); |
| 170 } |
| 171 |
158 //////////////////////////////////////////////////////////////////////////// | 172 //////////////////////////////////////////////////////////////////////////// |
159 // protocol::ClientSession::EventHandler implementation. | 173 // protocol::ClientSession::EventHandler implementation. |
160 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { | 174 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { |
161 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 175 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
162 | 176 |
163 // Disconnect all other clients. | 177 // Disconnect all other clients. |
164 // Iterate over a copy of the list of clients, to avoid mutating the list | 178 // Iterate over a copy of the list of clients, to avoid mutating the list |
165 // while iterating over it. | 179 // while iterating over it. |
166 ClientList clients_copy(clients_); | 180 ClientList clients_copy(clients_); |
167 for (ClientList::const_iterator other_client = clients_copy.begin(); | 181 for (ClientList::const_iterator other_client = clients_copy.begin(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 269 |
256 if (state == SignalStrategy::StatusObserver::CONNECTED) { | 270 if (state == SignalStrategy::StatusObserver::CONNECTED) { |
257 LOG(INFO) << "Host connected as " << local_jid_; | 271 LOG(INFO) << "Host connected as " << local_jid_; |
258 | 272 |
259 // Create and start session manager. | 273 // Create and start session manager. |
260 protocol::JingleSessionManager* server = | 274 protocol::JingleSessionManager* server = |
261 new protocol::JingleSessionManager(context_->network_message_loop()); | 275 new protocol::JingleSessionManager(context_->network_message_loop()); |
262 // TODO(ajwong): Make this a command switch when we're more stable. | 276 // TODO(ajwong): Make this a command switch when we're more stable. |
263 server->set_allow_local_ips(true); | 277 server->set_allow_local_ips(true); |
264 | 278 |
265 // Assign key and certificate to server. | 279 server->Init(local_jid_, signal_strategy_.get(), |
266 HostKeyPair key_pair; | 280 this, allow_nat_traversal_); |
267 CHECK(key_pair.Load(config_)) | |
268 << "Failed to load server authentication data"; | |
269 | |
270 server->Init(local_jid_, signal_strategy_.get(), this, | |
271 key_pair.CopyPrivateKey(), key_pair.GenerateCertificate(), | |
272 allow_nat_traversal_); | |
273 | 281 |
274 session_manager_.reset(server); | 282 session_manager_.reset(server); |
275 | 283 |
276 for (StatusObserverList::iterator it = status_observers_.begin(); | 284 for (StatusObserverList::iterator it = status_observers_.begin(); |
277 it != status_observers_.end(); ++it) { | 285 it != status_observers_.end(); ++it) { |
278 (*it)->OnSignallingConnected(signal_strategy_.get(), local_jid_); | 286 (*it)->OnSignallingConnected(signal_strategy_.get(), local_jid_); |
279 } | 287 } |
280 } else if (state == SignalStrategy::StatusObserver::CLOSED) { | 288 } else if (state == SignalStrategy::StatusObserver::CLOSED) { |
281 LOG(INFO) << "Host disconnected from talk network."; | 289 LOG(INFO) << "Host disconnected from talk network."; |
282 for (StatusObserverList::iterator it = status_observers_.begin(); | 290 for (StatusObserverList::iterator it = status_observers_.begin(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 protocol::SessionConfig config; | 333 protocol::SessionConfig config; |
326 if (!protocol_config_->Select(session->candidate_config(), | 334 if (!protocol_config_->Select(session->candidate_config(), |
327 true /* force_host_resolution */, &config)) { | 335 true /* force_host_resolution */, &config)) { |
328 LOG(WARNING) << "Rejecting connection from " << session->jid() | 336 LOG(WARNING) << "Rejecting connection from " << session->jid() |
329 << " because no compatible configuration has been found."; | 337 << " because no compatible configuration has been found."; |
330 *response = protocol::SessionManager::INCOMPATIBLE; | 338 *response = protocol::SessionManager::INCOMPATIBLE; |
331 return; | 339 return; |
332 } | 340 } |
333 | 341 |
334 session->set_config(config); | 342 session->set_config(config); |
335 // Provide the Access Code as shared secret for SSL channel authentication. | |
336 session->set_shared_secret(access_code_); | |
337 | 343 |
338 *response = protocol::SessionManager::ACCEPT; | 344 *response = protocol::SessionManager::ACCEPT; |
339 | 345 |
340 LOG(INFO) << "Client connected: " << session->jid(); | 346 LOG(INFO) << "Client connected: " << session->jid(); |
341 | 347 |
342 // Create a client object. | 348 // Create a client object. |
343 protocol::ConnectionToClient* connection = | 349 protocol::ConnectionToClient* connection = |
344 new protocol::ConnectionToClient(session); | 350 new protocol::ConnectionToClient(session); |
345 ClientSession* client = new ClientSession( | 351 ClientSession* client = new ClientSession( |
346 this, connection, desktop_environment_->event_executor(), | 352 this, connection, desktop_environment_->event_executor(), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 } | 472 } |
467 | 473 |
468 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); | 474 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); |
469 it != shutdown_tasks_.end(); ++it) { | 475 it != shutdown_tasks_.end(); ++it) { |
470 it->Run(); | 476 it->Run(); |
471 } | 477 } |
472 shutdown_tasks_.clear(); | 478 shutdown_tasks_.clear(); |
473 } | 479 } |
474 | 480 |
475 } // namespace remoting | 481 } // namespace remoting |
OLD | NEW |