Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1681)

Side by Side Diff: remoting/host/remoting_me2me_host.cc

Issue 834673007: Issue 356320: Pinless entry not working on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This file implements a standalone host process for Me2Me. 5 // This file implements a standalone host process for Me2Me.
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 void OnConfigUpdated(const std::string& serialized_config) override; 164 void OnConfigUpdated(const std::string& serialized_config) override;
165 void OnConfigWatcherError() override; 165 void OnConfigWatcherError() override;
166 166
167 // IPC::Listener implementation. 167 // IPC::Listener implementation.
168 bool OnMessageReceived(const IPC::Message& message) override; 168 bool OnMessageReceived(const IPC::Message& message) override;
169 void OnChannelError() override; 169 void OnChannelError() override;
170 170
171 // HostChangeNotificationListener::Listener overrides. 171 // HostChangeNotificationListener::Listener overrides.
172 void OnHostDeleted() override; 172 void OnHostDeleted() override;
173 173
174 // Initializes the pairing registry on Windows. 174 // Handler of the ChromotingDaemonNetworkMsg_InitializePairingRegistry IPC
175 // message.
175 void OnInitializePairingRegistry( 176 void OnInitializePairingRegistry(
176 IPC::PlatformFileForTransit privileged_key, 177 IPC::PlatformFileForTransit privileged_key,
177 IPC::PlatformFileForTransit unprivileged_key); 178 IPC::PlatformFileForTransit unprivileged_key);
178 179
179 private: 180 private:
180 enum HostState { 181 enum HostState {
181 // Host process has just been started. Waiting for config and policies to be 182 // Host process has just been started. Waiting for config and policies to be
182 // read from the disk. 183 // read from the disk.
183 HOST_INITIALIZING, 184 HOST_INITIALIZING,
184 185
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 265
265 // Stops the host and shuts down the process with the specified |exit_code|. 266 // Stops the host and shuts down the process with the specified |exit_code|.
266 void ShutdownHost(HostExitCodes exit_code); 267 void ShutdownHost(HostExitCodes exit_code);
267 268
268 void ScheduleHostShutdown(); 269 void ScheduleHostShutdown();
269 270
270 void ShutdownOnNetworkThread(); 271 void ShutdownOnNetworkThread();
271 272
272 void OnPolicyWatcherShutdown(); 273 void OnPolicyWatcherShutdown();
273 274
275 #if defined(OS_WIN)
276 // Initializes the pairing registry on Windows. This should be invoked on the
277 // network thread.
278 void InitializePairingRegistry(
279 IPC::PlatformFileForTransit privileged_key,
280 IPC::PlatformFileForTransit unprivileged_key);
281 #endif // defined(OS_WIN)
282
274 // Crashes the process in response to a daemon's request. The daemon passes 283 // Crashes the process in response to a daemon's request. The daemon passes
275 // the location of the code that detected the fatal error resulted in this 284 // the location of the code that detected the fatal error resulted in this
276 // request. 285 // request.
277 void OnCrash(const std::string& function_name, 286 void OnCrash(const std::string& function_name,
278 const std::string& file_name, 287 const std::string& file_name,
279 const int& line_number); 288 const int& line_number);
280 289
281 scoped_ptr<ChromotingHostContext> context_; 290 scoped_ptr<ChromotingHostContext> context_;
282 291
283 // Created on the UI thread but used from the network thread. 292 // Created on the UI thread but used from the network thread.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // Used to keep this HostProcess alive until it is shutdown. 354 // Used to keep this HostProcess alive until it is shutdown.
346 scoped_refptr<HostProcess> self_; 355 scoped_refptr<HostProcess> self_;
347 356
348 #if defined(REMOTING_MULTI_PROCESS) 357 #if defined(REMOTING_MULTI_PROCESS)
349 DesktopSessionConnector* desktop_session_connector_; 358 DesktopSessionConnector* desktop_session_connector_;
350 #endif // defined(REMOTING_MULTI_PROCESS) 359 #endif // defined(REMOTING_MULTI_PROCESS)
351 360
352 int* exit_code_out_; 361 int* exit_code_out_;
353 bool signal_parent_; 362 bool signal_parent_;
354 363
355 scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_; 364 scoped_refptr<PairingRegistry> pairing_registry_;
356 365
357 ShutdownWatchdog* shutdown_watchdog_; 366 ShutdownWatchdog* shutdown_watchdog_;
358 }; 367 };
359 368
360 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, 369 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context,
361 int* exit_code_out, 370 int* exit_code_out,
362 ShutdownWatchdog* shutdown_watchdog) 371 ShutdownWatchdog* shutdown_watchdog)
363 : context_(context.Pass()), 372 : context_(context.Pass()),
364 state_(HOST_INITIALIZING), 373 state_(HOST_INITIALIZING),
365 use_service_account_(false), 374 use_service_account_(false),
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 if (state_ != HOST_STARTED) 610 if (state_ != HOST_STARTED)
602 return; 611 return;
603 612
604 std::string local_certificate = key_pair_->GenerateCertificate(); 613 std::string local_certificate = key_pair_->GenerateCertificate();
605 if (local_certificate.empty()) { 614 if (local_certificate.empty()) {
606 LOG(ERROR) << "Failed to generate host certificate."; 615 LOG(ERROR) << "Failed to generate host certificate.";
607 ShutdownHost(kInitializationFailed); 616 ShutdownHost(kInitializationFailed);
608 return; 617 return;
609 } 618 }
610 619
611 scoped_refptr<PairingRegistry> pairing_registry = NULL;
612 if (allow_pairing_) {
613 if (!pairing_registry_delegate_)
614 pairing_registry_delegate_ = CreatePairingRegistryDelegate();
615
616 if (pairing_registry_delegate_) {
617 pairing_registry = new PairingRegistry(context_->file_task_runner(),
618 pairing_registry_delegate_.Pass());
619 }
620 }
621
622 scoped_ptr<protocol::AuthenticatorFactory> factory; 620 scoped_ptr<protocol::AuthenticatorFactory> factory;
623 621
624 if (third_party_auth_config_.is_empty()) { 622 if (third_party_auth_config_.is_empty()) {
623 scoped_refptr<PairingRegistry> pairing_registry;
624 if (allow_pairing_) {
625 // On Windows |pairing_registry_| is initialized in
626 // InitializePairingRegistry().
627 #if !defined(OS_WIN)
628 if (!pairing_registry_) {
629 scoped_ptr<PairingRegistry::Delegate> delegate(
630 CreatePairingRegistryDelegate());
Sergey Ulanov 2015/01/08 17:34:02 nit: this would be more readable with assignment:
weitao 2015/01/08 17:56:29 Done.
631
632 pairing_registry_ = new PairingRegistry(context_->file_task_runner(),
633 delegate.Pass());
Sergey Ulanov 2015/01/08 17:34:02 nit: indentation.
weitao 2015/01/08 17:56:29 Done.
634 }
635 #endif // defined(OS_WIN)
636
637 pairing_registry = pairing_registry_;
638 }
639
625 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithSharedSecret( 640 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithSharedSecret(
626 use_service_account_, host_owner_, local_certificate, key_pair_, 641 use_service_account_, host_owner_, local_certificate, key_pair_,
627 host_secret_hash_, pairing_registry); 642 host_secret_hash_, pairing_registry);
628 643
644 host_->set_pairing_registry(pairing_registry);
629 } else if (third_party_auth_config_.is_valid()) { 645 } else if (third_party_auth_config_.is_valid()) {
630 scoped_ptr<protocol::TokenValidatorFactory> token_validator_factory( 646 scoped_ptr<protocol::TokenValidatorFactory> token_validator_factory(
631 new TokenValidatorFactoryImpl( 647 new TokenValidatorFactoryImpl(
632 third_party_auth_config_, 648 third_party_auth_config_,
633 key_pair_, context_->url_request_context_getter())); 649 key_pair_, context_->url_request_context_getter()));
634 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithThirdPartyAuth( 650 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithThirdPartyAuth(
635 use_service_account_, host_owner_, local_certificate, key_pair_, 651 use_service_account_, host_owner_, local_certificate, key_pair_,
636 token_validator_factory.Pass()); 652 token_validator_factory.Pass());
637 653
638 } else { 654 } else {
639 // TODO(rmsousa): If the policy is bad the host should not go online. It 655 // TODO(rmsousa): If the policy is bad the host should not go online. It
640 // should keep running, but not connected, until the policies are fixed. 656 // should keep running, but not connected, until the policies are fixed.
641 // Having it show up as online and then reject all clients is misleading. 657 // Having it show up as online and then reject all clients is misleading.
642 LOG(ERROR) << "One of the third-party token URLs is empty or invalid. " 658 LOG(ERROR) << "One of the third-party token URLs is empty or invalid. "
643 << "Host will reject all clients until policies are corrected. " 659 << "Host will reject all clients until policies are corrected. "
644 << "TokenUrl: " << third_party_auth_config_.token_url << ", " 660 << "TokenUrl: " << third_party_auth_config_.token_url << ", "
645 << "TokenValidationUrl: " 661 << "TokenValidationUrl: "
646 << third_party_auth_config_.token_validation_url; 662 << third_party_auth_config_.token_validation_url;
647 factory = protocol::Me2MeHostAuthenticatorFactory::CreateRejecting(); 663 factory = protocol::Me2MeHostAuthenticatorFactory::CreateRejecting();
648 } 664 }
649 665
650 #if defined(OS_POSIX) 666 #if defined(OS_POSIX)
651 // On Linux and Mac, perform a PAM authorization step after authentication. 667 // On Linux and Mac, perform a PAM authorization step after authentication.
652 factory.reset(new PamAuthorizationFactory(factory.Pass())); 668 factory.reset(new PamAuthorizationFactory(factory.Pass()));
653 #endif 669 #endif
654 host_->SetAuthenticatorFactory(factory.Pass()); 670 host_->SetAuthenticatorFactory(factory.Pass());
655
656 host_->set_pairing_registry(pairing_registry);
657 } 671 }
658 672
659 // IPC::Listener implementation. 673 // IPC::Listener implementation.
660 bool HostProcess::OnMessageReceived(const IPC::Message& message) { 674 bool HostProcess::OnMessageReceived(const IPC::Message& message) {
661 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 675 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
662 676
663 #if defined(REMOTING_MULTI_PROCESS) 677 #if defined(REMOTING_MULTI_PROCESS)
664 bool handled = true; 678 bool handled = true;
665 IPC_BEGIN_MESSAGE_MAP(HostProcess, message) 679 IPC_BEGIN_MESSAGE_MAP(HostProcess, message)
666 IPC_MESSAGE_HANDLER(ChromotingDaemonMsg_Crash, OnCrash) 680 IPC_MESSAGE_HANDLER(ChromotingDaemonMsg_Crash, OnCrash)
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 } 810 }
797 811
798 void HostProcess::OnHostDeleted() { 812 void HostProcess::OnHostDeleted() {
799 LOG(ERROR) << "Host was deleted from the directory."; 813 LOG(ERROR) << "Host was deleted from the directory.";
800 ShutdownHost(kInvalidHostIdExitCode); 814 ShutdownHost(kInvalidHostIdExitCode);
801 } 815 }
802 816
803 void HostProcess::OnInitializePairingRegistry( 817 void HostProcess::OnInitializePairingRegistry(
804 IPC::PlatformFileForTransit privileged_key, 818 IPC::PlatformFileForTransit privileged_key,
805 IPC::PlatformFileForTransit unprivileged_key) { 819 IPC::PlatformFileForTransit unprivileged_key) {
806 DCHECK(!pairing_registry_delegate_); 820 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
807 821
808 #if defined(OS_WIN) 822 #if defined(OS_WIN)
809 // Initialize the pairing registry delegate. 823 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
810 scoped_ptr<PairingRegistryDelegateWin> delegate( 824 &HostProcess::InitializePairingRegistry,
811 new PairingRegistryDelegateWin()); 825 this, privileged_key, unprivileged_key));
812 bool result = delegate->SetRootKeys(
813 reinterpret_cast<HKEY>(
814 IPC::PlatformFileForTransitToPlatformFile(privileged_key)),
815 reinterpret_cast<HKEY>(
816 IPC::PlatformFileForTransitToPlatformFile(unprivileged_key)));
817 if (!result)
818 return;
819
820 pairing_registry_delegate_ = delegate.Pass();
821 #else // !defined(OS_WIN) 826 #else // !defined(OS_WIN)
822 NOTREACHED(); 827 NOTREACHED();
823 #endif // !defined(OS_WIN) 828 #endif // !defined(OS_WIN)
824 } 829 }
825 830
831 #if defined(OS_WIN)
832 void HostProcess::InitializePairingRegistry(
833 IPC::PlatformFileForTransit privileged_key,
834 IPC::PlatformFileForTransit unprivileged_key) {
835 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
836 // |privileged_key| can be NULL but not |unprivileged_key|.
837 DCHECK(unprivileged_key);
838 // |pairing_registry_| should only be initialized once.
839 DCHECK(!pairing_registry_);
840
841 HKEY privileged_hkey = reinterpret_cast<HKEY>(
842 IPC::PlatformFileForTransitToPlatformFile(privileged_key));
843 HKEY unprivileged_hkey = reinterpret_cast<HKEY>(
844 IPC::PlatformFileForTransitToPlatformFile(unprivileged_key));
845
846 scoped_ptr<PairingRegistryDelegateWin> delegate(
847 new PairingRegistryDelegateWin());
848 delegate->SetRootKeys(privileged_hkey, unprivileged_hkey);
849
850 pairing_registry_ = new PairingRegistry(context_->file_task_runner(),
851 delegate.Pass());
852
853 // (Re)Create the authenticator factory now that |pairing_registry_| has been
854 // initialized.
855 CreateAuthenticatorFactory();
856 }
857 #endif // !defined(OS_WIN)
858
826 // Applies the host config, returning true if successful. 859 // Applies the host config, returning true if successful.
827 bool HostProcess::ApplyConfig(const base::DictionaryValue& config) { 860 bool HostProcess::ApplyConfig(const base::DictionaryValue& config) {
828 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 861 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
829 862
830 if (!config.GetString(kHostIdConfigPath, &host_id_)) { 863 if (!config.GetString(kHostIdConfigPath, &host_id_)) {
831 LOG(ERROR) << "host_id is not defined in the config."; 864 LOG(ERROR) << "host_id is not defined in the config.";
832 return false; 865 return false;
833 } 866 }
834 867
835 std::string key_base64; 868 std::string key_base64;
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); 1536 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds));
1504 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); 1537 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog);
1505 1538
1506 // Run the main (also UI) message loop until the host no longer needs it. 1539 // Run the main (also UI) message loop until the host no longer needs it.
1507 message_loop.Run(); 1540 message_loop.Run();
1508 1541
1509 return exit_code; 1542 return exit_code;
1510 } 1543 }
1511 1544
1512 } // namespace remoting 1545 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698