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

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: 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
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 #include <base/linux_util.h> 115 #include <base/linux_util.h>
116 #include "remoting/host/audio_capturer_linux.h" 116 #include "remoting/host/audio_capturer_linux.h"
117 #include "remoting/host/linux/certificate_watcher.h"
118 #include "remoting/host/linux/certificate_watcher_inhibitor.h"
117 #endif // defined(OS_LINUX) 119 #endif // defined(OS_LINUX)
118 120
119 #if defined(OS_WIN) 121 #if defined(OS_WIN)
120 #include <commctrl.h> 122 #include <commctrl.h>
121 #include "base/win/registry.h" 123 #include "base/win/registry.h"
122 #include "base/win/scoped_handle.h" 124 #include "base/win/scoped_handle.h"
123 #include "remoting/host/pairing_registry_delegate_win.h" 125 #include "remoting/host/pairing_registry_delegate_win.h"
124 #include "remoting/host/win/session_desktop_environment.h" 126 #include "remoting/host/win/session_desktop_environment.h"
125 #endif // defined(OS_WIN) 127 #endif // defined(OS_WIN)
126 128
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 const char kDisableAuthenticationSwitchName[] = "disable-authentication"; 173 const char kDisableAuthenticationSwitchName[] = "disable-authentication";
172 174
173 // 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
174 // of the process. 176 // of the process.
175 const int kShutdownTimeoutSeconds = 15; 177 const int kShutdownTimeoutSeconds = 15;
176 178
177 // 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,
178 // before continuing normal process shutdown. 180 // before continuing normal process shutdown.
179 const int kHostOfflineReasonTimeoutSeconds = 10; 181 const int kHostOfflineReasonTimeoutSeconds = 10;
180 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 = 30;
Sergey Ulanov 2016/03/29 19:40:05 I don't think we need delay restart that long. Cur
Yuwei 2016/03/29 19:57:03 Acknowledged.
Sergey Ulanov 2016/03/29 23:09:54 Normally we use "Acknowledged." response only for
Yuwei 2016/03/30 18:47:45 Done. DelayedTimer is being used.
186
181 // Host offline reasons not associated with shutting down the host process 187 // Host offline reasons not associated with shutting down the host process
182 // and therefore not expressible through HostExitCodes enum. 188 // and therefore not expressible through HostExitCodes enum.
183 const char kHostOfflineReasonPolicyReadError[] = "POLICY_READ_ERROR"; 189 const char kHostOfflineReasonPolicyReadError[] = "POLICY_READ_ERROR";
184 const char kHostOfflineReasonPolicyChangeRequiresRestart[] = 190 const char kHostOfflineReasonPolicyChangeRequiresRestart[] =
185 "POLICY_CHANGE_REQUIRES_RESTART"; 191 "POLICY_CHANGE_REQUIRES_RESTART";
186 192
187 } // namespace 193 } // namespace
188 194
189 namespace remoting { 195 namespace remoting {
190 196
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // HostChangeNotificationListener::Listener overrides. 268 // HostChangeNotificationListener::Listener overrides.
263 void OnHostDeleted() override; 269 void OnHostDeleted() override;
264 270
265 // Handler of the ChromotingDaemonNetworkMsg_InitializePairingRegistry IPC 271 // Handler of the ChromotingDaemonNetworkMsg_InitializePairingRegistry IPC
266 // message. 272 // message.
267 void OnInitializePairingRegistry( 273 void OnInitializePairingRegistry(
268 IPC::PlatformFileForTransit privileged_key, 274 IPC::PlatformFileForTransit privileged_key,
269 IPC::PlatformFileForTransit unprivileged_key); 275 IPC::PlatformFileForTransit unprivileged_key);
270 276
271 private: 277 private:
278
272 // See SetState method for a list of allowed state transitions. 279 // See SetState method for a list of allowed state transitions.
273 enum HostState { 280 enum HostState {
274 // 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.
275 // 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
276 // again after temporarily going offline due to policy change or error. 283 // again after temporarily going offline due to policy change or error.
277 HOST_STARTING, 284 HOST_STARTING,
278 285
279 // Host is started and running. 286 // Host is started and running.
280 HOST_STARTED, 287 HOST_STARTED,
281 288
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 389
383 // Crashes the process in response to a daemon's request. The daemon passes 390 // Crashes the process in response to a daemon's request. The daemon passes
384 // the location of the code that detected the fatal error resulted in this 391 // the location of the code that detected the fatal error resulted in this
385 // request. 392 // request.
386 void OnCrash(const std::string& function_name, 393 void OnCrash(const std::string& function_name,
387 const std::string& file_name, 394 const std::string& file_name,
388 const int& line_number); 395 const int& line_number);
389 396
390 scoped_ptr<ChromotingHostContext> context_; 397 scoped_ptr<ChromotingHostContext> context_;
391 398
399 #if defined(OS_LINUX)
400 // Watch for NSS database changes and kill the host when changes occur
401 CertificateWatcher cert_watcher_;
402 CertificateWatcherInhibitor cert_watcher_inhibitor_;
403 #endif
404
392 // XMPP server/remoting bot configuration (initialized from the command line). 405 // XMPP server/remoting bot configuration (initialized from the command line).
393 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; 406 XmppSignalStrategy::XmppServerConfig xmpp_server_config_;
394 std::string directory_bot_jid_; 407 std::string directory_bot_jid_;
395 408
396 // Created on the UI thread but used from the network thread. 409 // Created on the UI thread but used from the network thread.
397 base::FilePath host_config_path_; 410 base::FilePath host_config_path_;
398 std::string host_config_; 411 std::string host_config_;
399 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; 412 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_;
400 413
401 // Accessed on the network thread. 414 // Accessed on the network thread.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 488
476 ShutdownWatchdog* shutdown_watchdog_; 489 ShutdownWatchdog* shutdown_watchdog_;
477 490
478 DISALLOW_COPY_AND_ASSIGN(HostProcess); 491 DISALLOW_COPY_AND_ASSIGN(HostProcess);
479 }; 492 };
480 493
481 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, 494 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context,
482 int* exit_code_out, 495 int* exit_code_out,
483 ShutdownWatchdog* shutdown_watchdog) 496 ShutdownWatchdog* shutdown_watchdog)
484 : context_(std::move(context)), 497 : context_(std::move(context)),
498 #if defined(OS_LINUX)
499 cert_watcher_(context_->file_task_runner(),
500 context_->network_task_runner(),
501 kCertUpdateShutdownDelaySeconds,
502 base::Bind(&HostProcess::ShutdownHost,
503 this, kSuccessExitCode)),
504 cert_watcher_inhibitor_(cert_watcher_),
505 #endif
485 state_(HOST_STARTING), 506 state_(HOST_STARTING),
486 use_service_account_(false), 507 use_service_account_(false),
487 enable_vp9_(false), 508 enable_vp9_(false),
488 frame_recorder_buffer_size_(0), 509 frame_recorder_buffer_size_(0),
489 policy_state_(POLICY_INITIALIZING), 510 policy_state_(POLICY_INITIALIZING),
490 host_username_match_required_(false), 511 host_username_match_required_(false),
491 allow_nat_traversal_(true), 512 allow_nat_traversal_(true),
492 allow_relay_(true), 513 allow_relay_(true),
493 allow_pairing_(true), 514 allow_pairing_(true),
494 curtain_required_(false), 515 curtain_required_(false),
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 use_service_account_, host_owner_, local_certificate, key_pair_, 820 use_service_account_, host_owner_, local_certificate, key_pair_,
800 client_domain_, pin_hash_, pairing_registry); 821 client_domain_, pin_hash_, pairing_registry);
801 822
802 host_->set_pairing_registry(pairing_registry); 823 host_->set_pairing_registry(pairing_registry);
803 } else { 824 } else {
804 // ThirdPartyAuthConfig::Parse() leaves the config in a valid state, so 825 // ThirdPartyAuthConfig::Parse() leaves the config in a valid state, so
805 // these URLs are both valid. 826 // these URLs are both valid.
806 DCHECK(third_party_auth_config_.token_url.is_valid()); 827 DCHECK(third_party_auth_config_.token_url.is_valid());
807 DCHECK(third_party_auth_config_.token_validation_url.is_valid()); 828 DCHECK(third_party_auth_config_.token_validation_url.is_valid());
808 829
830 #if defined(OS_LINUX)
831 cert_watcher_.Start();
832 host_->AddStatusObserver(&cert_watcher_inhibitor_);
Sergey Ulanov 2016/03/29 19:40:05 You also need to call RemoveStatusObserver() befor
Yuwei 2016/03/29 19:57:03 Acknowledged.
Yuwei 2016/03/29 21:37:41 I am a little bit confused... So the host will not
Sergey Ulanov 2016/03/29 23:09:54 In general when using the observer pattern it's ne
Yuwei 2016/03/30 18:47:45 Done. Observer will be added or removed in Start()
833 #endif
834
809 scoped_refptr<protocol::TokenValidatorFactory> token_validator_factory = 835 scoped_refptr<protocol::TokenValidatorFactory> token_validator_factory =
810 new TokenValidatorFactoryImpl(third_party_auth_config_, key_pair_, 836 new TokenValidatorFactoryImpl(third_party_auth_config_, key_pair_,
811 context_->url_request_context_getter()); 837 context_->url_request_context_getter());
812 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithThirdPartyAuth( 838 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithThirdPartyAuth(
813 use_service_account_, host_owner_, local_certificate, key_pair_, 839 use_service_account_, host_owner_, local_certificate, key_pair_,
814 client_domain_, token_validator_factory); 840 client_domain_, token_validator_factory);
815 } 841 }
816 842
817 #if defined(OS_POSIX) 843 #if defined(OS_POSIX)
818 // On Linux and Mac, perform a PAM authorization step after authentication. 844 // On Linux and Mac, perform a PAM authorization step after authentication.
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); 1771 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds));
1746 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog); 1772 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog);
1747 1773
1748 // Run the main (also UI) message loop until the host no longer needs it. 1774 // Run the main (also UI) message loop until the host no longer needs it.
1749 message_loop.Run(); 1775 message_loop.Run();
1750 1776
1751 return exit_code; 1777 return exit_code;
1752 } 1778 }
1753 1779
1754 } // namespace remoting 1780 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698