OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/plugin/host_script_object.h" | 5 #include "remoting/host/plugin/host_script_object.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/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
19 #include "remoting/base/auth_token_util.h" | 19 #include "remoting/base/auth_token_util.h" |
20 #include "remoting/base/auto_thread.h" | 20 #include "remoting/base/auto_thread.h" |
| 21 #include "remoting/base/rsa_key_pair.h" |
21 #include "remoting/host/basic_desktop_environment.h" | 22 #include "remoting/host/basic_desktop_environment.h" |
22 #include "remoting/host/chromoting_host.h" | 23 #include "remoting/host/chromoting_host.h" |
23 #include "remoting/host/chromoting_host_context.h" | 24 #include "remoting/host/chromoting_host_context.h" |
24 #include "remoting/host/host_config.h" | 25 #include "remoting/host/host_config.h" |
25 #include "remoting/host/host_event_logger.h" | 26 #include "remoting/host/host_event_logger.h" |
26 #include "remoting/host/host_key_pair.h" | |
27 #include "remoting/host/host_secret.h" | 27 #include "remoting/host/host_secret.h" |
28 #include "remoting/host/host_status_observer.h" | 28 #include "remoting/host/host_status_observer.h" |
29 #include "remoting/host/it2me_host_user_interface.h" | 29 #include "remoting/host/it2me_host_user_interface.h" |
30 #include "remoting/host/network_settings.h" | 30 #include "remoting/host/network_settings.h" |
31 #include "remoting/host/pin_hash.h" | 31 #include "remoting/host/pin_hash.h" |
32 #include "remoting/host/plugin/host_log_handler.h" | 32 #include "remoting/host/plugin/host_log_handler.h" |
33 #include "remoting/host/policy_hack/policy_watcher.h" | 33 #include "remoting/host/policy_hack/policy_watcher.h" |
34 #include "remoting/host/register_support_host_request.h" | 34 #include "remoting/host/register_support_host_request.h" |
35 #include "remoting/host/service_urls.h" | 35 #include "remoting/host/service_urls.h" |
36 #include "remoting/host/session_manager_factory.h" | 36 #include "remoting/host/session_manager_factory.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 // Caller supplied fields. | 156 // Caller supplied fields. |
157 scoped_ptr<ChromotingHostContext> host_context_; | 157 scoped_ptr<ChromotingHostContext> host_context_; |
158 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner_; | 158 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner_; |
159 base::WeakPtr<HostNPScriptObject> script_object_; | 159 base::WeakPtr<HostNPScriptObject> script_object_; |
160 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 160 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
161 std::string directory_bot_jid_; | 161 std::string directory_bot_jid_; |
162 | 162 |
163 State state_; | 163 State state_; |
164 | 164 |
165 HostKeyPair host_key_pair_; | 165 scoped_refptr<RsaKeyPair> host_key_pair_; |
166 scoped_ptr<SignalStrategy> signal_strategy_; | 166 scoped_ptr<SignalStrategy> signal_strategy_; |
167 scoped_ptr<RegisterSupportHostRequest> register_request_; | 167 scoped_ptr<RegisterSupportHostRequest> register_request_; |
168 scoped_ptr<LogToServer> log_to_server_; | 168 scoped_ptr<LogToServer> log_to_server_; |
169 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; | 169 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; |
170 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; | 170 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; |
171 scoped_ptr<HostEventLogger> host_event_logger_; | 171 scoped_ptr<HostEventLogger> host_event_logger_; |
172 | 172 |
173 scoped_refptr<ChromotingHost> host_; | 173 scoped_refptr<ChromotingHost> host_; |
174 int failed_login_attempts_; | 174 int failed_login_attempts_; |
175 | 175 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 337 |
338 // Check the host domain policy. | 338 // Check the host domain policy. |
339 if (!required_host_domain_.empty() && | 339 if (!required_host_domain_.empty() && |
340 !EndsWith(uid, std::string("@") + required_host_domain_, false)) { | 340 !EndsWith(uid, std::string("@") + required_host_domain_, false)) { |
341 SetState(kInvalidDomainError); | 341 SetState(kInvalidDomainError); |
342 return; | 342 return; |
343 } | 343 } |
344 | 344 |
345 // Generate a key pair for the Host to use. | 345 // Generate a key pair for the Host to use. |
346 // TODO(wez): Move this to the worker thread. | 346 // TODO(wez): Move this to the worker thread. |
347 host_key_pair_.Generate(); | 347 host_key_pair_->Generate(); |
348 | 348 |
349 // Create XMPP connection. | 349 // Create XMPP connection. |
350 scoped_ptr<SignalStrategy> signal_strategy( | 350 scoped_ptr<SignalStrategy> signal_strategy( |
351 new XmppSignalStrategy(host_context_->url_request_context_getter(), | 351 new XmppSignalStrategy(host_context_->url_request_context_getter(), |
352 uid, auth_token, auth_service, | 352 uid, auth_token, auth_service, |
353 xmpp_server_config_)); | 353 xmpp_server_config_)); |
354 | 354 |
355 // Request registration of the host for support. | 355 // Request registration of the host for support. |
356 scoped_ptr<RegisterSupportHostRequest> register_request( | 356 scoped_ptr<RegisterSupportHostRequest> register_request( |
357 new RegisterSupportHostRequest( | 357 new RegisterSupportHostRequest( |
358 signal_strategy.get(), &host_key_pair_, directory_bot_jid_, | 358 signal_strategy.get(), host_key_pair_, directory_bot_jid_, |
359 base::Bind(&It2MeImpl::OnReceivedSupportID, | 359 base::Bind(&It2MeImpl::OnReceivedSupportID, |
360 base::Unretained(this)))); | 360 base::Unretained(this)))); |
361 | 361 |
362 // Beyond this point nothing can fail, so save the config and request. | 362 // Beyond this point nothing can fail, so save the config and request. |
363 signal_strategy_ = signal_strategy.Pass(); | 363 signal_strategy_ = signal_strategy.Pass(); |
364 register_request_ = register_request.Pass(); | 364 register_request_ = register_request.Pass(); |
365 | 365 |
366 // If NAT traversal is off then limit port range to allow firewall pin-holing. | 366 // If NAT traversal is off then limit port range to allow firewall pin-holing. |
367 LOG(INFO) << "NAT state: " << nat_traversal_enabled_; | 367 LOG(INFO) << "NAT state: " << nat_traversal_enabled_; |
368 NetworkSettings network_settings( | 368 NetworkSettings network_settings( |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 | 634 |
635 if (!success) { | 635 if (!success) { |
636 SetState(kError); | 636 SetState(kError); |
637 Disconnect(); | 637 Disconnect(); |
638 return; | 638 return; |
639 } | 639 } |
640 | 640 |
641 std::string host_secret = GenerateSupportHostSecret(); | 641 std::string host_secret = GenerateSupportHostSecret(); |
642 std::string access_code = support_id + host_secret; | 642 std::string access_code = support_id + host_secret; |
643 | 643 |
644 std::string local_certificate = host_key_pair_.GenerateCertificate(); | 644 std::string local_certificate = host_key_pair_->GenerateCertificate(); |
645 if (local_certificate.empty()) { | 645 if (local_certificate.empty()) { |
646 LOG(ERROR) << "Failed to generate host certificate."; | 646 LOG(ERROR) << "Failed to generate host certificate."; |
647 SetState(kError); | 647 SetState(kError); |
648 Disconnect(); | 648 Disconnect(); |
649 return; | 649 return; |
650 } | 650 } |
651 | 651 |
652 scoped_ptr<protocol::AuthenticatorFactory> factory( | 652 scoped_ptr<protocol::AuthenticatorFactory> factory( |
653 new protocol::It2MeHostAuthenticatorFactory( | 653 new protocol::It2MeHostAuthenticatorFactory( |
654 local_certificate, *host_key_pair_.private_key(), access_code)); | 654 local_certificate, host_key_pair_, access_code)); |
655 host_->SetAuthenticatorFactory(factory.Pass()); | 655 host_->SetAuthenticatorFactory(factory.Pass()); |
656 | 656 |
657 // Pass the Access Code to the script object before changing state. | 657 // Pass the Access Code to the script object before changing state. |
658 plugin_task_runner_->PostTask( | 658 plugin_task_runner_->PostTask( |
659 FROM_HERE, base::Bind(&HostNPScriptObject::StoreAccessCode, | 659 FROM_HERE, base::Bind(&HostNPScriptObject::StoreAccessCode, |
660 script_object_, access_code, lifetime)); | 660 script_object_, access_code, lifetime)); |
661 | 661 |
662 SetState(kReceivedAccessCode); | 662 SetState(kReceivedAccessCode); |
663 } | 663 } |
664 | 664 |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1440 g_npnetscape_funcs->releasevariantvalue(&np_result); | 1440 g_npnetscape_funcs->releasevariantvalue(&np_result); |
1441 if (translation.empty()) { | 1441 if (translation.empty()) { |
1442 LOG(ERROR) << "Missing translation for " << tag; | 1442 LOG(ERROR) << "Missing translation for " << tag; |
1443 return false; | 1443 return false; |
1444 } | 1444 } |
1445 *result = UTF8ToUTF16(translation); | 1445 *result = UTF8ToUTF16(translation); |
1446 return true; | 1446 return true; |
1447 } | 1447 } |
1448 | 1448 |
1449 void HostNPScriptObject::DoGenerateKeyPair(const ScopedRefNPObject& callback) { | 1449 void HostNPScriptObject::DoGenerateKeyPair(const ScopedRefNPObject& callback) { |
1450 HostKeyPair key_pair; | 1450 scoped_refptr<RsaKeyPair> key_pair(new RsaKeyPair); |
1451 key_pair.Generate(); | 1451 key_pair->Generate(); |
1452 InvokeGenerateKeyPairCallback(callback, key_pair.GetAsString(), | 1452 InvokeGenerateKeyPairCallback(callback, key_pair->GetAsString(), |
1453 key_pair.GetPublicKey()); | 1453 key_pair->GetPublicKey()); |
1454 } | 1454 } |
1455 | 1455 |
1456 void HostNPScriptObject::InvokeGenerateKeyPairCallback( | 1456 void HostNPScriptObject::InvokeGenerateKeyPairCallback( |
1457 const ScopedRefNPObject& callback, | 1457 const ScopedRefNPObject& callback, |
1458 const std::string& private_key, | 1458 const std::string& private_key, |
1459 const std::string& public_key) { | 1459 const std::string& public_key) { |
1460 if (!plugin_task_runner_->BelongsToCurrentThread()) { | 1460 if (!plugin_task_runner_->BelongsToCurrentThread()) { |
1461 plugin_task_runner_->PostTask( | 1461 plugin_task_runner_->PostTask( |
1462 FROM_HERE, base::Bind( | 1462 FROM_HERE, base::Bind( |
1463 &HostNPScriptObject::InvokeGenerateKeyPairCallback, | 1463 &HostNPScriptObject::InvokeGenerateKeyPairCallback, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 } | 1582 } |
1583 | 1583 |
1584 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1584 void HostNPScriptObject::SetException(const std::string& exception_string) { |
1585 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 1585 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
1586 | 1586 |
1587 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1587 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
1588 LOG(INFO) << exception_string; | 1588 LOG(INFO) << exception_string; |
1589 } | 1589 } |
1590 | 1590 |
1591 } // namespace remoting | 1591 } // namespace remoting |
OLD | NEW |