diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-04 02:16:49 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-04 02:16:49 +0000 |
commit | 095079273cfaea72f9d5d78218fd9a2a62d78ca3 (patch) | |
tree | 43ea47d34aeeaf81511b13f96f4d675d05b3b230 /remoting | |
parent | bd81e4aab8a4d2fedb5f3997babd246a3a880772 (diff) | |
download | chromium_src-095079273cfaea72f9d5d78218fd9a2a62d78ca3.zip chromium_src-095079273cfaea72f9d5d78218fd9a2a62d78ca3.tar.gz chromium_src-095079273cfaea72f9d5d78218fd9a2a62d78ca3.tar.bz2 |
Faster connection establishment for chromoting
Chromoting used to generate a new key and certificate everytime we connect. This
patch reuse the private key in host config and generate a certificate from it.
This is still not optimal but much faster than before.
BUG=71253
TEST=none
Review URL: http://codereview.chromium.org/6312114
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73740 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/DEPS | 2 | ||||
-rw-r--r-- | remoting/host/chromoting_host.cc | 12 | ||||
-rw-r--r-- | remoting/host/host_key_pair.cc | 19 | ||||
-rw-r--r-- | remoting/host/host_key_pair.h | 10 |
4 files changed, 39 insertions, 4 deletions
diff --git a/remoting/host/DEPS b/remoting/host/DEPS index c94d231..bf2b75f 100644 --- a/remoting/host/DEPS +++ b/remoting/host/DEPS @@ -1,6 +1,8 @@ include_rules = [ "+gfx", "+ui", + "+base/crypto", + "+net/base", "+remoting/protocol", "+remoting/jingle_glue", diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index 942a1c0..29277d6 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_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. @@ -15,6 +15,7 @@ #include "remoting/host/chromoting_host_context.h" #include "remoting/host/event_executor.h" #include "remoting/host/host_config.h" +#include "remoting/host/host_key_pair.h" #include "remoting/host/host_stub_fake.h" #include "remoting/host/screen_recorder.h" #include "remoting/proto/auth.pb.h" @@ -249,8 +250,15 @@ void ChromotingHost::OnStateChange(JingleClient* jingle_client, server->Init(jingle_client->GetFullJid(), jingle_client->session_manager(), NewCallback(this, &ChromotingHost::OnNewClientSession)); - session_manager_ = server; + // Assign key and certificate to server. + HostKeyPair key_pair; + CHECK(key_pair.Load(config_)) + << "Failed to load server authentication data"; + server->SetCertificate(key_pair.GenerateCertificate()); + server->SetPrivateKey(key_pair.CopyPrivateKey()); + + session_manager_ = server; // Start heartbeating. heartbeat_sender_->Start(); } else if (state == JingleClient::CLOSED) { diff --git a/remoting/host/host_key_pair.cc b/remoting/host/host_key_pair.cc index 1255892..ad3d59b 100644 --- a/remoting/host/host_key_pair.cc +++ b/remoting/host/host_key_pair.cc @@ -1,9 +1,10 @@ -// 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. #include "remoting/host/host_key_pair.h" +#include <limits> #include <string> #include <vector> @@ -11,7 +12,10 @@ #include "base/crypto/rsa_private_key.h" #include "base/crypto/signature_creator.h" #include "base/logging.h" +#include "base/rand_util.h" #include "base/task.h" +#include "base/time.h" +#include "net/base/x509_certificate.h" #include "remoting/host/host_config.h" namespace remoting { @@ -84,4 +88,17 @@ std::string HostKeyPair::GetSignature(const std::string& message) const { return signature_base64; } +base::RSAPrivateKey* HostKeyPair::CopyPrivateKey() const { + std::vector<uint8> key_bytes; + CHECK(key_->ExportPrivateKey(&key_bytes)); + return base::RSAPrivateKey::CreateFromPrivateKeyInfo(key_bytes); +} + +net::X509Certificate* HostKeyPair::GenerateCertificate() const { + return net::X509Certificate::CreateSelfSigned( + key_.get(), "CN=chromoting", + base::RandInt(1, std::numeric_limits<int>::max()), + base::TimeDelta::FromDays(1)); +} + } // namespace remoting diff --git a/remoting/host/host_key_pair.h b/remoting/host/host_key_pair.h index 4ae3fde..2148739 100644 --- a/remoting/host/host_key_pair.h +++ b/remoting/host/host_key_pair.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. @@ -15,6 +15,10 @@ namespace base { class RSAPrivateKey; } // namespace base +namespace net { +class X509Certificate; +} // namespace net + namespace remoting { class HostConfig; @@ -33,6 +37,10 @@ class HostKeyPair { std::string GetPublicKey() const; std::string GetSignature(const std::string& message) const; + // Make a new copy of private key. Caller will own the generated private key. + base::RSAPrivateKey* CopyPrivateKey() const; + net::X509Certificate* GenerateCertificate() const; + private: scoped_ptr<base::RSAPrivateKey> key_; }; |