From a5f10b8554ddd8c1e2b5eec7410d59a1c89fc6a4 Mon Sep 17 00:00:00 2001 From: "hclam@chromium.org" Date: Fri, 4 Feb 2011 07:59:18 +0000 Subject: Remove auto generation of certificate when chromoting client connects Generate certificate once and reuse it in all chromoting session. BUG=None TEST=None Review URL: http://codereview.chromium.org/6246077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73781 0039d316-1c4b-4281-b951-d872f2087c98 --- remoting/protocol/jingle_connection_to_host.cc | 5 +-- remoting/protocol/jingle_session_manager.cc | 32 ++++++------------- remoting/protocol/jingle_session_manager.h | 16 +++++----- remoting/protocol/jingle_session_unittest.cc | 43 +++++++++++++------------- remoting/protocol/protocol_test_client.cc | 2 +- 5 files changed, 45 insertions(+), 53 deletions(-) (limited to 'remoting/protocol') diff --git a/remoting/protocol/jingle_connection_to_host.cc b/remoting/protocol/jingle_connection_to_host.cc index 6d4b256..2191a19 100644 --- a/remoting/protocol/jingle_connection_to_host.cc +++ b/remoting/protocol/jingle_connection_to_host.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -77,7 +77,8 @@ void JingleConnectionToHost::InitSession() { session_manager->Init( jingle_client_->GetFullJid(), jingle_client_->session_manager(), - NewCallback(this, &JingleConnectionToHost::OnNewSession)); + NewCallback(this, &JingleConnectionToHost::OnNewSession), + NULL, NULL); session_manager_ = session_manager; CandidateSessionConfig* candidate_config = diff --git a/remoting/protocol/jingle_session_manager.cc b/remoting/protocol/jingle_session_manager.cc index 6bb710f..88c1969 100644 --- a/remoting/protocol/jingle_session_manager.cc +++ b/remoting/protocol/jingle_session_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -177,12 +177,15 @@ JingleSessionManager::JingleSessionManager( void JingleSessionManager::Init( const std::string& local_jid, cricket::SessionManager* cricket_session_manager, - IncomingSessionCallback* incoming_session_callback) { + IncomingSessionCallback* incoming_session_callback, + base::RSAPrivateKey* private_key, + scoped_refptr certificate) { if (MessageLoop::current() != message_loop()) { message_loop()->PostTask( FROM_HERE, NewRunnableMethod( this, &JingleSessionManager::Init, - local_jid, cricket_session_manager, incoming_session_callback)); + local_jid, cricket_session_manager, incoming_session_callback, + private_key, certificate)); return; } @@ -190,6 +193,8 @@ void JingleSessionManager::Init( DCHECK(incoming_session_callback); local_jid_ = local_jid; + certificate_ = certificate; + private_key_.reset(private_key); incoming_session_callback_.reset(incoming_session_callback); cricket_session_manager_ = cricket_session_manager; cricket_session_manager_->AddClient(kChromotingXmlNamespace, this); @@ -280,20 +285,11 @@ void JingleSessionManager::OnSessionCreate( // If this is an outcoming session the session object is already created. if (incoming) { - // Generate private key and certificate. - // TODO(hclam): Instead of generating we should restore them from the disk. - if (!certificate_) { - private_key_.reset(base::RSAPrivateKey::Create(1024)); - certificate_ = net::X509Certificate::CreateSelfSigned( - private_key_.get(), "CN=chromoting", - base::RandInt(1, std::numeric_limits::max()), - base::TimeDelta::FromDays(1)); - CHECK(certificate_); - } + DCHECK(certificate_); + DCHECK(private_key_.get()); JingleSession* jingle_session = JingleSession::CreateServerSession(this, certificate_, private_key_.get()); - certificate_ = NULL; sessions_.push_back(make_scoped_refptr(jingle_session)); jingle_session->Init(cricket_session); } @@ -535,14 +531,6 @@ bool JingleSessionManager::WriteContent( return true; } -void JingleSessionManager::SetCertificate(net::X509Certificate* certificate) { - certificate_ = certificate; -} - -void JingleSessionManager::SetPrivateKey(base::RSAPrivateKey* private_key) { - private_key_.reset(private_key); -} - cricket::SessionDescription* JingleSessionManager::CreateSessionDescription( const CandidateSessionConfig* config, const std::string& auth_token, diff --git a/remoting/protocol/jingle_session_manager.h b/remoting/protocol/jingle_session_manager.h index 344095b..5cb0857 100644 --- a/remoting/protocol/jingle_session_manager.h +++ b/remoting/protocol/jingle_session_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -76,9 +76,16 @@ class JingleSessionManager // Initializes the session client. Doesn't accept ownership of the // |session_manager|. Close() must be called _before_ the |session_manager| // is destroyed. + // If this object is used in server mode, then |private_key| and + // |certificate| are used to establish a secured communication with the + // client. It will also take ownership of these objects. + // In case this is used in client mode, pass in NULL for both private key and + // certificate. virtual void Init(const std::string& local_jid, cricket::SessionManager* cricket_session_manager, - IncomingSessionCallback* incoming_session_callback); + IncomingSessionCallback* incoming_session_callback, + base::RSAPrivateKey* private_key, + scoped_refptr certificate); // SessionManager interface. virtual scoped_refptr Connect( @@ -104,11 +111,6 @@ class JingleSessionManager buzz::XmlElement** elem, cricket::WriteError* error); - // Set the certificate and private key if they are provided externally. - // TODO(hclam): Combine these two methods. - virtual void SetCertificate(net::X509Certificate* certificate); - virtual void SetPrivateKey(base::RSAPrivateKey* private_key); - protected: virtual ~JingleSessionManager(); diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc index 99e500f..1f0ca4a 100644 --- a/remoting/protocol/jingle_session_unittest.cc +++ b/remoting/protocol/jingle_session_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -116,23 +116,6 @@ class JingleSessionTest : public testing::Test { } void DoCreateServerPair() { - session_manager_pair_ = new SessionManagerPair(&thread_); - session_manager_pair_->Init(); - host_server_ = new JingleSessionManager(&thread_); - host_server_->set_allow_local_ips(true); - host_server_->Init(SessionManagerPair::kHostJid, - session_manager_pair_->host_session_manager(), - NewCallback(&host_server_callback_, - &MockSessionManagerCallback::OnIncomingSession)); - - client_server_ = new JingleSessionManager(&thread_); - client_server_->set_allow_local_ips(true); - client_server_->Init( - SessionManagerPair::kClientJid, - session_manager_pair_->client_session_manager(), - NewCallback(&client_server_callback_, - &MockSessionManagerCallback::OnIncomingSession)); - FilePath certs_dir; PathService::Get(base::DIR_SOURCE_ROOT, &certs_dir); certs_dir = certs_dir.AppendASCII("net"); @@ -155,11 +138,29 @@ class JingleSessionTest : public testing::Test { reinterpret_cast(key_string.data()), reinterpret_cast(key_string.data() + key_string.length())); - scoped_ptr private_key( base::RSAPrivateKey::CreateFromPrivateKeyInfo(key_vector)); - host_server_->SetCertificate(cert); - host_server_->SetPrivateKey(private_key.release()); + + session_manager_pair_ = new SessionManagerPair(&thread_); + session_manager_pair_->Init(); + host_server_ = new JingleSessionManager(&thread_); + host_server_->set_allow_local_ips(true); + host_server_->Init( + SessionManagerPair::kHostJid, + session_manager_pair_->host_session_manager(), + NewCallback(&host_server_callback_, + &MockSessionManagerCallback::OnIncomingSession), + private_key.release(), + cert); + + client_server_ = new JingleSessionManager(&thread_); + client_server_->set_allow_local_ips(true); + client_server_->Init( + SessionManagerPair::kClientJid, + session_manager_pair_->client_session_manager(), + NewCallback(&client_server_callback_, + &MockSessionManagerCallback::OnIncomingSession), + NULL, NULL); } bool InitiateConnection() { diff --git a/remoting/protocol/protocol_test_client.cc b/remoting/protocol/protocol_test_client.cc index 5f64aa4..cf8d486 100644 --- a/remoting/protocol/protocol_test_client.cc +++ b/remoting/protocol/protocol_test_client.cc @@ -279,7 +279,7 @@ void ProtocolTestClient::OnStateChange( session_manager_->Init( client_->GetFullJid(), client_->session_manager(), - NewCallback(this, &ProtocolTestClient::OnNewSession)); + NewCallback(this, &ProtocolTestClient::OnNewSession), NULL, NULL); session_manager_->set_allow_local_ips(true); if (host_jid_ != "") { -- cgit v1.1