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

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

Issue 1838313002: Restart the host when the third party auth certificate changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Applied Feedback From sergeyu@ Created 4 years, 8 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 #if defined(OS_MACOSX) 108 #if defined(OS_MACOSX)
109 #include "base/mac/scoped_cftyperef.h" 109 #include "base/mac/scoped_cftyperef.h"
110 #endif // defined(OS_MACOSX) 110 #endif // defined(OS_MACOSX)
111 111
112 #if defined(OS_LINUX) 112 #if defined(OS_LINUX)
113 #include <gtk/gtk.h> 113 #include <gtk/gtk.h>
114 #include <X11/Xlib.h> 114 #include <X11/Xlib.h>
115 #undef Status // Xlib.h #defines this, which breaks protobuf headers. 115 #undef Status // Xlib.h #defines this, which breaks protobuf headers.
116 #include <base/linux_util.h> 116 #include <base/linux_util.h>
117 #include "remoting/host/audio_capturer_linux.h" 117 #include "remoting/host/audio_capturer_linux.h"
118 #include "remoting/host/linux/certificate_watcher.h"
118 #endif // defined(OS_LINUX) 119 #endif // defined(OS_LINUX)
119 120
120 #if defined(OS_WIN) 121 #if defined(OS_WIN)
121 #include <commctrl.h> 122 #include <commctrl.h>
122 #include "base/win/registry.h" 123 #include "base/win/registry.h"
123 #include "base/win/scoped_handle.h" 124 #include "base/win/scoped_handle.h"
124 #include "remoting/host/pairing_registry_delegate_win.h" 125 #include "remoting/host/pairing_registry_delegate_win.h"
125 #include "remoting/host/win/session_desktop_environment.h" 126 #include "remoting/host/win/session_desktop_environment.h"
126 #endif // defined(OS_WIN) 127 #endif // defined(OS_WIN)
127 128
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 const char kDisableAuthenticationSwitchName[] = "disable-authentication"; 173 const char kDisableAuthenticationSwitchName[] = "disable-authentication";
173 174
174 // Maximum time to wait for clean shutdown to occur, before forcing termination 175 // Maximum time to wait for clean shutdown to occur, before forcing termination
175 // of the process. 176 // of the process.
176 const int kShutdownTimeoutSeconds = 15; 177 const int kShutdownTimeoutSeconds = 15;
177 178
178 // Maximum time to wait for reporting host-offline-reason to the service, 179 // Maximum time to wait for reporting host-offline-reason to the service,
179 // before continuing normal process shutdown. 180 // before continuing normal process shutdown.
180 const int kHostOfflineReasonTimeoutSeconds = 10; 181 const int kHostOfflineReasonTimeoutSeconds = 10;
181 182
183 // Delay time to shutdown the host when a change of NSS database is detected.
184 // This is to repeating restarts when continuous writes to the database occur.
185 const int kCertUpdateShutdownDelaySeconds = 2;
186
182 // Host offline reasons not associated with shutting down the host process 187 // Host offline reasons not associated with shutting down the host process
183 // and therefore not expressible through HostExitCodes enum. 188 // and therefore not expressible through HostExitCodes enum.
184 const char kHostOfflineReasonPolicyReadError[] = "POLICY_READ_ERROR"; 189 const char kHostOfflineReasonPolicyReadError[] = "POLICY_READ_ERROR";
185 const char kHostOfflineReasonPolicyChangeRequiresRestart[] = 190 const char kHostOfflineReasonPolicyChangeRequiresRestart[] =
186 "POLICY_CHANGE_REQUIRES_RESTART"; 191 "POLICY_CHANGE_REQUIRES_RESTART";
187 192
188 } // namespace 193 } // namespace
189 194
190 namespace remoting { 195 namespace remoting {
191 196
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // HostChangeNotificationListener::Listener overrides. 268 // HostChangeNotificationListener::Listener overrides.
264 void OnHostDeleted() override; 269 void OnHostDeleted() override;
265 270
266 // Handler of the ChromotingDaemonNetworkMsg_InitializePairingRegistry IPC 271 // Handler of the ChromotingDaemonNetworkMsg_InitializePairingRegistry IPC
267 // message. 272 // message.
268 void OnInitializePairingRegistry( 273 void OnInitializePairingRegistry(
269 IPC::PlatformFileForTransit privileged_key, 274 IPC::PlatformFileForTransit privileged_key,
270 IPC::PlatformFileForTransit unprivileged_key); 275 IPC::PlatformFileForTransit unprivileged_key);
271 276
272 private: 277 private:
278
Sergey Ulanov 2016/03/30 21:02:46 don't need this empty line.
Yuwei 2016/03/31 17:40:06 Done.
273 // See SetState method for a list of allowed state transitions. 279 // See SetState method for a list of allowed state transitions.
274 enum HostState { 280 enum HostState {
275 // Waiting for valid config and policies to be read from the disk. 281 // Waiting for valid config and policies to be read from the disk.
276 // Either the host process has just been started, or it is trying to start 282 // Either the host process has just been started, or it is trying to start
277 // again after temporarily going offline due to policy change or error. 283 // again after temporarily going offline due to policy change or error.
278 HOST_STARTING, 284 HOST_STARTING,
279 285
280 // Host is started and running. 286 // Host is started and running.
281 HOST_STARTED, 287 HOST_STARTED,
282 288
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 void StartHostIfReady(); 365 void StartHostIfReady();
360 void StartHost(); 366 void StartHost();
361 367
362 // Error handler for HeartbeatSender. 368 // Error handler for HeartbeatSender.
363 void OnHeartbeatSuccessful(); 369 void OnHeartbeatSuccessful();
364 void OnUnknownHostIdError(); 370 void OnUnknownHostIdError();
365 371
366 // Error handler for SignalingConnector. 372 // Error handler for SignalingConnector.
367 void OnAuthFailed(); 373 void OnAuthFailed();
368 374
375 // Handler for NSS certificate update event when the host is running.
Sergey Ulanov 2016/03/30 21:02:46 Suggest not referring to NSS in this file. The hos
Yuwei 2016/03/31 17:40:06 Done.
376 void OnNSSCertificateUpdate();
Sergey Ulanov 2016/03/30 21:02:46 Suggest renaming to "OnHostRestartRequested".
Yuwei 2016/03/31 17:40:06 Done.
377
369 void RestartHost(const std::string& host_offline_reason); 378 void RestartHost(const std::string& host_offline_reason);
370 void ShutdownHost(HostExitCodes exit_code); 379 void ShutdownHost(HostExitCodes exit_code);
371 380
372 // Helper methods doing the work needed by RestartHost and ShutdownHost. 381 // Helper methods doing the work needed by RestartHost and ShutdownHost.
373 void GoOffline(const std::string& host_offline_reason); 382 void GoOffline(const std::string& host_offline_reason);
374 void OnHostOfflineReasonAck(bool success); 383 void OnHostOfflineReasonAck(bool success);
375 384
376 #if defined(OS_WIN) 385 #if defined(OS_WIN)
377 // Initializes the pairing registry on Windows. This should be invoked on the 386 // Initializes the pairing registry on Windows. This should be invoked on the
378 // network thread. 387 // network thread.
379 void InitializePairingRegistry( 388 void InitializePairingRegistry(
380 IPC::PlatformFileForTransit privileged_key, 389 IPC::PlatformFileForTransit privileged_key,
381 IPC::PlatformFileForTransit unprivileged_key); 390 IPC::PlatformFileForTransit unprivileged_key);
382 #endif // defined(OS_WIN) 391 #endif // defined(OS_WIN)
383 392
384 // Crashes the process in response to a daemon's request. The daemon passes 393 // Crashes the process in response to a daemon's request. The daemon passes
385 // the location of the code that detected the fatal error resulted in this 394 // the location of the code that detected the fatal error resulted in this
386 // request. 395 // request.
387 void OnCrash(const std::string& function_name, 396 void OnCrash(const std::string& function_name,
388 const std::string& file_name, 397 const std::string& file_name,
389 const int& line_number); 398 const int& line_number);
390 399
391 scoped_ptr<ChromotingHostContext> context_; 400 scoped_ptr<ChromotingHostContext> context_;
392 401
402 #if defined(OS_LINUX)
403 // Watch for NSS database changes and kill the host when changes occur
404 CertificateWatcher cert_watcher_;
405 #endif
406
393 // XMPP server/remoting bot configuration (initialized from the command line). 407 // XMPP server/remoting bot configuration (initialized from the command line).
394 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; 408 XmppSignalStrategy::XmppServerConfig xmpp_server_config_;
395 std::string directory_bot_jid_; 409 std::string directory_bot_jid_;
396 410
397 // Created on the UI thread but used from the network thread. 411 // Created on the UI thread but used from the network thread.
398 base::FilePath host_config_path_; 412 base::FilePath host_config_path_;
399 std::string host_config_; 413 std::string host_config_;
400 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; 414 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_;
401 415
402 // Accessed on the network thread. 416 // Accessed on the network thread.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 490
477 ShutdownWatchdog* shutdown_watchdog_; 491 ShutdownWatchdog* shutdown_watchdog_;
478 492
479 DISALLOW_COPY_AND_ASSIGN(HostProcess); 493 DISALLOW_COPY_AND_ASSIGN(HostProcess);
480 }; 494 };
481 495
482 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, 496 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context,
483 int* exit_code_out, 497 int* exit_code_out,
484 ShutdownWatchdog* shutdown_watchdog) 498 ShutdownWatchdog* shutdown_watchdog)
485 : context_(std::move(context)), 499 : context_(std::move(context)),
500 #if defined(OS_LINUX)
501 cert_watcher_(kCertUpdateShutdownDelaySeconds,
502 base::Bind(&HostProcess::OnNSSCertificateUpdate, this)),
503 #endif
486 state_(HOST_STARTING), 504 state_(HOST_STARTING),
487 use_service_account_(false), 505 use_service_account_(false),
488 enable_vp9_(false), 506 enable_vp9_(false),
489 frame_recorder_buffer_size_(0), 507 frame_recorder_buffer_size_(0),
490 policy_state_(POLICY_INITIALIZING), 508 policy_state_(POLICY_INITIALIZING),
491 host_username_match_required_(false), 509 host_username_match_required_(false),
492 allow_nat_traversal_(true), 510 allow_nat_traversal_(true),
493 allow_relay_(true), 511 allow_relay_(true),
494 allow_pairing_(true), 512 allow_pairing_(true),
495 curtain_required_(false), 513 curtain_required_(false),
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 use_service_account_, host_owner_, local_certificate, key_pair_, 818 use_service_account_, host_owner_, local_certificate, key_pair_,
801 client_domain_, pin_hash_, pairing_registry); 819 client_domain_, pin_hash_, pairing_registry);
802 820
803 host_->set_pairing_registry(pairing_registry); 821 host_->set_pairing_registry(pairing_registry);
804 } else { 822 } else {
805 // ThirdPartyAuthConfig::Parse() leaves the config in a valid state, so 823 // ThirdPartyAuthConfig::Parse() leaves the config in a valid state, so
806 // these URLs are both valid. 824 // these URLs are both valid.
807 DCHECK(third_party_auth_config_.token_url.is_valid()); 825 DCHECK(third_party_auth_config_.token_url.is_valid());
808 DCHECK(third_party_auth_config_.token_validation_url.is_valid()); 826 DCHECK(third_party_auth_config_.token_validation_url.is_valid());
809 827
828 #if defined(OS_LINUX)
829 cert_watcher_.StartOn(context_->file_task_runner(), host_->AsWeakPtr());
830 #endif
831
810 scoped_refptr<protocol::TokenValidatorFactory> token_validator_factory = 832 scoped_refptr<protocol::TokenValidatorFactory> token_validator_factory =
811 new TokenValidatorFactoryImpl(third_party_auth_config_, key_pair_, 833 new TokenValidatorFactoryImpl(third_party_auth_config_, key_pair_,
812 context_->url_request_context_getter()); 834 context_->url_request_context_getter());
813 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithThirdPartyAuth( 835 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithThirdPartyAuth(
814 use_service_account_, host_owner_, local_certificate, key_pair_, 836 use_service_account_, host_owner_, local_certificate, key_pair_,
815 client_domain_, token_validator_factory); 837 client_domain_, token_validator_factory);
816 } 838 }
817 839
818 #if defined(OS_POSIX) 840 #if defined(OS_POSIX)
819 // On Linux and Mac, perform a PAM authorization step after authentication. 841 // On Linux and Mac, perform a PAM authorization step after authentication.
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 char message[1024]; 1720 char message[1024];
1699 base::snprintf(message, sizeof(message), 1721 base::snprintf(message, sizeof(message),
1700 "Requested by %s at %s, line %d.", 1722 "Requested by %s at %s, line %d.",
1701 function_name.c_str(), file_name.c_str(), line_number); 1723 function_name.c_str(), file_name.c_str(), line_number);
1702 base::debug::Alias(message); 1724 base::debug::Alias(message);
1703 1725
1704 // The daemon requested us to crash the process. 1726 // The daemon requested us to crash the process.
1705 CHECK(false) << message; 1727 CHECK(false) << message;
1706 } 1728 }
1707 1729
1730 void HostProcess::OnNSSCertificateUpdate() {
1731 // restarts(shutdowns) the server when the certificate is updated
1732 if (!context_->network_task_runner()->BelongsToCurrentThread()) {
1733 context_->network_task_runner()->PostTask(FROM_HERE,
1734 base::Bind(&HostProcess::OnNSSCertificateUpdate, this));
1735 return;
1736 }
1737 ShutdownHost(kSuccessExitCode);
1738 }
1739
1708 int HostProcessMain() { 1740 int HostProcessMain() {
1709 HOST_LOG << "Starting host process: version " << STRINGIZE(VERSION); 1741 HOST_LOG << "Starting host process: version " << STRINGIZE(VERSION);
1710 1742
1711 #if defined(OS_LINUX) 1743 #if defined(OS_LINUX)
1712 // Required in order for us to run multiple X11 threads. 1744 // Required in order for us to run multiple X11 threads.
1713 XInitThreads(); 1745 XInitThreads();
1714 1746
1715 // Required for any calls into GTK functions, such as the Disconnect and 1747 // Required for any calls into GTK functions, such as the Disconnect and
1716 // Continue windows, though these should not be used for the Me2Me case 1748 // Continue windows, though these should not be used for the Me2Me case
1717 // (crbug.com/104377). 1749 // (crbug.com/104377).
(...skipping 28 matching lines...) Expand all
1746 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); 1778 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds));
1747 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog); 1779 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog);
1748 1780
1749 // Run the main (also UI) message loop until the host no longer needs it. 1781 // Run the main (also UI) message loop until the host no longer needs it.
1750 message_loop.Run(); 1782 message_loop.Run();
1751 1783
1752 return exit_code; 1784 return exit_code;
1753 } 1785 }
1754 1786
1755 } // namespace remoting 1787 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698