| 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/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/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| 11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "remoting/base/auth_token_util.h" | 13 #include "remoting/base/auth_token_util.h" |
| 14 #include "remoting/host/chromoting_host.h" | 14 #include "remoting/host/chromoting_host.h" |
| 15 #include "remoting/host/chromoting_host_context.h" | 15 #include "remoting/host/chromoting_host_context.h" |
| 16 #include "remoting/host/desktop_environment.h" | 16 #include "remoting/host/desktop_environment.h" |
| 17 #include "remoting/host/host_config.h" | 17 #include "remoting/host/host_config.h" |
| 18 #include "remoting/host/host_key_pair.h" | 18 #include "remoting/host/host_key_pair.h" |
| 19 #include "remoting/host/host_secret.h" |
| 19 #include "remoting/host/in_memory_host_config.h" | 20 #include "remoting/host/in_memory_host_config.h" |
| 20 #include "remoting/host/plugin/host_log_handler.h" | 21 #include "remoting/host/plugin/host_log_handler.h" |
| 21 #include "remoting/host/plugin/policy_hack/nat_policy.h" | 22 #include "remoting/host/plugin/policy_hack/nat_policy.h" |
| 22 #include "remoting/host/register_support_host_request.h" | 23 #include "remoting/host/register_support_host_request.h" |
| 23 #include "remoting/host/support_access_verifier.h" | |
| 24 | 24 |
| 25 namespace remoting { | 25 namespace remoting { |
| 26 | 26 |
| 27 // Supported Javascript interface: | 27 // Supported Javascript interface: |
| 28 // readonly attribute string accessCode; | 28 // readonly attribute string accessCode; |
| 29 // readonly attribute int accessCodeLifetime; | 29 // readonly attribute int accessCodeLifetime; |
| 30 // readonly attribute string client; | 30 // readonly attribute string client; |
| 31 // readonly attribute int state; | 31 // readonly attribute int state; |
| 32 // | 32 // |
| 33 // state: { | 33 // state: { |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 // Host has been stopped while we were fetching policy. | 473 // Host has been stopped while we were fetching policy. |
| 474 return; | 474 return; |
| 475 } | 475 } |
| 476 | 476 |
| 477 // Store the supplied user ID and token to the Host configuration. | 477 // Store the supplied user ID and token to the Host configuration. |
| 478 scoped_refptr<MutableHostConfig> host_config = new InMemoryHostConfig(); | 478 scoped_refptr<MutableHostConfig> host_config = new InMemoryHostConfig(); |
| 479 host_config->SetString(kXmppLoginConfigPath, uid); | 479 host_config->SetString(kXmppLoginConfigPath, uid); |
| 480 host_config->SetString(kXmppAuthTokenConfigPath, auth_token); | 480 host_config->SetString(kXmppAuthTokenConfigPath, auth_token); |
| 481 host_config->SetString(kXmppAuthServiceConfigPath, auth_service); | 481 host_config->SetString(kXmppAuthServiceConfigPath, auth_service); |
| 482 | 482 |
| 483 // Create an access verifier and fetch the host secret. | |
| 484 scoped_ptr<SupportAccessVerifier> access_verifier; | |
| 485 access_verifier.reset(new SupportAccessVerifier()); | |
| 486 | |
| 487 // Generate a key pair for the Host to use. | 483 // Generate a key pair for the Host to use. |
| 488 // TODO(wez): Move this to the worker thread. | 484 // TODO(wez): Move this to the worker thread. |
| 489 HostKeyPair host_key_pair; | 485 HostKeyPair host_key_pair; |
| 490 host_key_pair.Generate(); | 486 host_key_pair.Generate(); |
| 491 host_key_pair.Save(host_config); | 487 host_key_pair.Save(host_config); |
| 492 | 488 |
| 493 // Request registration of the host for support. | 489 // Request registration of the host for support. |
| 494 scoped_ptr<RegisterSupportHostRequest> register_request( | 490 scoped_ptr<RegisterSupportHostRequest> register_request( |
| 495 new RegisterSupportHostRequest()); | 491 new RegisterSupportHostRequest()); |
| 496 if (!register_request->Init( | 492 if (!register_request->Init( |
| 497 host_config.get(), | 493 host_config.get(), |
| 498 base::Bind(&HostNPScriptObject::OnReceivedSupportID, | 494 base::Bind(&HostNPScriptObject::OnReceivedSupportID, |
| 499 base::Unretained(this), | 495 base::Unretained(this)))) { |
| 500 access_verifier.get()))) { | |
| 501 SetState(kError); | 496 SetState(kError); |
| 502 return; | 497 return; |
| 503 } | 498 } |
| 504 | 499 |
| 505 // Create DesktopEnvironment. | 500 // Create DesktopEnvironment. |
| 506 desktop_environment_.reset(DesktopEnvironment::Create(&host_context_)); | 501 desktop_environment_.reset(DesktopEnvironment::Create(&host_context_)); |
| 507 if (desktop_environment_.get() == NULL) { | 502 if (desktop_environment_.get() == NULL) { |
| 508 SetState(kError); | 503 SetState(kError); |
| 509 return; | 504 return; |
| 510 } | 505 } |
| 511 | 506 |
| 512 // Beyond this point nothing can fail, so save the config and request. | 507 // Beyond this point nothing can fail, so save the config and request. |
| 513 host_config_ = host_config; | 508 host_config_ = host_config; |
| 514 register_request_.reset(register_request.release()); | 509 register_request_.reset(register_request.release()); |
| 515 | 510 |
| 516 // Create the Host. | 511 // Create the Host. |
| 517 LOG(INFO) << "NAT state: " << nat_traversal_enabled_; | 512 LOG(INFO) << "NAT state: " << nat_traversal_enabled_; |
| 518 host_ = ChromotingHost::Create( | 513 host_ = ChromotingHost::Create( |
| 519 &host_context_, host_config_, desktop_environment_.get(), | 514 &host_context_, host_config_, desktop_environment_.get(), |
| 520 access_verifier.release(), nat_traversal_enabled_); | 515 nat_traversal_enabled_); |
| 521 host_->AddStatusObserver(this); | 516 host_->AddStatusObserver(this); |
| 522 host_->AddStatusObserver(register_request_.get()); | 517 host_->AddStatusObserver(register_request_.get()); |
| 523 if (enable_log_to_server_) { | 518 if (enable_log_to_server_) { |
| 524 log_to_server_.reset(new LogToServer(host_context_.network_message_loop())); | 519 log_to_server_.reset(new LogToServer(host_context_.network_message_loop())); |
| 525 host_->AddStatusObserver(log_to_server_.get()); | 520 host_->AddStatusObserver(log_to_server_.get()); |
| 526 } | 521 } |
| 527 host_->set_it2me(true); | 522 host_->set_it2me(true); |
| 528 | 523 |
| 529 { | 524 { |
| 530 base::AutoLock auto_lock(ui_strings_lock_); | 525 base::AutoLock auto_lock(ui_strings_lock_); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 | 632 |
| 638 UpdateWebappNatPolicy(nat_traversal_enabled_); | 633 UpdateWebappNatPolicy(nat_traversal_enabled_); |
| 639 | 634 |
| 640 if (!pending_connect_.is_null()) { | 635 if (!pending_connect_.is_null()) { |
| 641 pending_connect_.Run(); | 636 pending_connect_.Run(); |
| 642 pending_connect_.Reset(); | 637 pending_connect_.Reset(); |
| 643 } | 638 } |
| 644 } | 639 } |
| 645 | 640 |
| 646 void HostNPScriptObject::OnReceivedSupportID( | 641 void HostNPScriptObject::OnReceivedSupportID( |
| 647 SupportAccessVerifier* access_verifier, | |
| 648 bool success, | 642 bool success, |
| 649 const std::string& support_id, | 643 const std::string& support_id, |
| 650 const base::TimeDelta& lifetime) { | 644 const base::TimeDelta& lifetime) { |
| 651 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); | 645 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); |
| 652 | 646 |
| 653 if (!success) { | 647 if (!success) { |
| 654 host_context_.main_message_loop()->PostTask(FROM_HERE, base::Bind( | 648 host_context_.main_message_loop()->PostTask(FROM_HERE, base::Bind( |
| 655 &HostNPScriptObject::NotifyAccessCode, base::Unretained(this), false)); | 649 &HostNPScriptObject::NotifyAccessCode, base::Unretained(this), false)); |
| 656 DisconnectInternal(); | 650 DisconnectInternal(); |
| 657 return; | 651 return; |
| 658 } | 652 } |
| 659 | 653 |
| 660 access_verifier->OnIT2MeHostRegistered(success, support_id); | 654 std::string host_secret = GenerateSupportHostSecret(); |
| 661 std::string access_code = support_id + access_verifier->host_secret(); | 655 std::string access_code = support_id + host_secret; |
| 662 host_->set_access_code(access_code); | 656 host_->set_access_code(access_code); |
| 663 | 657 |
| 664 { | 658 { |
| 665 base::AutoLock lock(access_code_lock_); | 659 base::AutoLock lock(access_code_lock_); |
| 666 access_code_ = access_code; | 660 access_code_ = access_code; |
| 667 access_code_lifetime_ = lifetime; | 661 access_code_lifetime_ = lifetime; |
| 668 } | 662 } |
| 669 | 663 |
| 670 host_context_.main_message_loop()->PostTask(FROM_HERE, base::Bind( | 664 host_context_.main_message_loop()->PostTask(FROM_HERE, base::Bind( |
| 671 &HostNPScriptObject::NotifyAccessCode, base::Unretained(this), true)); | 665 &HostNPScriptObject::NotifyAccessCode, base::Unretained(this), true)); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 uint32_t argCount) { | 837 uint32_t argCount) { |
| 844 NPVariant np_result; | 838 NPVariant np_result; |
| 845 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, | 839 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, |
| 846 argCount, &np_result); | 840 argCount, &np_result); |
| 847 if (is_good) | 841 if (is_good) |
| 848 g_npnetscape_funcs->releasevariantvalue(&np_result); | 842 g_npnetscape_funcs->releasevariantvalue(&np_result); |
| 849 return is_good; | 843 return is_good; |
| 850 } | 844 } |
| 851 | 845 |
| 852 } // namespace remoting | 846 } // namespace remoting |
| OLD | NEW |