| 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_ = RsaKeyPair::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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 | 635 |
| 636 if (!success) { | 636 if (!success) { |
| 637 SetState(kError); | 637 SetState(kError); |
| 638 Disconnect(); | 638 Disconnect(); |
| 639 return; | 639 return; |
| 640 } | 640 } |
| 641 | 641 |
| 642 std::string host_secret = GenerateSupportHostSecret(); | 642 std::string host_secret = GenerateSupportHostSecret(); |
| 643 std::string access_code = support_id + host_secret; | 643 std::string access_code = support_id + host_secret; |
| 644 | 644 |
| 645 std::string local_certificate = host_key_pair_.GenerateCertificate(); | 645 std::string local_certificate = host_key_pair_->GenerateCertificate(); |
| 646 if (local_certificate.empty()) { | 646 if (local_certificate.empty()) { |
| 647 LOG(ERROR) << "Failed to generate host certificate."; | 647 LOG(ERROR) << "Failed to generate host certificate."; |
| 648 SetState(kError); | 648 SetState(kError); |
| 649 Disconnect(); | 649 Disconnect(); |
| 650 return; | 650 return; |
| 651 } | 651 } |
| 652 | 652 |
| 653 scoped_ptr<protocol::AuthenticatorFactory> factory( | 653 scoped_ptr<protocol::AuthenticatorFactory> factory( |
| 654 new protocol::It2MeHostAuthenticatorFactory( | 654 new protocol::It2MeHostAuthenticatorFactory( |
| 655 local_certificate, *host_key_pair_.private_key(), access_code)); | 655 local_certificate, host_key_pair_, access_code)); |
| 656 host_->SetAuthenticatorFactory(factory.Pass()); | 656 host_->SetAuthenticatorFactory(factory.Pass()); |
| 657 | 657 |
| 658 // Pass the Access Code to the script object before changing state. | 658 // Pass the Access Code to the script object before changing state. |
| 659 plugin_task_runner_->PostTask( | 659 plugin_task_runner_->PostTask( |
| 660 FROM_HERE, base::Bind(&HostNPScriptObject::StoreAccessCode, | 660 FROM_HERE, base::Bind(&HostNPScriptObject::StoreAccessCode, |
| 661 script_object_, access_code, lifetime)); | 661 script_object_, access_code, lifetime)); |
| 662 | 662 |
| 663 SetState(kReceivedAccessCode); | 663 SetState(kReceivedAccessCode); |
| 664 } | 664 } |
| 665 | 665 |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 g_npnetscape_funcs->releasevariantvalue(&np_result); | 1441 g_npnetscape_funcs->releasevariantvalue(&np_result); |
| 1442 if (translation.empty()) { | 1442 if (translation.empty()) { |
| 1443 LOG(ERROR) << "Missing translation for " << tag; | 1443 LOG(ERROR) << "Missing translation for " << tag; |
| 1444 return false; | 1444 return false; |
| 1445 } | 1445 } |
| 1446 *result = UTF8ToUTF16(translation); | 1446 *result = UTF8ToUTF16(translation); |
| 1447 return true; | 1447 return true; |
| 1448 } | 1448 } |
| 1449 | 1449 |
| 1450 void HostNPScriptObject::DoGenerateKeyPair(const ScopedRefNPObject& callback) { | 1450 void HostNPScriptObject::DoGenerateKeyPair(const ScopedRefNPObject& callback) { |
| 1451 HostKeyPair key_pair; | 1451 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); |
| 1452 key_pair.Generate(); | 1452 InvokeGenerateKeyPairCallback(callback, key_pair->ToString(), |
| 1453 InvokeGenerateKeyPairCallback(callback, key_pair.GetAsString(), | 1453 key_pair->GetPublicKey()); |
| 1454 key_pair.GetPublicKey()); | |
| 1455 } | 1454 } |
| 1456 | 1455 |
| 1457 void HostNPScriptObject::InvokeGenerateKeyPairCallback( | 1456 void HostNPScriptObject::InvokeGenerateKeyPairCallback( |
| 1458 const ScopedRefNPObject& callback, | 1457 const ScopedRefNPObject& callback, |
| 1459 const std::string& private_key, | 1458 const std::string& private_key, |
| 1460 const std::string& public_key) { | 1459 const std::string& public_key) { |
| 1461 if (!plugin_task_runner_->BelongsToCurrentThread()) { | 1460 if (!plugin_task_runner_->BelongsToCurrentThread()) { |
| 1462 plugin_task_runner_->PostTask( | 1461 plugin_task_runner_->PostTask( |
| 1463 FROM_HERE, base::Bind( | 1462 FROM_HERE, base::Bind( |
| 1464 &HostNPScriptObject::InvokeGenerateKeyPairCallback, | 1463 &HostNPScriptObject::InvokeGenerateKeyPairCallback, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 } | 1582 } |
| 1584 | 1583 |
| 1585 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1584 void HostNPScriptObject::SetException(const std::string& exception_string) { |
| 1586 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 1585 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 1587 | 1586 |
| 1588 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1587 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
| 1589 LOG(INFO) << exception_string; | 1588 LOG(INFO) << exception_string; |
| 1590 } | 1589 } |
| 1591 | 1590 |
| 1592 } // namespace remoting | 1591 } // namespace remoting |
| OLD | NEW |