OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/rsa_key_pair.h" | 5 #include "remoting/base/rsa_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/logging.h" | 12 #include "base/logging.h" |
13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "crypto/rsa_private_key.h" | 15 #include "crypto/rsa_private_key.h" |
16 #include "crypto/signature_creator.h" | 16 #include "crypto/signature_creator.h" |
17 #include "net/cert/x509_certificate.h" | 17 #include "net/cert/x509_util.h" |
18 | 18 |
19 namespace remoting { | 19 namespace remoting { |
20 | 20 |
21 RsaKeyPair::RsaKeyPair(scoped_ptr<crypto::RSAPrivateKey> key) | 21 RsaKeyPair::RsaKeyPair(scoped_ptr<crypto::RSAPrivateKey> key) |
22 : key_(key.Pass()){ | 22 : key_(key.Pass()){ |
23 DCHECK(key_); | 23 DCHECK(key_); |
24 } | 24 } |
25 | 25 |
26 RsaKeyPair::~RsaKeyPair() {} | 26 RsaKeyPair::~RsaKeyPair() {} |
27 | 27 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 message.length()); | 85 message.length()); |
86 std::vector<uint8> signature_buf; | 86 std::vector<uint8> signature_buf; |
87 signature_creator->Final(&signature_buf); | 87 signature_creator->Final(&signature_buf); |
88 std::string signature_str(signature_buf.begin(), signature_buf.end()); | 88 std::string signature_str(signature_buf.begin(), signature_buf.end()); |
89 std::string signature_base64; | 89 std::string signature_base64; |
90 base::Base64Encode(signature_str, &signature_base64); | 90 base::Base64Encode(signature_str, &signature_base64); |
91 return signature_base64; | 91 return signature_base64; |
92 } | 92 } |
93 | 93 |
94 std::string RsaKeyPair::GenerateCertificate() const { | 94 std::string RsaKeyPair::GenerateCertificate() const { |
95 scoped_refptr<net::X509Certificate> cert = | 95 std::string der_cert; |
96 net::X509Certificate::CreateSelfSigned( | 96 net::x509_util::CreateSelfSignedCert( |
97 key_.get(), "CN=chromoting", | 97 key_.get(), |
98 base::RandInt(1, std::numeric_limits<int>::max()), | 98 "CN=chromoting", |
99 base::TimeDelta::FromDays(1)); | 99 base::RandInt(1, std::numeric_limits<int>::max()), |
100 if (!cert.get()) | 100 base::Time::Now(), |
101 return std::string(); | 101 base::Time::Now() + base::TimeDelta::FromDays(1), |
102 | 102 &der_cert); |
103 std::string encoded; | 103 return der_cert; |
104 bool result = net::X509Certificate::GetDEREncoded(cert->os_cert_handle(), | |
105 &encoded); | |
106 CHECK(result); | |
107 return encoded; | |
108 } | 104 } |
109 | 105 |
110 } // namespace remoting | 106 } // namespace remoting |
OLD | NEW |