 Chromium Code Reviews
 Chromium Code Reviews Issue 9270031:
  Enable V2 authentication for Me2Me host.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 9270031:
  Enable V2 authentication for Me2Me host.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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, which is currently | 5 // This file implements a standalone host process for Me2Me, which is currently | 
| 6 // used for the Linux-only Virtual Me2Me build. | 6 // used for the Linux-only Virtual Me2Me build. | 
| 7 | 7 | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "remoting/host/json_host_config.h" | 31 #include "remoting/host/json_host_config.h" | 
| 32 #include "remoting/host/log_to_server.h" | 32 #include "remoting/host/log_to_server.h" | 
| 33 #include "remoting/host/signaling_connector.h" | 33 #include "remoting/host/signaling_connector.h" | 
| 34 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 34 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 
| 35 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 35 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 
| 36 | 36 | 
| 37 #if defined(TOOLKIT_USES_GTK) | 37 #if defined(TOOLKIT_USES_GTK) | 
| 38 #include "ui/gfx/gtk_util.h" | 38 #include "ui/gfx/gtk_util.h" | 
| 39 #endif | 39 #endif | 
| 40 | 40 | 
| 41 using remoting::protocol::SharedSecretHash; | |
| 
Wez
2012/01/23 23:53:49
nit: Do you really need this? protocol::SharedSecr
 
Sergey Ulanov
2012/01/24 06:32:22
Done.
 | |
| 42 | |
| 41 namespace { | 43 namespace { | 
| 42 | 44 | 
| 43 // This is used for tagging system event logs. | 45 // This is used for tagging system event logs. | 
| 44 const char kApplicationName[] = "remoting_me2me_host"; | 46 const char kApplicationName[] = "remoting_me2me_host"; | 
| 45 | 47 | 
| 46 // These are used for parsing the config-file locations from the command line, | 48 // These are used for parsing the config-file locations from the command line, | 
| 47 // and for defining the default locations if the switches are not present. | 49 // and for defining the default locations if the switches are not present. | 
| 48 const char kAuthConfigSwitchName[] = "auth-config"; | 50 const char kAuthConfigSwitchName[] = "auth-config"; | 
| 49 const char kHostConfigSwitchName[] = "host-config"; | 51 const char kHostConfigSwitchName[] = "host-config"; | 
| 50 | 52 | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 &HostProcess::StartHost, base::Unretained(this))); | 105 &HostProcess::StartHost, base::Unretained(this))); | 
| 104 | 106 | 
| 105 message_loop_.Run(); | 107 message_loop_.Run(); | 
| 106 | 108 | 
| 107 return 0; | 109 return 0; | 
| 108 } | 110 } | 
| 109 | 111 | 
| 110 private: | 112 private: | 
| 111 // Read Host config from disk, returning true if successful. | 113 // Read Host config from disk, returning true if successful. | 
| 112 bool LoadConfig(base::MessageLoopProxy* io_message_loop) { | 114 bool LoadConfig(base::MessageLoopProxy* io_message_loop) { | 
| 113 scoped_refptr<remoting::JsonHostConfig> host_config = | 115 scoped_refptr<remoting::JsonHostConfig> host_config = | 
| 
Wez
2012/01/23 23:53:49
nit: Unnecessary remoting::s
 
Sergey Ulanov
2012/01/24 06:32:22
Done.
 | |
| 114 new remoting::JsonHostConfig(host_config_path_, io_message_loop); | 116 new remoting::JsonHostConfig(host_config_path_, io_message_loop); | 
| 115 scoped_refptr<remoting::JsonHostConfig> auth_config = | 117 scoped_refptr<remoting::JsonHostConfig> auth_config = | 
| 116 new remoting::JsonHostConfig(auth_config_path_, io_message_loop); | 118 new remoting::JsonHostConfig(auth_config_path_, io_message_loop); | 
| 117 | 119 | 
| 118 std::string failed_path; | 120 std::string failed_path; | 
| 119 if (!host_config->Read()) { | 121 if (!host_config->Read()) { | 
| 120 failed_path = host_config_path_.value(); | 122 failed_path = host_config_path_.value(); | 
| 121 } else if (!auth_config->Read()) { | 123 } else if (!auth_config->Read()) { | 
| 122 failed_path = auth_config_path_.value(); | 124 failed_path = auth_config_path_.value(); | 
| 123 } | 125 } | 
| 124 if (!failed_path.empty()) { | 126 if (!failed_path.empty()) { | 
| 125 LOG(ERROR) << "Failed to read configuration file " << failed_path; | 127 LOG(ERROR) << "Failed to read configuration file " << failed_path; | 
| 126 return false; | 128 return false; | 
| 127 } | 129 } | 
| 128 | 130 | 
| 129 if (!host_config->GetString(kHostIdConfigPath, &host_id_)) { | 131 if (!host_config->GetString(kHostIdConfigPath, &host_id_)) { | 
| 130 LOG(ERROR) << "host_id is not defined in the config."; | 132 LOG(ERROR) << "host_id is not defined in the config."; | 
| 131 return false; | 133 return false; | 
| 132 } | 134 } | 
| 133 | 135 | 
| 134 if (!key_pair_.Load(host_config)) { | 136 if (!key_pair_.Load(host_config)) { | 
| 135 return false; | 137 return false; | 
| 136 } | 138 } | 
| 137 | 139 | 
| 140 std::string host_secret_hash_string; | |
| 141 if (!host_config->GetString(kHostSecretHashConfigPath, | |
| 142 &host_secret_hash_string)) { | |
| 
Wez
2012/01/23 23:53:49
nit: Indentation.
 
Sergey Ulanov
2012/01/24 06:32:22
Done.
 | |
| 143 LOG(ERROR) << "host_secret_hash is not defined in the config."; | |
| 144 return false; | |
| 145 } | |
| 146 | |
| 147 if (!host_secret_hash_.Parse(host_secret_hash_string)) { | |
| 148 LOG(ERROR) << "Invalid host_secret_hash."; | |
| 149 return false; | |
| 150 } | |
| 151 | |
| 138 // Use an XMPP connection to the Talk network for session signalling. | 152 // Use an XMPP connection to the Talk network for session signalling. | 
| 139 if (!auth_config->GetString(kXmppLoginConfigPath, &xmpp_login_) || | 153 if (!auth_config->GetString(kXmppLoginConfigPath, &xmpp_login_) || | 
| 140 !auth_config->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_)) { | 154 !auth_config->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_)) { | 
| 141 LOG(ERROR) << "XMPP credentials are not defined in the config."; | 155 LOG(ERROR) << "XMPP credentials are not defined in the config."; | 
| 142 return false; | 156 return false; | 
| 143 } | 157 } | 
| 144 | 158 | 
| 145 if (!auth_config->GetString(remoting::kXmppAuthServiceConfigPath, | 159 if (!auth_config->GetString(remoting::kXmppAuthServiceConfigPath, | 
| 146 &xmpp_auth_service_)) { | 160 &xmpp_auth_service_)) { | 
| 147 // For the me2me host, we assume we use the ClientLogin token for | 161 // For the me2me host, we assume we use the ClientLogin token for | 
| 148 // chromiumsync because we do not have an HTTP stack with which we can | 162 // chromiumsync because we do not have an HTTP stack with which we can | 
| 149 // easily request an OAuth2 access token even if we had a RefreshToken for | 163 // easily request an OAuth2 access token even if we had a RefreshToken for | 
| 150 // the account. | 164 // the account. | 
| 151 xmpp_auth_service_ = remoting::kChromotingTokenDefaultServiceName; | 165 xmpp_auth_service_ = remoting::kChromotingTokenDefaultServiceName; | 
| 
Wez
2012/01/23 23:53:49
nit: Here too.
 
Sergey Ulanov
2012/01/24 06:32:22
Done.
 | |
| 152 } | 166 } | 
| 153 | 167 | 
| 154 return true; | 168 return true; | 
| 155 } | 169 } | 
| 156 | 170 | 
| 157 void StartHost() { | 171 void StartHost() { | 
| 158 DCHECK(context_.network_message_loop()->BelongsToCurrentThread()); | 172 DCHECK(context_.network_message_loop()->BelongsToCurrentThread()); | 
| 159 | 173 | 
| 160 signal_strategy_.reset( | 174 signal_strategy_.reset( | 
| 161 new XmppSignalStrategy(context_.jingle_thread(), xmpp_login_, | 175 new XmppSignalStrategy(context_.jingle_thread(), xmpp_login_, | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 176 heartbeat_sender_.reset( | 190 heartbeat_sender_.reset( | 
| 177 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); | 191 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); | 
| 178 | 192 | 
| 179 log_to_server_.reset( | 193 log_to_server_.reset( | 
| 180 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); | 194 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); | 
| 181 host_event_logger_.reset(new HostEventLogger(host_, kApplicationName)); | 195 host_event_logger_.reset(new HostEventLogger(host_, kApplicationName)); | 
| 182 | 196 | 
| 183 host_->Start(); | 197 host_->Start(); | 
| 184 | 198 | 
| 185 // Create authenticator factory. | 199 // Create authenticator factory. | 
| 186 // | |
| 187 // TODO(sergeyu): Currently empty PIN is used. This is a temporary | |
| 188 // hack pending us adding a way to set a PIN. crbug.com/105214 . | |
| 189 scoped_ptr<protocol::AuthenticatorFactory> factory( | 200 scoped_ptr<protocol::AuthenticatorFactory> factory( | 
| 190 new protocol::Me2MeHostAuthenticatorFactory( | 201 new protocol::Me2MeHostAuthenticatorFactory( | 
| 191 xmpp_login_, key_pair_.GenerateCertificate(), | 202 xmpp_login_, key_pair_.GenerateCertificate(), | 
| 192 *key_pair_.private_key(), "")); | 203 *key_pair_.private_key(), host_secret_hash_)); | 
| 193 host_->SetAuthenticatorFactory(factory.Pass()); | 204 host_->SetAuthenticatorFactory(factory.Pass()); | 
| 194 } | 205 } | 
| 195 | 206 | 
| 196 MessageLoop message_loop_; | 207 MessageLoop message_loop_; | 
| 197 base::Thread file_io_thread_; | 208 base::Thread file_io_thread_; | 
| 198 remoting::ChromotingHostContext context_; | 209 remoting::ChromotingHostContext context_; | 
| 
Wez
2012/01/23 23:53:49
nit: Doesn't need remoting::
 
Sergey Ulanov
2012/01/24 06:32:22
Done.
 | |
| 199 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 210 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 
| 200 | 211 | 
| 201 FilePath auth_config_path_; | 212 FilePath auth_config_path_; | 
| 202 FilePath host_config_path_; | 213 FilePath host_config_path_; | 
| 203 | 214 | 
| 204 std::string host_id_; | 215 std::string host_id_; | 
| 205 HostKeyPair key_pair_; | 216 HostKeyPair key_pair_; | 
| 217 SharedSecretHash host_secret_hash_; | |
| 206 std::string xmpp_login_; | 218 std::string xmpp_login_; | 
| 207 std::string xmpp_auth_token_; | 219 std::string xmpp_auth_token_; | 
| 208 std::string xmpp_auth_service_; | 220 std::string xmpp_auth_service_; | 
| 209 | 221 | 
| 210 scoped_ptr<SignalStrategy> signal_strategy_; | 222 scoped_ptr<SignalStrategy> signal_strategy_; | 
| 211 scoped_ptr<SignalingConnector> signaling_connector_; | 223 scoped_ptr<SignalingConnector> signaling_connector_; | 
| 212 scoped_ptr<DesktopEnvironment> desktop_environment_; | 224 scoped_ptr<DesktopEnvironment> desktop_environment_; | 
| 213 scoped_ptr<remoting::HeartbeatSender> heartbeat_sender_; | 225 scoped_ptr<remoting::HeartbeatSender> heartbeat_sender_; | 
| 
Wez
2012/01/23 23:53:49
nit: This doesn't need the remoting:: prefix.
 
Sergey Ulanov
2012/01/24 06:32:22
Done.
 | |
| 214 scoped_ptr<LogToServer> log_to_server_; | 226 scoped_ptr<LogToServer> log_to_server_; | 
| 215 scoped_ptr<HostEventLogger> host_event_logger_; | 227 scoped_ptr<HostEventLogger> host_event_logger_; | 
| 216 scoped_refptr<ChromotingHost> host_; | 228 scoped_refptr<ChromotingHost> host_; | 
| 217 }; | 229 }; | 
| 218 | 230 | 
| 219 } // namespace remoting | 231 } // namespace remoting | 
| 220 | 232 | 
| 221 int main(int argc, char** argv) { | 233 int main(int argc, char** argv) { | 
| 222 CommandLine::Init(argc, argv); | 234 CommandLine::Init(argc, argv); | 
| 223 | 235 | 
| 224 // This object instance is required by Chrome code (for example, | 236 // This object instance is required by Chrome code (for example, | 
| 225 // LazyInstance, MessageLoop). | 237 // LazyInstance, MessageLoop). | 
| 226 base::AtExitManager exit_manager; | 238 base::AtExitManager exit_manager; | 
| 227 | 239 | 
| 228 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 240 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 
| 229 | 241 | 
| 230 #if defined(TOOLKIT_USES_GTK) | 242 #if defined(TOOLKIT_USES_GTK) | 
| 231 // Required for any calls into GTK functions, such as the Disconnect and | 243 // Required for any calls into GTK functions, such as the Disconnect and | 
| 232 // Continue windows, though these should not be used for the Me2Me case | 244 // Continue windows, though these should not be used for the Me2Me case | 
| 233 // (crbug.com/104377). | 245 // (crbug.com/104377). | 
| 234 gfx::GtkInitFromCommandLine(*cmd_line); | 246 gfx::GtkInitFromCommandLine(*cmd_line); | 
| 235 #endif // TOOLKIT_USES_GTK | 247 #endif // TOOLKIT_USES_GTK | 
| 236 | 248 | 
| 237 remoting::HostProcess me2me_host; | 249 remoting::HostProcess me2me_host; | 
| 238 me2me_host.InitWithCommandLine(cmd_line); | 250 me2me_host.InitWithCommandLine(cmd_line); | 
| 239 | 251 | 
| 240 return me2me_host.Run(); | 252 return me2me_host.Run(); | 
| 241 } | 253 } | 
| OLD | NEW |