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 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 std::vector<uint8> public_key; | 71 std::vector<uint8> public_key; |
72 CHECK(key_->ExportPublicKey(&public_key)); | 72 CHECK(key_->ExportPublicKey(&public_key)); |
73 std::string public_key_str(public_key.begin(), public_key.end()); | 73 std::string public_key_str(public_key.begin(), public_key.end()); |
74 std::string public_key_base64; | 74 std::string public_key_base64; |
75 base::Base64Encode(public_key_str, &public_key_base64); | 75 base::Base64Encode(public_key_str, &public_key_base64); |
76 return public_key_base64; | 76 return public_key_base64; |
77 } | 77 } |
78 | 78 |
79 std::string RsaKeyPair::SignMessage(const std::string& message) const { | 79 std::string RsaKeyPair::SignMessage(const std::string& message) const { |
80 scoped_ptr<crypto::SignatureCreator> signature_creator( | 80 scoped_ptr<crypto::SignatureCreator> signature_creator( |
81 crypto::SignatureCreator::Create(key_.get())); | 81 crypto::SignatureCreator::Create(key_.get(), |
| 82 crypto::SignatureCreator::SHA1)); |
82 signature_creator->Update(reinterpret_cast<const uint8*>(message.c_str()), | 83 signature_creator->Update(reinterpret_cast<const uint8*>(message.c_str()), |
83 message.length()); | 84 message.length()); |
84 std::vector<uint8> signature_buf; | 85 std::vector<uint8> signature_buf; |
85 signature_creator->Final(&signature_buf); | 86 signature_creator->Final(&signature_buf); |
86 std::string signature_str(signature_buf.begin(), signature_buf.end()); | 87 std::string signature_str(signature_buf.begin(), signature_buf.end()); |
87 std::string signature_base64; | 88 std::string signature_base64; |
88 base::Base64Encode(signature_str, &signature_base64); | 89 base::Base64Encode(signature_str, &signature_base64); |
89 return signature_base64; | 90 return signature_base64; |
90 } | 91 } |
91 | 92 |
92 std::string RsaKeyPair::GenerateCertificate() const { | 93 std::string RsaKeyPair::GenerateCertificate() const { |
93 std::string der_cert; | 94 std::string der_cert; |
94 // Certificates are SHA1-signed because |key_| has likely been used to sign | 95 // Certificates are SHA1-signed because |key_| has likely been used to sign |
95 // with SHA1 previously, and you should not re-use a key for signing data with | 96 // with SHA1 previously, and you should not re-use a key for signing data with |
96 // multiple signature algorithms. | 97 // multiple signature algorithms. |
97 net::x509_util::CreateSelfSignedCert( | 98 net::x509_util::CreateSelfSignedCert( |
98 key_.get(), | 99 key_.get(), |
99 net::x509_util::DIGEST_SHA1, | 100 net::x509_util::DIGEST_SHA1, |
100 "CN=chromoting", | 101 "CN=chromoting", |
101 base::RandInt(1, std::numeric_limits<int>::max()), | 102 base::RandInt(1, std::numeric_limits<int>::max()), |
102 base::Time::Now(), | 103 base::Time::Now(), |
103 base::Time::Now() + base::TimeDelta::FromDays(1), | 104 base::Time::Now() + base::TimeDelta::FromDays(1), |
104 &der_cert); | 105 &der_cert); |
105 return der_cert; | 106 return der_cert; |
106 } | 107 } |
107 | 108 |
108 } // namespace remoting | 109 } // namespace remoting |
OLD | NEW |