OLD | NEW |
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 18 matching lines...) Expand all Loading... |
29 #include "media/base/media.h" | 29 #include "media/base/media.h" |
30 #include "net/base/network_change_notifier.h" | 30 #include "net/base/network_change_notifier.h" |
31 #include "net/socket/client_socket_factory.h" | 31 #include "net/socket/client_socket_factory.h" |
32 #include "net/socket/ssl_server_socket.h" | 32 #include "net/socket/ssl_server_socket.h" |
33 #include "net/url_request/url_fetcher.h" | 33 #include "net/url_request/url_fetcher.h" |
34 #include "remoting/base/auto_thread_task_runner.h" | 34 #include "remoting/base/auto_thread_task_runner.h" |
35 #include "remoting/base/breakpad.h" | 35 #include "remoting/base/breakpad.h" |
36 #include "remoting/base/constants.h" | 36 #include "remoting/base/constants.h" |
37 #include "remoting/base/logging.h" | 37 #include "remoting/base/logging.h" |
38 #include "remoting/base/rsa_key_pair.h" | 38 #include "remoting/base/rsa_key_pair.h" |
| 39 #include "remoting/base/util.h" |
39 #include "remoting/host/branding.h" | 40 #include "remoting/host/branding.h" |
40 #include "remoting/host/chromoting_host.h" | 41 #include "remoting/host/chromoting_host.h" |
41 #include "remoting/host/chromoting_host_context.h" | 42 #include "remoting/host/chromoting_host_context.h" |
42 #include "remoting/host/chromoting_messages.h" | 43 #include "remoting/host/chromoting_messages.h" |
43 #include "remoting/host/config_file_watcher.h" | 44 #include "remoting/host/config_file_watcher.h" |
44 #include "remoting/host/config_watcher.h" | 45 #include "remoting/host/config_watcher.h" |
45 #include "remoting/host/desktop_environment.h" | 46 #include "remoting/host/desktop_environment.h" |
46 #include "remoting/host/desktop_session_connector.h" | 47 #include "remoting/host/desktop_session_connector.h" |
47 #include "remoting/host/dns_blackhole_checker.h" | 48 #include "remoting/host/dns_blackhole_checker.h" |
48 #include "remoting/host/heartbeat_sender.h" | 49 #include "remoting/host/heartbeat_sender.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 void ShutdownOnUiThread(); | 221 void ShutdownOnUiThread(); |
221 | 222 |
222 // Applies the host config, returning true if successful. | 223 // Applies the host config, returning true if successful. |
223 bool ApplyConfig(scoped_ptr<JsonHostConfig> config); | 224 bool ApplyConfig(scoped_ptr<JsonHostConfig> config); |
224 | 225 |
225 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); | 226 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); |
226 bool OnHostDomainPolicyUpdate(const std::string& host_domain); | 227 bool OnHostDomainPolicyUpdate(const std::string& host_domain); |
227 bool OnUsernamePolicyUpdate(bool curtain_required, | 228 bool OnUsernamePolicyUpdate(bool curtain_required, |
228 bool username_match_required); | 229 bool username_match_required); |
229 bool OnNatPolicyUpdate(bool nat_traversal_enabled); | 230 bool OnNatPolicyUpdate(bool nat_traversal_enabled); |
| 231 bool OnRelayPolicyUpdate(bool allow_relay); |
| 232 bool OnUdpPortPolicyUpdate(const std::string& udp_port_range); |
230 void OnCurtainPolicyUpdate(bool curtain_required); | 233 void OnCurtainPolicyUpdate(bool curtain_required); |
231 bool OnHostTalkGadgetPrefixPolicyUpdate(const std::string& talkgadget_prefix); | 234 bool OnHostTalkGadgetPrefixPolicyUpdate(const std::string& talkgadget_prefix); |
232 bool OnHostTokenUrlPolicyUpdate( | 235 bool OnHostTokenUrlPolicyUpdate( |
233 const GURL& token_url, | 236 const GURL& token_url, |
234 const GURL& token_validation_url, | 237 const GURL& token_validation_url, |
235 const std::string& token_validation_cert_issuer); | 238 const std::string& token_validation_cert_issuer); |
236 bool OnPairingPolicyUpdate(bool pairing_enabled); | 239 bool OnPairingPolicyUpdate(bool pairing_enabled); |
237 bool OnGnubbyAuthPolicyUpdate(bool enable_gnubby_auth); | 240 bool OnGnubbyAuthPolicyUpdate(bool enable_gnubby_auth); |
238 | 241 |
239 void StartHost(); | 242 void StartHost(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 283 |
281 std::string host_id_; | 284 std::string host_id_; |
282 protocol::SharedSecretHash host_secret_hash_; | 285 protocol::SharedSecretHash host_secret_hash_; |
283 scoped_refptr<RsaKeyPair> key_pair_; | 286 scoped_refptr<RsaKeyPair> key_pair_; |
284 std::string oauth_refresh_token_; | 287 std::string oauth_refresh_token_; |
285 std::string serialized_config_; | 288 std::string serialized_config_; |
286 std::string host_owner_; | 289 std::string host_owner_; |
287 bool use_service_account_; | 290 bool use_service_account_; |
288 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 291 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
289 bool allow_nat_traversal_; | 292 bool allow_nat_traversal_; |
| 293 bool allow_relay_; |
| 294 int min_udp_port_; |
| 295 int max_udp_port_; |
290 std::string talkgadget_prefix_; | 296 std::string talkgadget_prefix_; |
291 bool allow_pairing_; | 297 bool allow_pairing_; |
292 | 298 |
293 bool curtain_required_; | 299 bool curtain_required_; |
294 ThirdPartyAuthConfig third_party_auth_config_; | 300 ThirdPartyAuthConfig third_party_auth_config_; |
295 bool enable_gnubby_auth_; | 301 bool enable_gnubby_auth_; |
296 | 302 |
297 scoped_ptr<OAuthTokenGetter> oauth_token_getter_; | 303 scoped_ptr<OAuthTokenGetter> oauth_token_getter_; |
298 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 304 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
299 scoped_ptr<SignalingConnector> signaling_connector_; | 305 scoped_ptr<SignalingConnector> signaling_connector_; |
(...skipping 17 matching lines...) Expand all Loading... |
317 | 323 |
318 scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_; | 324 scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_; |
319 }; | 325 }; |
320 | 326 |
321 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 327 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
322 int* exit_code_out) | 328 int* exit_code_out) |
323 : context_(context.Pass()), | 329 : context_(context.Pass()), |
324 state_(HOST_INITIALIZING), | 330 state_(HOST_INITIALIZING), |
325 use_service_account_(false), | 331 use_service_account_(false), |
326 allow_nat_traversal_(true), | 332 allow_nat_traversal_(true), |
| 333 allow_relay_(true), |
| 334 min_udp_port_(0), |
| 335 max_udp_port_(0), |
327 allow_pairing_(true), | 336 allow_pairing_(true), |
328 curtain_required_(false), | 337 curtain_required_(false), |
329 enable_gnubby_auth_(false), | 338 enable_gnubby_auth_(false), |
330 #if defined(REMOTING_MULTI_PROCESS) | 339 #if defined(REMOTING_MULTI_PROCESS) |
331 desktop_session_connector_(NULL), | 340 desktop_session_connector_(NULL), |
332 #endif // defined(REMOTING_MULTI_PROCESS) | 341 #endif // defined(REMOTING_MULTI_PROCESS) |
333 self_(this), | 342 self_(this), |
334 exit_code_out_(exit_code_out), | 343 exit_code_out_(exit_code_out), |
335 signal_parent_(false) { | 344 signal_parent_(false) { |
336 StartOnUiThread(); | 345 StartOnUiThread(); |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 } | 838 } |
830 if (policies->GetBoolean( | 839 if (policies->GetBoolean( |
831 policy_hack::PolicyWatcher::kHostMatchUsernamePolicyName, | 840 policy_hack::PolicyWatcher::kHostMatchUsernamePolicyName, |
832 &bool_value)) { | 841 &bool_value)) { |
833 restart_required |= OnUsernamePolicyUpdate(curtain_required, bool_value); | 842 restart_required |= OnUsernamePolicyUpdate(curtain_required, bool_value); |
834 } | 843 } |
835 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, | 844 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, |
836 &bool_value)) { | 845 &bool_value)) { |
837 restart_required |= OnNatPolicyUpdate(bool_value); | 846 restart_required |= OnNatPolicyUpdate(bool_value); |
838 } | 847 } |
| 848 if (policies->GetBoolean(policy_hack::PolicyWatcher::kRelayPolicyName, |
| 849 &bool_value)) { |
| 850 restart_required |= OnRelayPolicyUpdate(bool_value); |
| 851 } |
| 852 std::string udp_port_range; |
| 853 if (policies->GetString(policy_hack::PolicyWatcher::kUdpPortRangePolicyName, |
| 854 &udp_port_range)) { |
| 855 restart_required |= OnUdpPortPolicyUpdate(udp_port_range); |
| 856 } |
| 857 |
839 if (policies->GetString( | 858 if (policies->GetString( |
840 policy_hack::PolicyWatcher::kHostTalkGadgetPrefixPolicyName, | 859 policy_hack::PolicyWatcher::kHostTalkGadgetPrefixPolicyName, |
841 &string_value)) { | 860 &string_value)) { |
842 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(string_value); | 861 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(string_value); |
843 } | 862 } |
844 std::string token_url_string, token_validation_url_string; | 863 std::string token_url_string, token_validation_url_string; |
845 std::string token_validation_cert_issuer; | 864 std::string token_validation_cert_issuer; |
846 if (policies->GetString( | 865 if (policies->GetString( |
847 policy_hack::PolicyWatcher::kHostTokenUrlPolicyName, | 866 policy_hack::PolicyWatcher::kHostTokenUrlPolicyName, |
848 &token_url_string) && | 867 &token_url_string) && |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 if (nat_traversal_enabled) | 954 if (nat_traversal_enabled) |
936 HOST_LOG << "Policy enables NAT traversal."; | 955 HOST_LOG << "Policy enables NAT traversal."; |
937 else | 956 else |
938 HOST_LOG << "Policy disables NAT traversal."; | 957 HOST_LOG << "Policy disables NAT traversal."; |
939 allow_nat_traversal_ = nat_traversal_enabled; | 958 allow_nat_traversal_ = nat_traversal_enabled; |
940 return true; | 959 return true; |
941 } | 960 } |
942 return false; | 961 return false; |
943 } | 962 } |
944 | 963 |
| 964 bool HostProcess::OnRelayPolicyUpdate(bool allow_relay) { |
| 965 // Returns true if the host has to be restarted after this policy update. |
| 966 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 967 |
| 968 if (allow_relay_ != allow_relay) { |
| 969 if (allow_relay) |
| 970 HOST_LOG << "Policy enables use of relay server."; |
| 971 else |
| 972 HOST_LOG << "Policy disables use of relay server."; |
| 973 allow_relay_ = allow_relay; |
| 974 return true; |
| 975 } |
| 976 return false; |
| 977 } |
| 978 |
| 979 bool HostProcess::OnUdpPortPolicyUpdate(const std::string& udp_port_range) { |
| 980 // Returns true if the host has to be restarted after this policy update. |
| 981 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 982 |
| 983 // Use default values if policy setting is empty or invalid. |
| 984 int min_udp_port = 0; |
| 985 int max_udp_port = 0; |
| 986 if (!udp_port_range.empty() && |
| 987 !NetworkSettings::ParsePortRange(udp_port_range, &min_udp_port, |
| 988 &max_udp_port)) { |
| 989 LOG(WARNING) << "Invalid port range policy: \"" << udp_port_range |
| 990 << "\". Using default values."; |
| 991 } |
| 992 |
| 993 if (min_udp_port_ != min_udp_port || max_udp_port_ != max_udp_port) { |
| 994 if (min_udp_port != 0 && max_udp_port != 0) { |
| 995 HOST_LOG << "Policy restricts UDP port range to [" << min_udp_port |
| 996 << ", " << max_udp_port << "]"; |
| 997 } else { |
| 998 HOST_LOG << "Policy does not restrict UDP port range."; |
| 999 } |
| 1000 min_udp_port_ = min_udp_port; |
| 1001 max_udp_port_ = max_udp_port; |
| 1002 return true; |
| 1003 } |
| 1004 return false; |
| 1005 } |
| 1006 |
945 void HostProcess::OnCurtainPolicyUpdate(bool curtain_required) { | 1007 void HostProcess::OnCurtainPolicyUpdate(bool curtain_required) { |
946 // Returns true if the host has to be restarted after this policy update. | 1008 // Returns true if the host has to be restarted after this policy update. |
947 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1009 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
948 | 1010 |
949 #if defined(OS_MACOSX) | 1011 #if defined(OS_MACOSX) |
950 if (curtain_required) { | 1012 if (curtain_required) { |
951 // When curtain mode is in effect on Mac, the host process runs in the | 1013 // When curtain mode is in effect on Mac, the host process runs in the |
952 // user's switched-out session, but launchd will also run an instance at | 1014 // user's switched-out session, but launchd will also run an instance at |
953 // the console login screen. Even if no user is currently logged-on, we | 1015 // the console login screen. Even if no user is currently logged-on, we |
954 // can't support remote-access to the login screen because the current host | 1016 // can't support remote-access to the login screen because the current host |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 new OAuthTokenGetter::OAuthCredentials( | 1142 new OAuthTokenGetter::OAuthCredentials( |
1081 xmpp_server_config_.username, oauth_refresh_token_, | 1143 xmpp_server_config_.username, oauth_refresh_token_, |
1082 use_service_account_)); | 1144 use_service_account_)); |
1083 | 1145 |
1084 oauth_token_getter_.reset(new OAuthTokenGetter( | 1146 oauth_token_getter_.reset(new OAuthTokenGetter( |
1085 oauth_credentials.Pass(), context_->url_request_context_getter())); | 1147 oauth_credentials.Pass(), context_->url_request_context_getter())); |
1086 | 1148 |
1087 signaling_connector_->EnableOAuth(oauth_token_getter_.get()); | 1149 signaling_connector_->EnableOAuth(oauth_token_getter_.get()); |
1088 } | 1150 } |
1089 | 1151 |
1090 NetworkSettings network_settings( | 1152 uint32 network_flags = allow_nat_traversal_ ? |
1091 allow_nat_traversal_ ? | 1153 NetworkSettings::NAT_TRAVERSAL_STUN : 0; |
1092 NetworkSettings::NAT_TRAVERSAL_ENABLED : | 1154 |
1093 NetworkSettings::NAT_TRAVERSAL_DISABLED); | 1155 if (allow_relay_) |
1094 if (!allow_nat_traversal_) { | 1156 network_flags |= NetworkSettings::NAT_TRAVERSAL_RELAY; |
| 1157 |
| 1158 if (allow_relay_ || allow_nat_traversal_) |
| 1159 network_flags |= NetworkSettings::NAT_TRAVERSAL_OUTGOING; |
| 1160 |
| 1161 NetworkSettings network_settings(network_flags); |
| 1162 |
| 1163 if (min_udp_port_ && max_udp_port_) { |
| 1164 network_settings.min_port = min_udp_port_; |
| 1165 network_settings.max_port = max_udp_port_; |
| 1166 } else if (!allow_nat_traversal_) { |
| 1167 // For legacy reasons we have to restrict the port range to a set of default |
| 1168 // values when nat traversal is disabled, even if the port range was not |
| 1169 // set in policy. |
1095 network_settings.min_port = NetworkSettings::kDefaultMinPort; | 1170 network_settings.min_port = NetworkSettings::kDefaultMinPort; |
1096 network_settings.max_port = NetworkSettings::kDefaultMaxPort; | 1171 network_settings.max_port = NetworkSettings::kDefaultMaxPort; |
1097 } | 1172 } |
1098 | 1173 |
1099 host_.reset(new ChromotingHost( | 1174 host_.reset(new ChromotingHost( |
1100 signal_strategy_.get(), | 1175 signal_strategy_.get(), |
1101 desktop_environment_factory_.get(), | 1176 desktop_environment_factory_.get(), |
1102 CreateHostSessionManager(signal_strategy_.get(), network_settings, | 1177 CreateHostSessionManager(signal_strategy_.get(), network_settings, |
1103 context_->url_request_context_getter()), | 1178 context_->url_request_context_getter()), |
1104 context_->audio_task_runner(), | 1179 context_->audio_task_runner(), |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 return exit_code; | 1353 return exit_code; |
1279 } | 1354 } |
1280 | 1355 |
1281 } // namespace remoting | 1356 } // namespace remoting |
1282 | 1357 |
1283 #if !defined(OS_WIN) | 1358 #if !defined(OS_WIN) |
1284 int main(int argc, char** argv) { | 1359 int main(int argc, char** argv) { |
1285 return remoting::HostMain(argc, argv); | 1360 return remoting::HostMain(argc, argv); |
1286 } | 1361 } |
1287 #endif // !defined(OS_WIN) | 1362 #endif // !defined(OS_WIN) |
OLD | NEW |