| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/it2me/it2me_host.h" | 5 #include "remoting/host/it2me/it2me_host.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
| 17 #include "components/policy/policy_constants.h" | 17 #include "components/policy/policy_constants.h" |
| 18 #include "net/socket/client_socket_factory.h" | |
| 19 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
| 20 #include "remoting/base/auto_thread.h" | 19 #include "remoting/base/auto_thread.h" |
| 21 #include "remoting/base/chromium_url_request.h" | 20 #include "remoting/base/chromium_url_request.h" |
| 22 #include "remoting/base/logging.h" | 21 #include "remoting/base/logging.h" |
| 23 #include "remoting/base/rsa_key_pair.h" | 22 #include "remoting/base/rsa_key_pair.h" |
| 24 #include "remoting/host/chromoting_host.h" | 23 #include "remoting/host/chromoting_host.h" |
| 25 #include "remoting/host/chromoting_host_context.h" | 24 #include "remoting/host/chromoting_host_context.h" |
| 26 #include "remoting/host/host_event_logger.h" | 25 #include "remoting/host/host_event_logger.h" |
| 27 #include "remoting/host/host_secret.h" | 26 #include "remoting/host/host_secret.h" |
| 28 #include "remoting/host/host_status_logger.h" | 27 #include "remoting/host/host_status_logger.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 54 typedef ValidatingAuthenticator::Result ValidationResult; | 53 typedef ValidatingAuthenticator::Result ValidationResult; |
| 55 typedef ValidatingAuthenticator::ValidationCallback ValidationCallback; | 54 typedef ValidatingAuthenticator::ValidationCallback ValidationCallback; |
| 56 | 55 |
| 57 } // namespace | 56 } // namespace |
| 58 | 57 |
| 59 It2MeHost::It2MeHost( | 58 It2MeHost::It2MeHost( |
| 60 std::unique_ptr<ChromotingHostContext> host_context, | 59 std::unique_ptr<ChromotingHostContext> host_context, |
| 61 std::unique_ptr<PolicyWatcher> policy_watcher, | 60 std::unique_ptr<PolicyWatcher> policy_watcher, |
| 62 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog, | 61 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog, |
| 63 base::WeakPtr<It2MeHost::Observer> observer, | 62 base::WeakPtr<It2MeHost::Observer> observer, |
| 64 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 63 std::unique_ptr<SignalStrategy> signal_strategy, |
| 64 const std::string& username, |
| 65 const std::string& directory_bot_jid) | 65 const std::string& directory_bot_jid) |
| 66 : host_context_(std::move(host_context)), | 66 : host_context_(std::move(host_context)), |
| 67 observer_(observer), | 67 observer_(observer), |
| 68 xmpp_server_config_(xmpp_server_config), | 68 signal_strategy_(std::move(signal_strategy)), |
| 69 username_(username), |
| 69 directory_bot_jid_(directory_bot_jid), | 70 directory_bot_jid_(directory_bot_jid), |
| 70 policy_watcher_(std::move(policy_watcher)), | 71 policy_watcher_(std::move(policy_watcher)), |
| 71 confirmation_dialog_(std::move(confirmation_dialog)) { | 72 confirmation_dialog_(std::move(confirmation_dialog)) { |
| 72 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); | 73 DCHECK(host_context_->ui_task_runner()->BelongsToCurrentThread()); |
| 73 } | 74 } |
| 74 | 75 |
| 75 It2MeHost::~It2MeHost() { | 76 It2MeHost::~It2MeHost() { |
| 76 // Check that resources that need to be torn down on the UI thread are gone. | 77 // Check that resources that need to be torn down on the UI thread are gone. |
| 77 DCHECK(!desktop_environment_factory_.get()); | 78 DCHECK(!desktop_environment_factory_.get()); |
| 78 DCHECK(!policy_watcher_.get()); | 79 DCHECK(!policy_watcher_.get()); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 void It2MeHost::FinishConnect() { | 167 void It2MeHost::FinishConnect() { |
| 167 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 168 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
| 168 | 169 |
| 169 if (state_ != kStarting) { | 170 if (state_ != kStarting) { |
| 170 // Host has been stopped while we were fetching policy. | 171 // Host has been stopped while we were fetching policy. |
| 171 return; | 172 return; |
| 172 } | 173 } |
| 173 | 174 |
| 174 // Check the host domain policy. | 175 // Check the host domain policy. |
| 175 if (!required_host_domain_.empty() && | 176 if (!required_host_domain_.empty() && |
| 176 !base::EndsWith(xmpp_server_config_.username, | 177 !base::EndsWith(username_, std::string("@") + required_host_domain_, |
| 177 std::string("@") + required_host_domain_, | |
| 178 base::CompareCase::INSENSITIVE_ASCII)) { | 178 base::CompareCase::INSENSITIVE_ASCII)) { |
| 179 SetState(kInvalidDomainError, ""); | 179 SetState(kInvalidDomainError, ""); |
| 180 return; | 180 return; |
| 181 } | 181 } |
| 182 | 182 |
| 183 // Generate a key pair for the Host to use. | 183 // Generate a key pair for the Host to use. |
| 184 // TODO(wez): Move this to the worker thread. | 184 // TODO(wez): Move this to the worker thread. |
| 185 host_key_pair_ = RsaKeyPair::Generate(); | 185 host_key_pair_ = RsaKeyPair::Generate(); |
| 186 | 186 |
| 187 // Create XMPP connection. | |
| 188 std::unique_ptr<SignalStrategy> signal_strategy(new XmppSignalStrategy( | |
| 189 net::ClientSocketFactory::GetDefaultFactory(), | |
| 190 host_context_->url_request_context_getter(), xmpp_server_config_)); | |
| 191 | |
| 192 // Request registration of the host for support. | 187 // Request registration of the host for support. |
| 193 std::unique_ptr<RegisterSupportHostRequest> register_request( | 188 std::unique_ptr<RegisterSupportHostRequest> register_request( |
| 194 new RegisterSupportHostRequest( | 189 new RegisterSupportHostRequest( |
| 195 signal_strategy.get(), host_key_pair_, directory_bot_jid_, | 190 signal_strategy_.get(), host_key_pair_, directory_bot_jid_, |
| 196 base::Bind(&It2MeHost::OnReceivedSupportID, base::Unretained(this)))); | 191 base::Bind(&It2MeHost::OnReceivedSupportID, base::Unretained(this)))); |
| 197 | 192 |
| 198 // Beyond this point nothing can fail, so save the config and request. | 193 // Beyond this point nothing can fail, so save the config and request. |
| 199 signal_strategy_ = std::move(signal_strategy); | |
| 200 register_request_ = std::move(register_request); | 194 register_request_ = std::move(register_request); |
| 201 | 195 |
| 202 // If NAT traversal is off then limit port range to allow firewall pin-holing. | 196 // If NAT traversal is off then limit port range to allow firewall pin-holing. |
| 203 HOST_LOG << "NAT state: " << nat_traversal_enabled_; | 197 HOST_LOG << "NAT state: " << nat_traversal_enabled_; |
| 204 protocol::NetworkSettings network_settings( | 198 protocol::NetworkSettings network_settings( |
| 205 nat_traversal_enabled_ ? | 199 nat_traversal_enabled_ ? |
| 206 protocol::NetworkSettings::NAT_TRAVERSAL_FULL : | 200 protocol::NetworkSettings::NAT_TRAVERSAL_FULL : |
| 207 protocol::NetworkSettings::NAT_TRAVERSAL_DISABLED); | 201 protocol::NetworkSettings::NAT_TRAVERSAL_DISABLED); |
| 208 if (!nat_traversal_enabled_) { | 202 if (!nat_traversal_enabled_) { |
| 209 network_settings.port_range.min_port = | 203 network_settings.port_range.min_port = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 host_status_logger_.reset( | 236 host_status_logger_.reset( |
| 243 new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::IT2ME, | 237 new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::IT2ME, |
| 244 signal_strategy_.get(), directory_bot_jid_)); | 238 signal_strategy_.get(), directory_bot_jid_)); |
| 245 | 239 |
| 246 // Create event logger. | 240 // Create event logger. |
| 247 host_event_logger_ = | 241 host_event_logger_ = |
| 248 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); | 242 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); |
| 249 | 243 |
| 250 // Connect signaling and start the host. | 244 // Connect signaling and start the host. |
| 251 signal_strategy_->Connect(); | 245 signal_strategy_->Connect(); |
| 252 host_->Start(xmpp_server_config_.username); | 246 host_->Start(username_); |
| 253 | 247 |
| 254 SetState(kRequestedAccessCode, ""); | 248 SetState(kRequestedAccessCode, ""); |
| 255 return; | 249 return; |
| 256 } | 250 } |
| 257 | 251 |
| 258 void It2MeHost::OnAccessDenied(const std::string& jid) { | 252 void It2MeHost::OnAccessDenied(const std::string& jid) { |
| 259 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 253 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
| 260 | 254 |
| 261 ++failed_login_attempts_; | 255 ++failed_login_attempts_; |
| 262 if (failed_login_attempts_ == kMaxLoginAttempts) { | 256 if (failed_login_attempts_ == kMaxLoginAttempts) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 } | 538 } |
| 545 | 539 |
| 546 It2MeHostFactory::It2MeHostFactory() {} | 540 It2MeHostFactory::It2MeHostFactory() {} |
| 547 | 541 |
| 548 It2MeHostFactory::~It2MeHostFactory() {} | 542 It2MeHostFactory::~It2MeHostFactory() {} |
| 549 | 543 |
| 550 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( | 544 scoped_refptr<It2MeHost> It2MeHostFactory::CreateIt2MeHost( |
| 551 std::unique_ptr<ChromotingHostContext> context, | 545 std::unique_ptr<ChromotingHostContext> context, |
| 552 policy::PolicyService* policy_service, | 546 policy::PolicyService* policy_service, |
| 553 base::WeakPtr<It2MeHost::Observer> observer, | 547 base::WeakPtr<It2MeHost::Observer> observer, |
| 554 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 548 std::unique_ptr<SignalStrategy> signal_strategy, |
| 549 const std::string& username, |
| 555 const std::string& directory_bot_jid) { | 550 const std::string& directory_bot_jid) { |
| 556 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); | 551 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); |
| 557 | 552 |
| 558 std::unique_ptr<PolicyWatcher> policy_watcher = | 553 std::unique_ptr<PolicyWatcher> policy_watcher = |
| 559 PolicyWatcher::Create(policy_service, context->file_task_runner()); | 554 PolicyWatcher::Create(policy_service, context->file_task_runner()); |
| 560 return new It2MeHost(std::move(context), std::move(policy_watcher), | 555 return new It2MeHost(std::move(context), std::move(policy_watcher), |
| 561 It2MeConfirmationDialog::Create(), observer, | 556 It2MeConfirmationDialog::Create(), observer, |
| 562 xmpp_server_config, directory_bot_jid); | 557 std::move(signal_strategy), username, directory_bot_jid); |
| 563 } | 558 } |
| 564 | 559 |
| 565 } // namespace remoting | 560 } // namespace remoting |
| OLD | NEW |