Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: remoting/host/host_key_pair.cc

Issue 6805019: Move crypto files out of base, to a top level directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixes comments by eroman Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/host_key_pair.h ('k') | remoting/host/keygen_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "remoting/host/host_key_pair.h" 5 #include "remoting/host/host_key_pair.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/crypto/rsa_private_key.h"
13 #include "base/crypto/signature_creator.h"
14 #include "base/logging.h" 12 #include "base/logging.h"
15 #include "base/rand_util.h" 13 #include "base/rand_util.h"
16 #include "base/task.h" 14 #include "base/task.h"
17 #include "base/time.h" 15 #include "base/time.h"
16 #include "crypto/rsa_private_key.h"
17 #include "crypto/signature_creator.h"
18 #include "net/base/x509_certificate.h" 18 #include "net/base/x509_certificate.h"
19 #include "remoting/host/host_config.h" 19 #include "remoting/host/host_config.h"
20 20
21 namespace remoting { 21 namespace remoting {
22 22
23 HostKeyPair::HostKeyPair() { } 23 HostKeyPair::HostKeyPair() { }
24 24
25 HostKeyPair::~HostKeyPair() { } 25 HostKeyPair::~HostKeyPair() { }
26 26
27 void HostKeyPair::Generate() { 27 void HostKeyPair::Generate() {
28 key_.reset(base::RSAPrivateKey::Create(2048)); 28 key_.reset(crypto::RSAPrivateKey::Create(2048));
29 } 29 }
30 30
31 bool HostKeyPair::LoadFromString(const std::string& key_base64) { 31 bool HostKeyPair::LoadFromString(const std::string& key_base64) {
32 std::string key_str; 32 std::string key_str;
33 if (!base::Base64Decode(key_base64, &key_str)) { 33 if (!base::Base64Decode(key_base64, &key_str)) {
34 LOG(ERROR) << "Failed to decode private key."; 34 LOG(ERROR) << "Failed to decode private key.";
35 return false; 35 return false;
36 } 36 }
37 37
38 std::vector<uint8> key_buf(key_str.begin(), key_str.end()); 38 std::vector<uint8> key_buf(key_str.begin(), key_str.end());
39 key_.reset(base::RSAPrivateKey::CreateFromPrivateKeyInfo(key_buf)); 39 key_.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_buf));
40 if (key_.get() == NULL) { 40 if (key_.get() == NULL) {
41 LOG(ERROR) << "Invalid private key."; 41 LOG(ERROR) << "Invalid private key.";
42 return false; 42 return false;
43 } 43 }
44 44
45 return true; 45 return true;
46 } 46 }
47 47
48 bool HostKeyPair::Load(HostConfig* host_config) { 48 bool HostKeyPair::Load(HostConfig* host_config) {
49 std::string key_base64; 49 std::string key_base64;
(...skipping 19 matching lines...) Expand all
69 std::string HostKeyPair::GetPublicKey() const { 69 std::string HostKeyPair::GetPublicKey() const {
70 std::vector<uint8> public_key; 70 std::vector<uint8> public_key;
71 key_->ExportPublicKey(&public_key); 71 key_->ExportPublicKey(&public_key);
72 std::string public_key_str(public_key.begin(), public_key.end()); 72 std::string public_key_str(public_key.begin(), public_key.end());
73 std::string public_key_base64; 73 std::string public_key_base64;
74 base::Base64Encode(public_key_str, &public_key_base64); 74 base::Base64Encode(public_key_str, &public_key_base64);
75 return public_key_base64; 75 return public_key_base64;
76 } 76 }
77 77
78 std::string HostKeyPair::GetSignature(const std::string& message) const { 78 std::string HostKeyPair::GetSignature(const std::string& message) const {
79 scoped_ptr<base::SignatureCreator> signature_creator( 79 scoped_ptr<crypto::SignatureCreator> signature_creator(
80 base::SignatureCreator::Create(key_.get())); 80 crypto::SignatureCreator::Create(key_.get()));
81 signature_creator->Update(reinterpret_cast<const uint8*>(message.c_str()), 81 signature_creator->Update(reinterpret_cast<const uint8*>(message.c_str()),
82 message.length()); 82 message.length());
83 std::vector<uint8> signature_buf; 83 std::vector<uint8> signature_buf;
84 signature_creator->Final(&signature_buf); 84 signature_creator->Final(&signature_buf);
85 std::string signature_str(signature_buf.begin(), signature_buf.end()); 85 std::string signature_str(signature_buf.begin(), signature_buf.end());
86 std::string signature_base64; 86 std::string signature_base64;
87 base::Base64Encode(signature_str, &signature_base64); 87 base::Base64Encode(signature_str, &signature_base64);
88 return signature_base64; 88 return signature_base64;
89 } 89 }
90 90
91 base::RSAPrivateKey* HostKeyPair::CopyPrivateKey() const { 91 crypto::RSAPrivateKey* HostKeyPair::CopyPrivateKey() const {
92 std::vector<uint8> key_bytes; 92 std::vector<uint8> key_bytes;
93 CHECK(key_->ExportPrivateKey(&key_bytes)); 93 CHECK(key_->ExportPrivateKey(&key_bytes));
94 return base::RSAPrivateKey::CreateFromPrivateKeyInfo(key_bytes); 94 return crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_bytes);
95 } 95 }
96 96
97 net::X509Certificate* HostKeyPair::GenerateCertificate() const { 97 net::X509Certificate* HostKeyPair::GenerateCertificate() const {
98 return net::X509Certificate::CreateSelfSigned( 98 return net::X509Certificate::CreateSelfSigned(
99 key_.get(), "CN=chromoting", 99 key_.get(), "CN=chromoting",
100 base::RandInt(1, std::numeric_limits<int>::max()), 100 base::RandInt(1, std::numeric_limits<int>::max()),
101 base::TimeDelta::FromDays(1)); 101 base::TimeDelta::FromDays(1));
102 } 102 }
103 103
104 } // namespace remoting 104 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/host_key_pair.h ('k') | remoting/host/keygen_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698