Commit 8f1504bf authored by rmsousa@chromium.org's avatar rmsousa@chromium.org

Move HostKeyPair into protocol::KeyPair.

This makes the RSAPrivateKey dependency encapsulated inside KeyPair, and makes it a refcounted object, rather than copying the private key on every authenticator constructor. It also allows authenticators to use the KeyPair methods (such as GetSignature() or GetPublicKey()).

BUG=115899

Review URL: https://chromiumcodereview.appspot.com/12316083

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186709 0039d316-1c4b-4281-b951-d872f2087c98
parent 558b2e4b
......@@ -2,7 +2,7 @@
// 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 "remoting/base/rsa_key_pair.h"
#include <limits>
#include <string>
......@@ -15,54 +15,52 @@
#include "crypto/rsa_private_key.h"
#include "crypto/signature_creator.h"
#include "net/base/x509_certificate.h"
#include "remoting/host/host_config.h"
namespace remoting {
HostKeyPair::HostKeyPair() { }
RsaKeyPair::RsaKeyPair(scoped_ptr<crypto::RSAPrivateKey> key)
: key_(key.Pass()){
DCHECK(key_);
}
HostKeyPair::~HostKeyPair() { }
RsaKeyPair::~RsaKeyPair() {}
void HostKeyPair::Generate() {
key_.reset(crypto::RSAPrivateKey::Create(2048));
//static
scoped_refptr<RsaKeyPair> RsaKeyPair::Generate() {
scoped_ptr<crypto::RSAPrivateKey> key(crypto::RSAPrivateKey::Create(2048));
if (!key) {
LOG(ERROR) << "Cannot generate private key.";
return NULL;
}
return new RsaKeyPair(key.Pass());
}
bool HostKeyPair::LoadFromString(const std::string& key_base64) {
//static
scoped_refptr<RsaKeyPair> RsaKeyPair::FromString(
const std::string& key_base64) {
std::string key_str;
if (!base::Base64Decode(key_base64, &key_str)) {
LOG(ERROR) << "Failed to decode private key.";
return false;
return NULL;
}
std::vector<uint8> key_buf(key_str.begin(), key_str.end());
key_.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_buf));
if (key_.get() == NULL) {
scoped_ptr<crypto::RSAPrivateKey> key(
crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_buf));
if (!key) {
LOG(ERROR) << "Invalid private key.";
return false;
}
return true;
}
bool HostKeyPair::Load(const HostConfig& host_config) {
std::string key_base64;
if (!host_config.GetString(kPrivateKeyConfigPath, &key_base64)) {
LOG(ERROR) << "Private key wasn't found in the config file.";
return false;
return NULL;
}
return LoadFromString(key_base64);
}
void HostKeyPair::Save(MutableHostConfig* host_config) {
host_config->SetString(kPrivateKeyConfigPath, GetAsString());
return new RsaKeyPair(key.Pass());
}
std::string HostKeyPair::GetAsString() const {
std::string RsaKeyPair::ToString() const {
// Check that the key initialized.
DCHECK(key_.get() != NULL);
std::vector<uint8> key_buf;
key_->ExportPrivateKey(&key_buf);
CHECK(key_->ExportPrivateKey(&key_buf));
std::string key_str(key_buf.begin(), key_buf.end());
std::string key_base64;
if (!base::Base64Encode(key_str, &key_base64)) {
......@@ -71,16 +69,16 @@ std::string HostKeyPair::GetAsString() const {
return key_base64;
}
std::string HostKeyPair::GetPublicKey() const {
std::string RsaKeyPair::GetPublicKey() const {
std::vector<uint8> public_key;
key_->ExportPublicKey(&public_key);
CHECK(key_->ExportPublicKey(&public_key));
std::string public_key_str(public_key.begin(), public_key.end());
std::string public_key_base64;
base::Base64Encode(public_key_str, &public_key_base64);
return public_key_base64;
}
std::string HostKeyPair::GetSignature(const std::string& message) const {
std::string RsaKeyPair::SignMessage(const std::string& message) const {
scoped_ptr<crypto::SignatureCreator> signature_creator(
crypto::SignatureCreator::Create(key_.get()));
signature_creator->Update(reinterpret_cast<const uint8*>(message.c_str()),
......@@ -93,13 +91,7 @@ std::string HostKeyPair::GetSignature(const std::string& message) const {
return signature_base64;
}
crypto::RSAPrivateKey* HostKeyPair::CopyPrivateKey() const {
std::vector<uint8> key_bytes;
CHECK(key_->ExportPrivateKey(&key_bytes));
return crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_bytes);
}
std::string HostKeyPair::GenerateCertificate() const {
std::string RsaKeyPair::GenerateCertificate() const {
scoped_refptr<net::X509Certificate> cert =
net::X509Certificate::CreateSelfSigned(
key_.get(), "CN=chromoting",
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_HOST_HOST_KEY_PAIR_H_
#define REMOTING_HOST_HOST_KEY_PAIR_H_
#ifndef REMOTING_BASE_RSA_KEY_PAIR_H_
#define REMOTING_BASE_RSA_KEY_PAIR_H_
#include <string>
......@@ -12,40 +12,44 @@
namespace crypto {
class RSAPrivateKey;
} // namespace base
} // namespace crypto
namespace remoting {
class HostConfig;
class MutableHostConfig;
class HostKeyPair {
class RsaKeyPair : public base::RefCountedThreadSafe<RsaKeyPair> {
public:
HostKeyPair();
~HostKeyPair();
// Generates a new (random) private key.
static scoped_refptr<RsaKeyPair> Generate();
void Generate();
bool LoadFromString(const std::string& key_base64);
bool Load(const HostConfig& host_config);
void Save(MutableHostConfig* host_config);
// Loads a private key from a base64-encoded string. Returns true on success.
static scoped_refptr<RsaKeyPair> FromString(const std::string& key_base64);
crypto::RSAPrivateKey* private_key() { return key_.get(); }
// Returns a base64 encoded string representing the private key.
std::string ToString() const;
// Generates a DER-encoded self-signed certificate using the key pair. Returns
// empty string if cert generation fails (e.g. it may happen when the system
// clock is off).
std::string GenerateCertificate() const;
std::string GetAsString() const;
// Returns a base64-encoded string representing the public key.
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.
crypto::RSAPrivateKey* CopyPrivateKey() const;
// Returns a base64-encoded signature for the message.
std::string SignMessage(const std::string& message) const;
// Generates self-signed certificate using the key pair. Returns empty string
// if cert generation fails (e.g. it may happen when the system clock is off).
std::string GenerateCertificate() const;
crypto::RSAPrivateKey* private_key() { return key_.get(); }
private:
friend class base::RefCountedThreadSafe<RsaKeyPair>;
RsaKeyPair(scoped_ptr<crypto::RSAPrivateKey> key);
virtual ~RsaKeyPair();
scoped_ptr<crypto::RSAPrivateKey> key_;
DISALLOW_COPY_AND_ASSIGN(RsaKeyPair);
};
} // namespace remoting
#endif // REMOTING_HOST_HOST_KEY_PAIR_H_
#endif // REMOTING_BASE_RSA_KEY_PAIR_H_
// 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.
#include <string>
#include "remoting/base/rsa_key_pair.h"
#include "remoting/base/test_rsa_key_pair.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace remoting {
namespace {
const char kTestMessage[] = "Test Message";
// |kTestMessage| signed with the key from |kTestRsaKeyPair|.
const char kExpectedSignature[] =
"LfUyXU2AiKM4rpWivUR3bLiQiRt1W3iIenNfJEB8RWyoEfnvSBoD52x8q9yFvtLFDEMPWyIrwM+N2"
"LuaWBKG1c0R7h+twBgvpExzZneJl+lbGMRx9ba8m/KAFrUWA/NRzOen2NHCuPybOEasgrPgGWBrmf"
"gDcvyW8QiGuKLopGj/4c5CQT4yE8JjsyU3Qqo2ZPK4neJYQhOmAlg+Q5dAPLpzWMj5HQyOVHJaSXZ"
"Y8vl/LiKvbdofYLeYNVKAE4q5mfpQMrsysPYpbxBV60AhFyrvtC040MFGcflKQRZNiZwMXVb7DclC"
"BPgvK7rI5Y0ERtVm+yNmH7vCivfyAnDUYA==";
// Another RSA key pair, different from |kTestRsaKeyPair|
const char kTestRsaKeyPair2[] =
"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDLNd9bNNBFxXSasqWHv8ydItmoi"
"NhiWV/1Z6JI6TpKTnTm9yQSxIoCLHT8fB8QA0wzzgYEuZpDHIZDv1WxSdC3kgx84JrWe43+SPDZ2b"
"7ekuhXinPK+f3Nw5GjGaAUevyeWNoDD3GFka5q4zw8W1OE8E/z50FfPqOUejg+qyrgovEWQIZWvI0"
"CHdy8HTtxT7G0YbPJYZ8ycRkUrsXtY2RQX4IaCMEcdAmCm2Q2hYldulbZX6Bvv5GX8FOWYOerbYVK"
"ZsmH5II+KEP4We75ONVR2jdCCJ5L3YMXtbYtZZy1yZXcOf2fpBo6+p81M7rG9com/C75QoMVMVJJC"
"ahCli7/AgMBAAECggEAZNzThUC8k7UDQHmlgbCojeIraOSrin1UDMmomknxHcq9aZqHtC0LVzLbyi"
"qNfHQ2kYwUHqpFMERrPBsvHHVH/KWoPx94mzbubqWjrm3OuEjwu+rDuJ7G5CfLFMp2U1QMKUhuxZA"
"Xx7Vcfj9VuZuW4+gntyc0omLD7MGRQ0HQYXh7ZDGWrMPEs6Cjzcx9/G9AD7ysWIqk14iwJqKhztiD"
"NirMr64eDZFzzDvXTl3j5l+yiAHiV5LPUUKyCe+jEdZMceSKy5wSZXSkiW4zhgEzwdMN2zmxlcC59"
"17dw2c6xD+tKxTMwzx77sauBFNzebNU1m5hIKH+jCPiA8aQv3/l8QKBgQD8J4ilT/CV6hhw0/q99e"
"+54s+SIz8nYo8fvyeEBCiA4lf/OZuxl/sYWK+PthP+xzsjKTq7yoFkliXrtOioW34E0WdLv+6jEXQ"
"hxaXZyk0TMwxm228xMG66evXDJ8OGWCi6uiAnVWNUu6VXacQwKHf9hv6DNRNcmkQGojfcx3ZNZwKB"
"gQDOT0ApweRr0zA28l8C6qtNfY/NIeWTWPDTspt8zDoX1ILXc2HZHYW0QtUQ6tXNQnUW/ymavla7E"
"upa8AoZoqMvaUIg1BjMYIzc4yQMVf1BRCfvT8GsoymX+8Gt/DB34L7KMPOhQysMmZMNjKtozQsbZY"
"wcnN19pWnDv78trFZ6qQKBgHy1nMqN7+JlRjM/VCrxYOAhwiF31ztGbpz38LZFTDb6OyVau5spHKH"
"c8u9z0Q3YQXJRaOAJ9tblv9mEvvDNV1VQr/Lx+TejYTl2xGEjwdz2CXMxohvE5W7Lc5NSrkxae8Jm"
"XZK2k4sLx2mlQMfErBuy0VvZOzs4fN5/CnviFquPAoGBAI8NAI5ztPDW1L2kvSCGmxT2FTnFYSwUJ"
"ZiEZa/Y5AcWAUtm49fp0oW1OYuraWgTxqCVeMGlbPn2Ga3IdxhjXwdG0uV0a2V7JPEcRiiPjzUsDw"
"yunroXwIVzuU3saacVnPURkDynGDh6XC6u9UOLuUHb3ZURZ7rxcS6by/HdZ3FRAoGBAOhjtjyfFEn"
"bZtjcQd+bNtoTPV/L71+K8AYPwV0td5Qy5VbBrTIlv7pNFxE4bYNuEe6cI2cxTua4i5IoKYXyUm5u"
"SvUVkkz7CpoiFwMnnLsNrZmazVS2zq0Y2a2ai8C3mPgLOdroS2fBBAcuFApeq1PvISmT6ZnJJ8Yah"
"HQCfClh";
} // namespace
class RsaKeyPairTest : public testing::Test {
};
TEST_F(RsaKeyPairTest, ImportExportImport) {
// Load a key from a string, export to a string, load again, and verify that
// we generate the same signature with both keys.
scoped_refptr<RsaKeyPair> exported_key = RsaKeyPair::FromString(
kTestRsaKeyPair);
scoped_refptr<RsaKeyPair> imported_key = RsaKeyPair::FromString(
exported_key->ToString());
ASSERT_EQ(exported_key->SignMessage(kTestMessage),
imported_key->SignMessage(kTestMessage));
}
TEST_F(RsaKeyPairTest, Signatures) {
// Sign a message and check that we get the expected signature.
scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(kTestRsaKeyPair);
std::string signature_base64 = key_pair->SignMessage(kTestMessage);
ASSERT_EQ(signature_base64, std::string(kExpectedSignature));
}
TEST_F(RsaKeyPairTest, GenerateKey) {
// Test that we can generate a valid key.
scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate();
ASSERT_TRUE(key_pair);
ASSERT_NE(key_pair->ToString(), "");
ASSERT_NE(key_pair->GetPublicKey(), "");
ASSERT_NE(key_pair->SignMessage(kTestMessage), "");
}
TEST_F(RsaKeyPairTest, SignaturesDiffer) {
// Sign using different keys/messages and check that signatures are different.
scoped_refptr<RsaKeyPair> key_pair1 = RsaKeyPair::FromString(kTestRsaKeyPair);
scoped_refptr<RsaKeyPair> key_pair2 = RsaKeyPair::FromString(
kTestRsaKeyPair2);
std::string signature_kp1_msg1_base64 = key_pair1->SignMessage(kTestMessage);
std::string signature_kp2_msg1_base64 = key_pair2->SignMessage(kTestMessage);
std::string signature_kp1_msg2_base64 = key_pair1->SignMessage("Different");
ASSERT_NE(signature_kp1_msg1_base64, signature_kp2_msg1_base64);
ASSERT_NE(signature_kp1_msg1_base64, signature_kp1_msg2_base64);
ASSERT_NE(key_pair1->GetPublicKey(), key_pair2->GetPublicKey());
}
} // namespace remoting
......@@ -3,8 +3,9 @@
// found in the LICENSE file.
namespace remoting {
// An RSA keypair used in unittests.
const char kTestHostKeyPair[] =
const char kTestRsaKeyPair[] =
"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDeeT/wgtzQkGoeA5LRQI4iXibQZ"
"R3YUiJn/oVz0P+KLJSCWL4Uhjl3CytKg0nzuxgaJ9UOHxrl91k1XnLnwJytqkjl8kgWle+JJbiDx3"
"+3WBxmSjPWmmaPNuBebpyTD1N3TJEPRwe7vfYiOz56jzBPSm3gqIeRvJGIC+Ou+Q0OV+ISTu2Jjtj"
......@@ -27,4 +28,5 @@ const char kTestHostKeyPair[] =
"Et5ho7YqrrBWTwnvMLw4G7qftiMco15JcMAXhfGhmlDI8OUq7MlXVCUWwdZtRYcAyWJcqhWQ3yrXv"
"8cWi9hxwNGPuof5PchDDuR+cwe8gZvpzwfFDFTgJHIBe64CkFd9Oeb5CvEffbrP04mpWvjVeMcjjz"
"ZA6a+IB";
} // namespace remoting
......@@ -15,7 +15,6 @@
#include "base/threading/thread.h"
#include "net/base/backoff_entry.h"
#include "remoting/host/client_session.h"
#include "remoting/host/host_key_pair.h"
#include "remoting/host/host_status_monitor.h"
#include "remoting/host/host_status_observer.h"
#include "remoting/host/mouse_move_observer.h"
......
......@@ -51,7 +51,7 @@ HeartbeatSender::HeartbeatSender(
Listener* listener,
const std::string& host_id,
SignalStrategy* signal_strategy,
HostKeyPair* key_pair,
scoped_refptr<RsaKeyPair> key_pair,
const std::string& directory_bot_jid)
: listener_(listener),
host_id_(host_id),
......@@ -264,7 +264,7 @@ scoped_ptr<XmlElement> HeartbeatSender::CreateSignature() {
std::string message = signal_strategy_->GetLocalJid() + ' ' +
base::IntToString(sequence_id_);
std::string signature(key_pair_->GetSignature(message));
std::string signature(key_pair_->SignMessage(message));
signature_tag->AddText(signature);
return signature_tag.Pass();
......
......@@ -12,7 +12,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/timer.h"
#include "remoting/host/host_key_pair.h"
#include "remoting/base/rsa_key_pair.h"
#include "remoting/jingle_glue/signal_strategy.h"
namespace base {
......@@ -25,7 +25,7 @@ class XmlElement;
namespace remoting {
class HostKeyPair;
class RsaKeyPair;
class IqRequest;
class IqSender;
......@@ -86,13 +86,13 @@ class HeartbeatSender : public SignalStrategy::Listener {
virtual void OnUnknownHostIdError() = 0;
};
// |signal_strategy|, |key_pair| and |delegate| must outlive this
// |signal_strategy| and |delegate| must outlive this
// object. Heartbeats will start when the supplied SignalStrategy
// enters the CONNECTED state.
HeartbeatSender(Listener* listener,
const std::string& host_id,
SignalStrategy* signal_strategy,
HostKeyPair* key_pair,
scoped_refptr<RsaKeyPair> key_pair,
const std::string& directory_bot_jid);
virtual ~HeartbeatSender();
......@@ -125,7 +125,7 @@ class HeartbeatSender : public SignalStrategy::Listener {
Listener* listener_;
std::string host_id_;
SignalStrategy* signal_strategy_;
HostKeyPair* key_pair_;
scoped_refptr<RsaKeyPair> key_pair_;
std::string directory_bot_jid_;
scoped_ptr<IqSender> iq_sender_;
scoped_ptr<IqRequest> request_;
......
......@@ -11,8 +11,8 @@
#include "base/message_loop_proxy.h"
#include "base/string_number_conversions.h"
#include "remoting/base/constants.h"
#include "remoting/host/host_key_pair.h"
#include "remoting/host/test_key_pair.h"
#include "remoting/base/rsa_key_pair.h"
#include "remoting/base/test_rsa_key_pair.h"
#include "remoting/jingle_glue/iq_sender.h"
#include "remoting/jingle_glue/mock_objects.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -58,7 +58,8 @@ class HeartbeatSenderTest
}
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(key_pair_.LoadFromString(kTestHostKeyPair));
key_pair_ = RsaKeyPair::FromString(kTestRsaKeyPair);
ASSERT_TRUE(key_pair_);
EXPECT_CALL(signal_strategy_, GetState())
.WillOnce(Return(SignalStrategy::DISCONNECTED));
......@@ -70,7 +71,7 @@ class HeartbeatSenderTest
.WillRepeatedly(Return(kTestJid));
heartbeat_sender_.reset(new HeartbeatSender(
this, kHostId, &signal_strategy_, &key_pair_, kTestBotJid));
this, kHostId, &signal_strategy_, key_pair_, kTestBotJid));
}
virtual void TearDown() OVERRIDE {
......@@ -84,7 +85,7 @@ class HeartbeatSenderTest
MessageLoop message_loop_;
MockSignalStrategy signal_strategy_;
std::set<SignalStrategy::Listener*> signal_strategy_listeners_;
HostKeyPair key_pair_;
scoped_refptr<RsaKeyPair> key_pair_;
scoped_ptr<HeartbeatSender> heartbeat_sender_;
};
......@@ -236,10 +237,10 @@ void HeartbeatSenderTest::ValidateHeartbeatStanza(
ASSERT_TRUE(signature != NULL);
EXPECT_TRUE(heartbeat_stanza->NextNamed(signature_tag) == NULL);
HostKeyPair key_pair;
key_pair.LoadFromString(kTestHostKeyPair);
scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(kTestRsaKeyPair);
ASSERT_TRUE(key_pair);
std::string expected_signature =
key_pair.GetSignature(std::string(kTestJid) + ' ' + expectedSequenceId);
key_pair->SignMessage(std::string(kTestJid) + ' ' + expectedSequenceId);
EXPECT_EQ(expected_signature, signature->BodyText());
}
......
// 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.
#include <string>
#include "base/files/scoped_temp_dir.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "base/string_util.h"
#include "remoting/host/host_key_pair.h"
#include "remoting/host/json_host_config.h"
#include "remoting/host/test_key_pair.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace remoting {
namespace {
const char kTestMessage[] = "Test Message";
// |kTestMessage| signed with the key from |kTestHostKeyPair|.
const char kExpectedSignature[] =
"LfUyXU2AiKM4rpWivUR3bLiQiRt1W3iIenNfJEB8RWyoEfnvSBoD52x8q9yFvtLFDEMPWyIrwM+N2"
"LuaWBKG1c0R7h+twBgvpExzZneJl+lbGMRx9ba8m/KAFrUWA/NRzOen2NHCuPybOEasgrPgGWBrmf"
"gDcvyW8QiGuKLopGj/4c5CQT4yE8JjsyU3Qqo2ZPK4neJYQhOmAlg+Q5dAPLpzWMj5HQyOVHJaSXZ"
"Y8vl/LiKvbdofYLeYNVKAE4q5mfpQMrsysPYpbxBV60AhFyrvtC040MFGcflKQRZNiZwMXVb7DclC"
"BPgvK7rI5Y0ERtVm+yNmH7vCivfyAnDUYA==";
} // namespace
class HostKeyPairTest : public testing::Test {
protected:
virtual void SetUp() {
ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
base::FilePath config_path = test_dir_.path().AppendASCII("test_config.json");
config_.reset(new JsonHostConfig(config_path));
}
MessageLoop message_loop_;
base::ScopedTempDir test_dir_;
scoped_ptr<JsonHostConfig> config_;
};
TEST_F(HostKeyPairTest, SaveLoad) {
// Save a key to a config, then load it back, and verify that we
// generate the same signature with both keys.
HostKeyPair exported_key;
exported_key.LoadFromString(kTestHostKeyPair);
exported_key.Save(config_.get());
message_loop_.RunUntilIdle();
HostKeyPair imported_key;
imported_key.Load(*config_);
ASSERT_EQ(exported_key.GetSignature(kTestMessage),
imported_key.GetSignature(kTestMessage));
}
TEST_F(HostKeyPairTest, Signatures) {
// Sign a message and check that we get expected signature.
HostKeyPair key_pair;
key_pair.LoadFromString(kTestHostKeyPair);
std::string signature_base64 = key_pair.GetSignature(kTestMessage);
ASSERT_EQ(signature_base64, std::string(kExpectedSignature));
}
} // namespace remoting
......@@ -18,12 +18,12 @@
#include "net/base/net_util.h"
#include "remoting/base/auth_token_util.h"
#include "remoting/base/auto_thread.h"
#include "remoting/base/rsa_key_pair.h"
#include "remoting/host/basic_desktop_environment.h"
#include "remoting/host/chromoting_host.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/host_config.h"
#include "remoting/host/host_event_logger.h"
#include "remoting/host/host_key_pair.h"
#include "remoting/host/host_secret.h"
#include "remoting/host/host_status_observer.h"
#include "remoting/host/it2me_host_user_interface.h"
......@@ -162,7 +162,7 @@ class HostNPScriptObject::It2MeImpl
State state_;
HostKeyPair host_key_pair_;
scoped_refptr<RsaKeyPair> host_key_pair_;
scoped_ptr<SignalStrategy> signal_strategy_;
scoped_ptr<RegisterSupportHostRequest> register_request_;
scoped_ptr<LogToServer> log_to_server_;
......@@ -344,7 +344,7 @@ void HostNPScriptObject::It2MeImpl::FinishConnect(
// Generate a key pair for the Host to use.
// TODO(wez): Move this to the worker thread.
host_key_pair_.Generate();
host_key_pair_ = RsaKeyPair::Generate();
// Create XMPP connection.
scoped_ptr<SignalStrategy> signal_strategy(
......@@ -355,7 +355,7 @@ void HostNPScriptObject::It2MeImpl::FinishConnect(
// Request registration of the host for support.
scoped_ptr<RegisterSupportHostRequest> register_request(
new RegisterSupportHostRequest(
signal_strategy.get(), &host_key_pair_, directory_bot_jid_,
signal_strategy.get(), host_key_pair_, directory_bot_jid_,
base::Bind(&It2MeImpl::OnReceivedSupportID,
base::Unretained(this))));
......@@ -642,7 +642,7 @@ void HostNPScriptObject::It2MeImpl::OnReceivedSupportID(
std::string host_secret = GenerateSupportHostSecret();
std::string access_code = support_id + host_secret;
std::string local_certificate = host_key_pair_.GenerateCertificate();
std::string local_certificate = host_key_pair_->GenerateCertificate();
if (local_certificate.empty()) {
LOG(ERROR) << "Failed to generate host certificate.";
SetState(kError);
......@@ -652,7 +652,7 @@ void HostNPScriptObject::It2MeImpl::OnReceivedSupportID(
scoped_ptr<protocol::AuthenticatorFactory> factory(
new protocol::It2MeHostAuthenticatorFactory(
local_certificate, *host_key_pair_.private_key(), access_code));
local_certificate, host_key_pair_, access_code));
host_->SetAuthenticatorFactory(factory.Pass());
// Pass the Access Code to the script object before changing state.
......@@ -1448,10 +1448,9 @@ bool HostNPScriptObject::LocalizeStringWithSubstitution(
}
void HostNPScriptObject::DoGenerateKeyPair(const ScopedRefNPObject& callback) {
HostKeyPair key_pair;
key_pair.Generate();
InvokeGenerateKeyPairCallback(callback, key_pair.GetAsString(),
key_pair.GetPublicKey());
scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate();
InvokeGenerateKeyPairCallback(callback, key_pair->ToString(),
key_pair->GetPublicKey());
}
void HostNPScriptObject::InvokeGenerateKeyPairCallback(
......
......@@ -21,7 +21,6 @@
#include "base/time.h"
#include "remoting/base/auto_thread_task_runner.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/host_key_pair.h"
#include "remoting/host/log_to_server.h"
#include "remoting/host/plugin/host_plugin_utils.h"
#include "remoting/host/setup/daemon_controller.h"
......
......@@ -36,7 +36,7 @@ const char kSupportIdLifetimeTag[] = "support-id-lifetime";
RegisterSupportHostRequest::RegisterSupportHostRequest(
SignalStrategy* signal_strategy,
HostKeyPair* key_pair,
scoped_refptr<RsaKeyPair> key_pair,
const std::string& directory_bot_jid,
const RegisterCallback& callback)
: signal_strategy_(signal_strategy),
......@@ -98,7 +98,7 @@ scoped_ptr<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_->SignMessage(message));
signature_tag->AddText(signature);
return signature_tag.Pass();
......
......@@ -10,8 +10,8 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "remoting/base/rsa_key_pair.h"
#include "remoting/jingle_glue/signal_strategy.h"
#include "remoting/host/host_key_pair.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
class MessageLoop;
......@@ -49,7 +49,7 @@ class RegisterSupportHostRequest : public SignalStrategy::Listener {
// TODO(sergeyu): This class should have timeout for the bot
// response.
RegisterSupportHostRequest(SignalStrategy* signal_strategy,
HostKeyPair* key_pair,
scoped_refptr<RsaKeyPair> key_pair,
const std::string& directory_bot_jid,
const RegisterCallback& callback);
virtual ~RegisterSupportHostRequest();
......@@ -75,7 +75,7 @@ class RegisterSupportHostRequest : public SignalStrategy::Listener {
bool success, const std::string& support_id, base::TimeDelta lifetime);
SignalStrategy* signal_strategy_;
HostKeyPair* key_pair_;
scoped_refptr<RsaKeyPair> key_pair_;
std::string directory_bot_jid_;
RegisterCallback callback_;
......
......@@ -10,9 +10,9 @@
#include "base/observer_list.h"
#include "base/string_number_conversions.h"
#include "remoting/base/constants.h"
#