diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-07 05:48:20 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-07 05:48:20 +0000 |
commit | b5a6afe4d47adfae0c403b00c393127955572453 (patch) | |
tree | 766577e4f33bcc923871c710be27cede682fded8 /remoting | |
parent | d93ad24560fc76f2d7912095aa6efd009a2e9b04 (diff) | |
download | chromium_src-b5a6afe4d47adfae0c403b00c393127955572453.zip chromium_src-b5a6afe4d47adfae0c403b00c393127955572453.tar.gz chromium_src-b5a6afe4d47adfae0c403b00c393127955572453.tar.bz2 |
Remove dependency on HostConfig from ChromotingHost and other classes.
Remove dependency on HostConfig from ChromotingHost,
RegisterSupportHostRequest and HeartbeatSender. Also replaced
ChromotingHost::SetSharedSecret() with SetAuthenticatorFactory() to
support new authentication mechanism.
BUG=105214
Review URL: http://codereview.chromium.org/9022045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116818 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
20 files changed, 169 insertions, 197 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index 1fa3ae2..21a3d3e 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -24,7 +24,6 @@ #include "remoting/protocol/input_stub.h" #include "remoting/protocol/jingle_session_manager.h" #include "remoting/protocol/session_config.h" -#include "remoting/protocol/v1_authenticator.h" using remoting::protocol::ConnectionToClient; using remoting::protocol::InputStub; @@ -32,13 +31,11 @@ using remoting::protocol::InputStub; namespace remoting { ChromotingHost::ChromotingHost(ChromotingHostContext* context, - MutableHostConfig* config, SignalStrategy* signal_strategy, DesktopEnvironment* environment, bool allow_nat_traversal) : context_(context), desktop_environment_(environment), - config_(config), allow_nat_traversal_(allow_nat_traversal), have_shared_secret_(false), signal_strategy_(signal_strategy), @@ -67,12 +64,6 @@ void ChromotingHost::Start() { return; state_ = kStarted; - // Assign key and certificate to server. - if (!key_pair_.Load(config_)) { - LOG(ERROR) << "Failed to load key pair for the host."; - return; - } - // Create and start session manager. session_manager_.reset( new protocol::JingleSessionManager(context_->network_message_loop())); @@ -130,12 +121,10 @@ void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { status_observers_.push_back(observer); } -void ChromotingHost::SetSharedSecret(const std::string& shared_secret) { +void ChromotingHost::SetAuthenticatorFactory( + scoped_ptr<protocol::AuthenticatorFactory> authenticator_factory) { DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); - session_manager_->set_authenticator_factory( - new protocol::V1HostAuthenticatorFactory( - key_pair_.GenerateCertificate(), key_pair_.private_key(), - shared_secret)); + session_manager_->set_authenticator_factory(authenticator_factory.Pass()); } //////////////////////////////////////////////////////////////////////////// diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h index 6af0f2c..1c1022f 100644 --- a/remoting/host/chromoting_host.h +++ b/remoting/host/chromoting_host.h @@ -19,6 +19,7 @@ #include "remoting/host/ui_strings.h" #include "remoting/jingle_glue/jingle_thread.h" #include "remoting/jingle_glue/signal_strategy.h" +#include "remoting/protocol/authenticator.h" #include "remoting/protocol/session_manager.h" #include "remoting/protocol/connection_to_client.h" @@ -34,7 +35,6 @@ class Capturer; class ChromotingHostContext; class DesktopEnvironment; class Encoder; -class MutableHostConfig; class ScreenRecorder; // A class to implement the functionality of a host process. @@ -67,7 +67,6 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, // The caller must ensure that |context|, |signal_strategy| and // |environment| out-live the host. ChromotingHost(ChromotingHostContext* context, - MutableHostConfig* config, SignalStrategy* signal_strategy, DesktopEnvironment* environment, bool allow_nat_traversal); @@ -90,10 +89,14 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, // started. void AddStatusObserver(HostStatusObserver* observer); - // Sets shared secret for the host. All incoming connections are - // rejected if shared secret isn't set. Must be called on the - // network thread after the host is started. - void SetSharedSecret(const std::string& shared_secret); + // Sets the authenticator factory to use for incoming + // connections. Incoming connections are rejected until + // authenticator factory is set. Must be called on the network + // thread after the host is started. Must not be called more than + // once per host instance because it may not be safe to delete + // factory before all authenticators it created are deleted. + void SetAuthenticatorFactory( + scoped_ptr<protocol::AuthenticatorFactory> authenticator_factory); //////////////////////////////////////////////////////////////////////////// // ClientSession::EventHandler implementation. @@ -170,8 +173,6 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, // Parameters specified when the host was created. ChromotingHostContext* context_; DesktopEnvironment* desktop_environment_; - scoped_refptr<MutableHostConfig> config_; - HostKeyPair key_pair_; bool allow_nat_traversal_; // TODO(lambroslambrou): The following is a temporary fix for Me2Me diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc index 9e210a6..b1a364e 100644 --- a/remoting/host/chromoting_host_unittest.cc +++ b/remoting/host/chromoting_host_unittest.cc @@ -94,8 +94,7 @@ class ChromotingHostTest : public testing::Test { new DesktopEnvironment(&context_, capturer, event_executor_)); host_ = new ChromotingHost( - &context_, config_, &signal_strategy_, - desktop_environment_.get(), false); + &context_, &signal_strategy_, desktop_environment_.get(), false); disconnect_window_ = new MockDisconnectWindow(); continue_window_ = new MockContinueWindow(); diff --git a/remoting/host/heartbeat_sender.cc b/remoting/host/heartbeat_sender.cc index 27ac108..f1ba515 100644 --- a/remoting/host/heartbeat_sender.cc +++ b/remoting/host/heartbeat_sender.cc @@ -10,7 +10,6 @@ #include "base/string_number_conversions.h" #include "base/time.h" #include "remoting/base/constants.h" -#include "remoting/host/host_config.h" #include "remoting/jingle_glue/iq_sender.h" #include "remoting/jingle_glue/jingle_thread.h" #include "remoting/jingle_glue/signal_strategy.h" @@ -23,6 +22,7 @@ using buzz::XmlElement; namespace remoting { namespace { + const char kHeartbeatQueryTag[] = "heartbeat"; const char kHostIdAttr[] = "hostid"; const char kHeartbeatSignatureTag[] = "signature"; @@ -32,56 +32,37 @@ const char kHeartbeatResultTag[] = "heartbeat-result"; const char kSetIntervalTag[] = "set-interval"; const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes. -} - -HeartbeatSender::HeartbeatSender() - : state_(CREATED), - signal_strategy_(NULL), - interval_ms_(kDefaultHeartbeatIntervalMs) { -} - -HeartbeatSender::~HeartbeatSender() { - if (signal_strategy_) - signal_strategy_->RemoveListener(this); -} - -bool HeartbeatSender::Init(SignalStrategy* signal_strategy, - MutableHostConfig* config) { - DCHECK(state_ == CREATED); - if (!config->GetString(kHostIdConfigPath, &host_id_)) { - LOG(ERROR) << "host_id is not defined in the config."; - return false; - } +} // namespace - if (!key_pair_.Load(config)) { - return false; - } +HeartbeatSender::HeartbeatSender( + const std::string& host_id, + SignalStrategy* signal_strategy, + HostKeyPair* key_pair) + : host_id_(host_id), + signal_strategy_(signal_strategy), + key_pair_(key_pair), + interval_ms_(kDefaultHeartbeatIntervalMs) { + DCHECK(signal_strategy_); + DCHECK(key_pair_); - DCHECK(signal_strategy); - signal_strategy_ = signal_strategy; signal_strategy_->AddListener(this); - state_ = INITIALIZED; - - // Update the state if the |signal_strategy_| is already connected. + // Start heartbeats if the |signal_strategy_| is already connected. OnSignalStrategyStateChange(signal_strategy_->GetState()); +} - return true; +HeartbeatSender::~HeartbeatSender() { + signal_strategy_->RemoveListener(this); } void HeartbeatSender::OnSignalStrategyStateChange(SignalStrategy::State state) { if (state == SignalStrategy::CONNECTED) { - DCHECK(state_ == INITIALIZED || state_ == STOPPED); - state_ = STARTED; - iq_sender_.reset(new IqSender(signal_strategy_)); - DoSendStanza(); timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(interval_ms_), this, &HeartbeatSender::DoSendStanza); } else if (state == SignalStrategy::DISCONNECTED) { - state_ = STOPPED; request_.reset(); iq_sender_.reset(); timer_.Stop(); @@ -89,8 +70,6 @@ void HeartbeatSender::OnSignalStrategyStateChange(SignalStrategy::State state) { } void HeartbeatSender::DoSendStanza() { - DCHECK_EQ(state_, STARTED); - VLOG(1) << "Sending heartbeat stanza to " << kChromotingBotJid; request_.reset(iq_sender_->SendIq( buzz::STR_SET, kChromotingBotJid, CreateHeartbeatMessage(), @@ -133,7 +112,7 @@ void HeartbeatSender::SetInterval(int interval) { interval_ms_ = interval; // Restart the timer with the new interval. - if (state_ == STARTED) { + if (timer_.IsRunning()) { timer_.Stop(); timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(interval_ms_), this, &HeartbeatSender::DoSendStanza); @@ -159,7 +138,7 @@ XmlElement* HeartbeatSender::CreateSignature() { QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); std::string message = signal_strategy_->GetLocalJid() + ' ' + time_str; - std::string signature(key_pair_.GetSignature(message)); + std::string signature(key_pair_->GetSignature(message)); signature_tag->AddText(signature); return signature_tag; diff --git a/remoting/host/heartbeat_sender.h b/remoting/host/heartbeat_sender.h index f50e156..24a45ba 100644 --- a/remoting/host/heartbeat_sender.h +++ b/remoting/host/heartbeat_sender.h @@ -28,7 +28,6 @@ namespace remoting { class HostKeyPair; class IqRequest; class IqSender; -class MutableHostConfig; // HeartbeatSender periodically sends heartbeat stanzas to the Chromoting Bot. // Each heartbeat stanza looks as follows: @@ -64,15 +63,14 @@ class MutableHostConfig; // server. class HeartbeatSender : public SignalStrategy::Listener { public: - HeartbeatSender(); + // Doesn't take ownership of |signal_strategy| or |key_pair|. Both + // parameters must outlive this object. Heartbeats will start when + // the supplied SignalStrategy enters the CONNECTED state. + HeartbeatSender(const std::string& host_id, + SignalStrategy* signal_strategy, + HostKeyPair* key_pair); virtual ~HeartbeatSender(); - // Initializes the HeartbeatSender. Returns false if the |config| is - // invalid (e.g. private key cannot be parsed). SignalStrategy must - // outlive this object. Heartbeats will start when the supplied - // SignalStrategy enters the CONNECTED state. - bool Init(SignalStrategy* signal_strategy, MutableHostConfig* config); - // SignalStrategy::Listener interface. virtual void OnSignalStrategyStateChange( SignalStrategy::State state) OVERRIDE; @@ -82,13 +80,6 @@ class HeartbeatSender : public SignalStrategy::Listener { FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, CreateHeartbeatMessage); FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponse); - enum State { - CREATED, - INITIALIZED, - STARTED, - STOPPED, - }; - void DoSendStanza(); void ProcessResponse(const buzz::XmlElement* response); void SetInterval(int interval); @@ -98,10 +89,9 @@ class HeartbeatSender : public SignalStrategy::Listener { buzz::XmlElement* CreateHeartbeatMessage(); buzz::XmlElement* CreateSignature(); - State state_; - SignalStrategy* signal_strategy_; std::string host_id_; - HostKeyPair key_pair_; + SignalStrategy* signal_strategy_; + HostKeyPair* key_pair_; scoped_ptr<IqSender> iq_sender_; scoped_ptr<IqRequest> request_; int interval_ms_; diff --git a/remoting/host/heartbeat_sender_unittest.cc b/remoting/host/heartbeat_sender_unittest.cc index 854a6a6..0b619af 100644 --- a/remoting/host/heartbeat_sender_unittest.cc +++ b/remoting/host/heartbeat_sender_unittest.cc @@ -12,7 +12,6 @@ #include "base/string_number_conversions.h" #include "remoting/base/constants.h" #include "remoting/host/host_key_pair.h" -#include "remoting/host/in_memory_host_config.h" #include "remoting/host/test_key_pair.h" #include "remoting/jingle_glue/iq_sender.h" #include "remoting/jingle_glue/mock_objects.h" @@ -52,9 +51,7 @@ ACTION_P(RemoveListener, list) { class HeartbeatSenderTest : public testing::Test { protected: virtual void SetUp() OVERRIDE { - config_ = new InMemoryHostConfig(); - config_->SetString(kHostIdConfigPath, kHostId); - config_->SetString(kPrivateKeyConfigPath, kTestHostKeyPair); + ASSERT_TRUE(key_pair_.LoadFromString(kTestHostKeyPair)); EXPECT_CALL(signal_strategy_, GetState()) .WillOnce(Return(SignalStrategy::DISCONNECTED)); @@ -65,8 +62,8 @@ class HeartbeatSenderTest : public testing::Test { EXPECT_CALL(signal_strategy_, GetLocalJid()) .WillRepeatedly(Return(kTestJid)); - heartbeat_sender_.reset(new HeartbeatSender()); - ASSERT_TRUE(heartbeat_sender_->Init(&signal_strategy_, config_)); + heartbeat_sender_.reset( + new HeartbeatSender(kHostId, &signal_strategy_, &key_pair_)); } virtual void TearDown() OVERRIDE { @@ -77,7 +74,7 @@ class HeartbeatSenderTest : public testing::Test { MessageLoop message_loop_; MockSignalStrategy signal_strategy_; std::set<SignalStrategy::Listener*> signal_strategy_listeners_; - scoped_refptr<InMemoryHostConfig> config_; + HostKeyPair key_pair_; scoped_ptr<HeartbeatSender> heartbeat_sender_; }; diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc index 491e1cf..844af25 100644 --- a/remoting/host/plugin/host_script_object.cc +++ b/remoting/host/plugin/host_script_object.cc @@ -15,14 +15,13 @@ #include "remoting/host/chromoting_host.h" #include "remoting/host/chromoting_host_context.h" #include "remoting/host/desktop_environment.h" -#include "remoting/host/host_config.h" #include "remoting/host/host_key_pair.h" #include "remoting/host/host_secret.h" -#include "remoting/host/in_memory_host_config.h" #include "remoting/host/it2me_host_user_interface.h" #include "remoting/host/plugin/host_log_handler.h" #include "remoting/host/plugin/policy_hack/nat_policy.h" #include "remoting/host/register_support_host_request.h" +#include "remoting/protocol/it2me_host_authenticator_factory.h" namespace remoting { @@ -501,13 +500,9 @@ void HostNPScriptObject::FinishConnectNetworkThread( return; } - scoped_refptr<MutableHostConfig> host_config = new InMemoryHostConfig(); - // Generate a key pair for the Host to use. // TODO(wez): Move this to the worker thread. - HostKeyPair host_key_pair; - host_key_pair.Generate(); - host_key_pair.Save(host_config); + host_key_pair_.Generate(); // Create XMPP connection. scoped_ptr<SignalStrategy> signal_strategy( @@ -516,25 +511,19 @@ void HostNPScriptObject::FinishConnectNetworkThread( // Request registration of the host for support. scoped_ptr<RegisterSupportHostRequest> register_request( - new RegisterSupportHostRequest()); - if (!register_request->Init( - signal_strategy.get(), - host_config.get(), + new RegisterSupportHostRequest( + signal_strategy.get(), &host_key_pair_, base::Bind(&HostNPScriptObject::OnReceivedSupportID, - base::Unretained(this)))) { - SetState(kError); - return; - } + base::Unretained(this)))); // Beyond this point nothing can fail, so save the config and request. - host_config_ = host_config; signal_strategy_.reset(signal_strategy.release()); register_request_.reset(register_request.release()); // Create the Host. LOG(INFO) << "NAT state: " << nat_traversal_enabled_; host_ = new ChromotingHost( - &host_context_, host_config_, signal_strategy_.get(), + &host_context_, signal_strategy_.get(), desktop_environment_.get(), nat_traversal_enabled_); host_->AddStatusObserver(this); if (enable_log_to_server_) { @@ -679,7 +668,11 @@ void HostNPScriptObject::OnReceivedSupportID( std::string host_secret = GenerateSupportHostSecret(); std::string access_code = support_id + host_secret; - host_->SetSharedSecret(access_code); + scoped_ptr<protocol::AuthenticatorFactory> factory( + new protocol::It2MeHostAuthenticatorFactory( + host_key_pair_.GenerateCertificate(), host_key_pair_.private_key(), + access_code)); + host_->SetAuthenticatorFactory(factory.Pass()); { base::AutoLock lock(access_code_lock_); diff --git a/remoting/host/plugin/host_script_object.h b/remoting/host/plugin/host_script_object.h index 0f8d211..fcbecb4 100644 --- a/remoting/host/plugin/host_script_object.h +++ b/remoting/host/plugin/host_script_object.h @@ -19,6 +19,7 @@ #include "base/time.h" #include "remoting/base/plugin_message_loop_proxy.h" #include "remoting/host/chromoting_host_context.h" +#include "remoting/host/host_key_pair.h" #include "remoting/host/host_status_observer.h" #include "remoting/host/log_to_server.h" #include "remoting/host/plugin/host_plugin_utils.h" @@ -178,7 +179,7 @@ class HostNPScriptObject : public HostStatusObserver { scoped_refptr<PluginMessageLoopProxy> plugin_message_loop_proxy_; ChromotingHostContext host_context_; - scoped_refptr<MutableHostConfig> host_config_; + HostKeyPair host_key_pair_; scoped_ptr<SignalStrategy> signal_strategy_; scoped_ptr<RegisterSupportHostRequest> register_request_; scoped_ptr<LogToServer> log_to_server_; diff --git a/remoting/host/register_support_host_request.cc b/remoting/host/register_support_host_request.cc index 63caadf..010ab6e 100644 --- a/remoting/host/register_support_host_request.cc +++ b/remoting/host/register_support_host_request.cc @@ -35,8 +35,17 @@ const char kSupportIdTag[] = "support-id"; const char kSupportIdLifetimeTag[] = "support-id-lifetime"; } -RegisterSupportHostRequest::RegisterSupportHostRequest() - : signal_strategy_(NULL) { +RegisterSupportHostRequest::RegisterSupportHostRequest( + SignalStrategy* signal_strategy, + HostKeyPair* key_pair, + const RegisterCallback& callback) + : signal_strategy_(signal_strategy), + key_pair_(key_pair), + callback_(callback) { + DCHECK(signal_strategy_); + DCHECK(key_pair_); + signal_strategy_->AddListener(this); + iq_sender_.reset(new IqSender(signal_strategy_)); } RegisterSupportHostRequest::~RegisterSupportHostRequest() { @@ -44,21 +53,6 @@ RegisterSupportHostRequest::~RegisterSupportHostRequest() { signal_strategy_->RemoveListener(this); } -bool RegisterSupportHostRequest::Init(SignalStrategy* signal_strategy, - HostConfig* config, - const RegisterCallback& callback) { - if (!key_pair_.Load(config)) { - return false; - } - - callback_ = callback; - signal_strategy_ = signal_strategy; - signal_strategy_->AddListener(this); - iq_sender_.reset(new IqSender(signal_strategy_)); - - return true; -} - void RegisterSupportHostRequest::OnSignalStrategyStateChange( SignalStrategy::State state) { if (state == SignalStrategy::CONNECTED) { @@ -86,7 +80,7 @@ XmlElement* RegisterSupportHostRequest::CreateRegistrationRequest( QName(kChromotingXmlNamespace, kRegisterQueryTag)); XmlElement* public_key = new XmlElement( QName(kChromotingXmlNamespace, kPublicKeyTag)); - public_key->AddText(key_pair_.GetPublicKey()); + public_key->AddText(key_pair_->GetPublicKey()); query->AddElement(public_key); query->AddElement(CreateSignature(jid)); return query; @@ -103,7 +97,7 @@ XmlElement* RegisterSupportHostRequest::CreateSignature( QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); std::string message = jid + ' ' + time_str; - std::string signature(key_pair_.GetSignature(message)); + std::string signature(key_pair_->GetSignature(message)); signature_tag->AddText(signature); return signature_tag; diff --git a/remoting/host/register_support_host_request.h b/remoting/host/register_support_host_request.h index 16e8a61..6678cca 100644 --- a/remoting/host/register_support_host_request.h +++ b/remoting/host/register_support_host_request.h @@ -41,19 +41,18 @@ class RegisterSupportHostRequest : public SignalStrategy::Listener { typedef base::Callback<void(bool, const std::string&, const base::TimeDelta&)> RegisterCallback; - RegisterSupportHostRequest(); - virtual ~RegisterSupportHostRequest(); - - // Initializes the registration to use the |signal_startegy| and to - // notify |callback| upon completion or failure. Returns false on - // falure (e.g. config is invalid). Callback is never called if the - // bot malfunctions and doesn't respond to the request. + // Doesn't take ownership of |signal_strategy| or |key_pair|. Both + // |signal_strategy| and |key_pair| must outlive this + // object. |callback| is called when registration response is + // received from the server. Callback is never called if the bot + // malfunctions and doesn't respond to the request. // // TODO(sergeyu): This class should have timeout for the bot // response. - bool Init(SignalStrategy* signal_strategy, - HostConfig* config, - const RegisterCallback& callback); + RegisterSupportHostRequest(SignalStrategy* signal_strategy, + HostKeyPair* key_pair, + const RegisterCallback& callback); + virtual ~RegisterSupportHostRequest(); // HostStatusObserver implementation. virtual void OnSignalStrategyStateChange( @@ -76,10 +75,11 @@ class RegisterSupportHostRequest : public SignalStrategy::Listener { bool success, const std::string& support_id, base::TimeDelta lifetime); SignalStrategy* signal_strategy_; + HostKeyPair* key_pair_; RegisterCallback callback_; + scoped_ptr<IqSender> iq_sender_; scoped_ptr<IqRequest> request_; - HostKeyPair key_pair_; DISALLOW_COPY_AND_ASSIGN(RegisterSupportHostRequest); }; diff --git a/remoting/host/register_support_host_request_unittest.cc b/remoting/host/register_support_host_request_unittest.cc index 92eaef2..4dea7ef 100644 --- a/remoting/host/register_support_host_request_unittest.cc +++ b/remoting/host/register_support_host_request_unittest.cc @@ -57,8 +57,7 @@ class RegisterSupportHostRequestTest : public testing::Test { public: protected: virtual void SetUp() { - config_ = new InMemoryHostConfig(); - config_->SetString(kPrivateKeyConfigPath, kTestHostKeyPair); + ASSERT_TRUE(key_pair_.LoadFromString(kTestHostKeyPair)); EXPECT_CALL(signal_strategy_, AddListener(NotNull())) .WillRepeatedly(AddListener(&signal_strategy_listeners_)); @@ -71,7 +70,7 @@ class RegisterSupportHostRequestTest : public testing::Test { MessageLoop message_loop_; MockSignalStrategy signal_strategy_; ObserverList<SignalStrategy::Listener, true> signal_strategy_listeners_; - scoped_refptr<InMemoryHostConfig> config_; + HostKeyPair key_pair_; MockCallback callback_; }; @@ -81,10 +80,9 @@ TEST_F(RegisterSupportHostRequestTest, Send) { int64 start_time = static_cast<int64>(base::Time::Now().ToDoubleT()); scoped_ptr<RegisterSupportHostRequest> request( - new RegisterSupportHostRequest()); - ASSERT_TRUE(request->Init( - &signal_strategy_, config_, base::Bind(&MockCallback::OnResponse, - base::Unretained(&callback_)))); + new RegisterSupportHostRequest(&signal_strategy_, &key_pair_, + base::Bind(&MockCallback::OnResponse, + base::Unretained(&callback_)))); XmlElement* sent_iq = NULL; EXPECT_CALL(signal_strategy_, GetNextId()) diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index d7d1fb8..21a4f40 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -5,8 +5,6 @@ // This file implements a standalone host process for Me2Me, which is currently // used for the Linux-only Virtual Me2Me build. -#include <stdlib.h> - #include <string> #include "base/at_exit.h" @@ -32,6 +30,7 @@ #include "remoting/host/json_host_config.h" #include "remoting/host/signaling_connector.h" #include "remoting/jingle_glue/xmpp_signal_strategy.h" +#include "remoting/protocol/v1_authenticator.h" #if defined(TOOLKIT_USES_GTK) #include "ui/gfx/gtk_util.h" @@ -100,13 +99,13 @@ class HostProcess { private: // Read Host config from disk, returning true if successful. bool LoadConfig(base::MessageLoopProxy* io_message_loop) { - host_config_ = + scoped_refptr<remoting::JsonHostConfig> host_config = new remoting::JsonHostConfig(host_config_path_, io_message_loop); scoped_refptr<remoting::JsonHostConfig> auth_config = new remoting::JsonHostConfig(auth_config_path_, io_message_loop); std::string failed_path; - if (!host_config_->Read()) { + if (!host_config->Read()) { failed_path = host_config_path_.value(); } else if (!auth_config->Read()) { failed_path = auth_config_path_.value(); @@ -116,6 +115,15 @@ class HostProcess { return false; } + if (!host_config->GetString(kHostIdConfigPath, &host_id_)) { + LOG(ERROR) << "host_id is not defined in the config."; + return false; + } + + if (!key_pair_.Load(host_config)) { + return false; + } + // Use an XMPP connection to the Talk network for session signalling. if (!auth_config->GetString(kXmppLoginConfigPath, &xmpp_login_) || !auth_config->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_)) { @@ -146,20 +154,21 @@ class HostProcess { desktop_environment_.reset(DesktopEnvironment::Create(&context_)); host_ = new ChromotingHost( - &context_, host_config_, signal_strategy_.get(), - desktop_environment_.get(), false); + &context_, signal_strategy_.get(), desktop_environment_.get(), false); - heartbeat_sender_.reset(new remoting::HeartbeatSender()); - if (!heartbeat_sender_->Init(signal_strategy_.get(), host_config_)) { - LOG(ERROR) << "Failed to initialize heartbeat sender"; - } + heartbeat_sender_.reset( + new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); host_->Start(); // Set an empty shared-secret for Me2Me. - // TODO(lambroslambrou): This is a temporary fix, pending a Me2Me-specific - // AuthenticatorFactory - crbug.com/105214. - host_->SetSharedSecret(""); + + // TODO(sergeyu): This is a temporary hack pending us adding a way + // to set a PIN. crbug.com/105214 . + scoped_ptr<protocol::AuthenticatorFactory> factory( + new protocol::V1HostAuthenticatorFactory( + key_pair_.GenerateCertificate(), key_pair_.private_key(), "")); + host_->SetAuthenticatorFactory(factory.Pass()); } MessageLoop message_loop_; @@ -170,8 +179,8 @@ class HostProcess { FilePath auth_config_path_; FilePath host_config_path_; - scoped_refptr<remoting::JsonHostConfig> host_config_; - + std::string host_id_; + HostKeyPair key_pair_; std::string xmpp_login_; std::string xmpp_auth_token_; std::string xmpp_auth_service_; diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc index 05b9389..f7fbbe0 100644 --- a/remoting/host/simple_host_process.cc +++ b/remoting/host/simple_host_process.cc @@ -37,6 +37,7 @@ #include "remoting/host/desktop_environment.h" #include "remoting/host/event_executor.h" #include "remoting/host/heartbeat_sender.h" +#include "remoting/host/host_key_pair.h" #include "remoting/host/host_secret.h" #include "remoting/host/it2me_host_user_interface.h" #include "remoting/host/json_host_config.h" @@ -45,6 +46,8 @@ #include "remoting/host/signaling_connector.h" #include "remoting/jingle_glue/xmpp_signal_strategy.h" #include "remoting/proto/video.pb.h" +#include "remoting/protocol/it2me_host_authenticator_factory.h" +#include "remoting/protocol/v1_authenticator.h" #if defined(TOOLKIT_USES_GTK) #include "ui/gfx/gtk_util.h" @@ -96,21 +99,30 @@ class SimpleHost { int Run() { FilePath config_path = GetConfigPath(); - config_ = new JsonHostConfig( + scoped_refptr<JsonHostConfig> config = new JsonHostConfig( config_path, file_io_thread_.message_loop_proxy()); - if (!config_->Read()) { + if (!config->Read()) { LOG(ERROR) << "Failed to read configuration file " << config_path.value(); return 1; } + if (!config->GetString(kHostIdConfigPath, &host_id_)) { + LOG(ERROR) << "host_id is not defined in the config."; + return 1; + } + + if (!key_pair_.Load(config)) { + return 1; + } + // Use an XMPP connection to the Talk network for session signalling. - if (!config_->GetString(kXmppLoginConfigPath, &xmpp_login_) || - !config_->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_)) { + if (!config->GetString(kXmppLoginConfigPath, &xmpp_login_) || + !config->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_)) { LOG(ERROR) << "XMPP credentials are not defined in the config."; return 1; } - if (!config_->GetString(kXmppAuthServiceConfigPath, &xmpp_auth_service_)) { + if (!config->GetString(kXmppAuthServiceConfigPath, &xmpp_auth_service_)) { // For the simple host, we assume we always use the ClientLogin token for // chromiumsync because we do not have an HTTP stack with which we can // easily request an OAuth2 access token even if we had a RefreshToken for @@ -137,6 +149,7 @@ class SimpleHost { private: static void SetIT2MeAccessCode(scoped_refptr<ChromotingHost> host, + HostKeyPair* key_pair, bool successful, const std::string& support_id, const base::TimeDelta& lifetime) { @@ -145,8 +158,11 @@ class SimpleHost { std::string access_code = support_id + host_secret; std::cout << "Support id: " << access_code << std::endl; - // Tell the ChromotingHost the access code, to use as shared-secret. - host->SetSharedSecret(access_code); + scoped_ptr<protocol::AuthenticatorFactory> factory( + new protocol::It2MeHostAuthenticatorFactory( + key_pair->GenerateCertificate(), key_pair->private_key(), + access_code)); + host->SetAuthenticatorFactory(factory.Pass()); } else { LOG(ERROR) << "If you haven't done so recently, try running" << " remoting/tools/register_host.py."; @@ -190,7 +206,7 @@ class SimpleHost { desktop_environment_.reset(DesktopEnvironment::Create(&context_)); } - host_ = new ChromotingHost(&context_, config_, signal_strategy_.get(), + host_ = new ChromotingHost(&context_, signal_strategy_.get(), desktop_environment_.get(), false); host_->set_it2me(is_it2me_); @@ -209,26 +225,25 @@ class SimpleHost { } if (is_it2me_) { - register_request_.reset(new RegisterSupportHostRequest()); - if (!register_request_->Init( - signal_strategy_.get(), config_, base::Bind( - &SimpleHost::SetIT2MeAccessCode, host_))) { - LOG(ERROR) << "Failed to initialize RegisterSupportHostRequest."; - } + register_request_.reset(new RegisterSupportHostRequest( + signal_strategy_.get(), &key_pair_, + base::Bind(&SimpleHost::SetIT2MeAccessCode, host_, &key_pair_))); } else { - // Initialize HeartbeatSender. - heartbeat_sender_.reset(new HeartbeatSender()); - if (!heartbeat_sender_->Init(signal_strategy_.get(), config_)) - LOG(ERROR) << "Failed to initialize HeartbeatSender."; + heartbeat_sender_.reset( + new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); } host_->Start(); // Set an empty shared-secret for Me2Me. - // TODO(lambroslambrou): This is a temporary fix, pending a Me2Me-specific - // AuthenticatorFactory - crbug.com/105214. - if (!is_it2me_) - host_->SetSharedSecret(""); + // TODO(sergeyu): This is a temporary hack pending us adding a way + // to set a PIN. crbug.com/105214 . + if (!is_it2me_) { + scoped_ptr<protocol::AuthenticatorFactory> factory( + new protocol::V1HostAuthenticatorFactory( + key_pair_.GenerateCertificate(), key_pair_.private_key(), "")); + host_->SetAuthenticatorFactory(factory.Pass()); + } } MessageLoop message_loop_; @@ -241,11 +256,12 @@ class SimpleHost { bool is_it2me_; scoped_ptr<CandidateSessionConfig> protocol_config_; + std::string host_id_; + HostKeyPair key_pair_; std::string xmpp_login_; std::string xmpp_auth_token_; std::string xmpp_auth_service_; - scoped_refptr<JsonHostConfig> config_; scoped_ptr<SignalStrategy> signal_strategy_; scoped_ptr<SignalingConnector> signaling_connector_; scoped_ptr<DesktopEnvironment> desktop_environment_; diff --git a/remoting/protocol/jingle_session_manager.cc b/remoting/protocol/jingle_session_manager.cc index c1705c0..a40c397 100644 --- a/remoting/protocol/jingle_session_manager.cc +++ b/remoting/protocol/jingle_session_manager.cc @@ -112,9 +112,11 @@ void JingleSessionManager::Close() { } void JingleSessionManager::set_authenticator_factory( - AuthenticatorFactory* authenticator_factory) { + scoped_ptr<AuthenticatorFactory> authenticator_factory) { DCHECK(CalledOnValidThread()); - authenticator_factory_.reset(authenticator_factory); + DCHECK(authenticator_factory.get()); + DCHECK(!authenticator_factory_.get()); + authenticator_factory_ = authenticator_factory.Pass(); } Session* JingleSessionManager::Connect( diff --git a/remoting/protocol/jingle_session_manager.h b/remoting/protocol/jingle_session_manager.h index 5424bf9..79b8e31 100644 --- a/remoting/protocol/jingle_session_manager.h +++ b/remoting/protocol/jingle_session_manager.h @@ -51,7 +51,7 @@ class JingleSessionManager : public SessionManager, const Session::StateChangeCallback& state_change_callback) OVERRIDE; virtual void Close() OVERRIDE; virtual void set_authenticator_factory( - AuthenticatorFactory* authenticator_factory) OVERRIDE; + scoped_ptr<AuthenticatorFactory> authenticator_factory) OVERRIDE; // cricket::SessionClient interface. virtual void OnSessionCreate(cricket::Session* cricket_session, diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc index ca78e9a..4a087d0 100644 --- a/remoting/protocol/jingle_session_unittest.cc +++ b/remoting/protocol/jingle_session_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -135,8 +135,9 @@ class JingleSessionTest : public testing::Test { host_server_->Init( host_signal_strategy_.get(), &host_server_listener_, false); - host_server_->set_authenticator_factory( + scoped_ptr<AuthenticatorFactory> factory( new FakeHostAuthenticatorFactory(auth_round_trips, auth_action, true)); + host_server_->set_authenticator_factory(factory.Pass()); EXPECT_CALL(client_server_listener_, OnSessionManagerReady()) .Times(1); diff --git a/remoting/protocol/pepper_session_manager.cc b/remoting/protocol/pepper_session_manager.cc index 3492cd3..a9e7471 100644 --- a/remoting/protocol/pepper_session_manager.cc +++ b/remoting/protocol/pepper_session_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -94,9 +94,9 @@ void PepperSessionManager::Close() { } void PepperSessionManager::set_authenticator_factory( - AuthenticatorFactory* authenticator_factory) { + scoped_ptr<AuthenticatorFactory> authenticator_factory) { DCHECK(CalledOnValidThread()); - authenticator_factory_.reset(authenticator_factory); + authenticator_factory_ = authenticator_factory.Pass(); } void PepperSessionManager::OnSignalStrategyStateChange( diff --git a/remoting/protocol/pepper_session_manager.h b/remoting/protocol/pepper_session_manager.h index 54369bd..784b297 100644 --- a/remoting/protocol/pepper_session_manager.h +++ b/remoting/protocol/pepper_session_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -58,7 +58,7 @@ class PepperSessionManager : public SessionManager, const Session::StateChangeCallback& state_change_callback) OVERRIDE; virtual void Close() OVERRIDE; virtual void set_authenticator_factory( - AuthenticatorFactory* authenticator_factory) OVERRIDE; + scoped_ptr<AuthenticatorFactory> authenticator_factory) OVERRIDE; // SignalStrategy::Listener interface. virtual void OnSignalStrategyStateChange( diff --git a/remoting/protocol/pepper_session_unittest.cc b/remoting/protocol/pepper_session_unittest.cc index b7c9b2b..39d9b34 100644 --- a/remoting/protocol/pepper_session_unittest.cc +++ b/remoting/protocol/pepper_session_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -101,8 +101,9 @@ class PepperSessionTest : public testing::Test { host_server_->Init( host_signal_strategy_.get(), &host_server_listener_, false); - host_server_->set_authenticator_factory( + scoped_ptr<AuthenticatorFactory> factory( new FakeHostAuthenticatorFactory(auth_round_trips, auth_action, true)); + host_server_->set_authenticator_factory(factory.Pass()); EXPECT_CALL(client_server_listener_, OnSessionManagerReady()) .Times(1); diff --git a/remoting/protocol/session_manager.h b/remoting/protocol/session_manager.h index bee08cc..879dc70 100644 --- a/remoting/protocol/session_manager.h +++ b/remoting/protocol/session_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -144,9 +144,11 @@ class SessionManager : public base::NonThreadSafe { // Set authenticator factory that should be used to authenticate // incoming connection. No connections will be accepted if - // authenticator factory isn't set. + // authenticator factory isn't set. Must not be called more than + // once per SessionManager because it may not be safe to delete + // factory before all authenticators it created are deleted. virtual void set_authenticator_factory( - AuthenticatorFactory* authenticator_factory) = 0; + scoped_ptr<AuthenticatorFactory> authenticator_factory) = 0; private: DISALLOW_COPY_AND_ASSIGN(SessionManager); |