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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 SignalStrategy::StatusObserver::State state) { | 267 SignalStrategy::StatusObserver::State state) { |
254 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 268 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
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 | 276 |
263 // Assign key and certificate to server. | 277 server->Init(local_jid_, signal_strategy_.get(), |
264 HostKeyPair key_pair; | 278 this, allow_nat_traversal_); |
265 CHECK(key_pair.Load(config_)) | |
266 << "Failed to load server authentication data"; | |
267 | |
268 server->Init(local_jid_, signal_strategy_.get(), this, | |
269 key_pair.CopyPrivateKey(), key_pair.GenerateCertificate(), | |
270 allow_nat_traversal_); | |
271 | 279 |
272 session_manager_.reset(server); | 280 session_manager_.reset(server); |
273 | 281 |
274 for (StatusObserverList::iterator it = status_observers_.begin(); | 282 for (StatusObserverList::iterator it = status_observers_.begin(); |
275 it != status_observers_.end(); ++it) { | 283 it != status_observers_.end(); ++it) { |
276 (*it)->OnSignallingConnected(signal_strategy_.get(), local_jid_); | 284 (*it)->OnSignallingConnected(signal_strategy_.get(), local_jid_); |
277 } | 285 } |
278 } else if (state == SignalStrategy::StatusObserver::CLOSED) { | 286 } else if (state == SignalStrategy::StatusObserver::CLOSED) { |
279 LOG(INFO) << "Host disconnected from talk network."; | 287 LOG(INFO) << "Host disconnected from talk network."; |
280 for (StatusObserverList::iterator it = status_observers_.begin(); | 288 for (StatusObserverList::iterator it = status_observers_.begin(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 protocol::SessionConfig config; | 331 protocol::SessionConfig config; |
324 if (!protocol_config_->Select(session->candidate_config(), | 332 if (!protocol_config_->Select(session->candidate_config(), |
325 true /* force_host_resolution */, &config)) { | 333 true /* force_host_resolution */, &config)) { |
326 LOG(WARNING) << "Rejecting connection from " << session->jid() | 334 LOG(WARNING) << "Rejecting connection from " << session->jid() |
327 << " because no compatible configuration has been found."; | 335 << " because no compatible configuration has been found."; |
328 *response = protocol::SessionManager::INCOMPATIBLE; | 336 *response = protocol::SessionManager::INCOMPATIBLE; |
329 return; | 337 return; |
330 } | 338 } |
331 | 339 |
332 session->set_config(config); | 340 session->set_config(config); |
333 // Provide the Access Code as shared secret for SSL channel authentication. | |
334 session->set_shared_secret(access_code_); | |
335 | 341 |
336 *response = protocol::SessionManager::ACCEPT; | 342 *response = protocol::SessionManager::ACCEPT; |
337 | 343 |
338 LOG(INFO) << "Client connected: " << session->jid(); | 344 LOG(INFO) << "Client connected: " << session->jid(); |
339 | 345 |
340 // Create a client object. | 346 // Create a client object. |
341 protocol::ConnectionToClient* connection = | 347 protocol::ConnectionToClient* connection = |
342 new protocol::ConnectionToClient(session); | 348 new protocol::ConnectionToClient(session); |
343 ClientSession* client = new ClientSession( | 349 ClientSession* client = new ClientSession( |
344 this, connection, desktop_environment_->event_executor(), | 350 this, connection, desktop_environment_->event_executor(), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 470 } |
465 | 471 |
466 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); | 472 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); |
467 it != shutdown_tasks_.end(); ++it) { | 473 it != shutdown_tasks_.end(); ++it) { |
468 it->Run(); | 474 it->Run(); |
469 } | 475 } |
470 shutdown_tasks_.clear(); | 476 shutdown_tasks_.clear(); |
471 } | 477 } |
472 | 478 |
473 } // namespace remoting | 479 } // namespace remoting |
OLD | NEW |