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 "net/cert/x509_util.h" | 5 #include "net/cert/x509_util.h" |
6 | 6 |
7 #include "base/basictypes.h" | |
8 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
9 #include "base/time/time.h" | 8 #include "base/time/time.h" |
10 #include "crypto/ec_private_key.h" | 9 #include "crypto/ec_private_key.h" |
11 #include "crypto/rsa_private_key.h" | 10 #include "crypto/rsa_private_key.h" |
12 #include "net/cert/x509_certificate.h" | 11 #include "net/cert/x509_certificate.h" |
13 | 12 |
14 namespace net { | 13 namespace net { |
15 | 14 |
16 namespace x509_util { | 15 namespace x509_util { |
17 | 16 |
18 // RSA keys created by CreateKeyAndSelfSignedCert will be of this length. | 17 // RSA keys created by CreateKeyAndSelfSignedCert will be of this length. |
19 static const uint16 kRSAKeyLength = 1024; | 18 static const uint16_t kRSAKeyLength = 1024; |
20 | 19 |
21 // Certificates made by CreateKeyAndSelfSignedCert and | 20 // Certificates made by CreateKeyAndSelfSignedCert and |
22 // CreateKeyAndChannelIDEC will be signed using this digest algorithm. | 21 // CreateKeyAndChannelIDEC will be signed using this digest algorithm. |
23 static const DigestAlgorithm kSignatureDigestAlgorithm = DIGEST_SHA256; | 22 static const DigestAlgorithm kSignatureDigestAlgorithm = DIGEST_SHA256; |
24 | 23 |
25 ClientCertSorter::ClientCertSorter() : now_(base::Time::Now()) {} | 24 ClientCertSorter::ClientCertSorter() : now_(base::Time::Now()) {} |
26 | 25 |
27 bool ClientCertSorter::operator()( | 26 bool ClientCertSorter::operator()( |
28 const scoped_refptr<X509Certificate>& a, | 27 const scoped_refptr<X509Certificate>& a, |
29 const scoped_refptr<X509Certificate>& b) const { | 28 const scoped_refptr<X509Certificate>& b) const { |
(...skipping 19 matching lines...) Expand all Loading... |
49 | 48 |
50 // Otherwise, prefer client certificates with shorter chains. | 49 // Otherwise, prefer client certificates with shorter chains. |
51 const X509Certificate::OSCertHandles& a_intermediates = | 50 const X509Certificate::OSCertHandles& a_intermediates = |
52 a->GetIntermediateCertificates(); | 51 a->GetIntermediateCertificates(); |
53 const X509Certificate::OSCertHandles& b_intermediates = | 52 const X509Certificate::OSCertHandles& b_intermediates = |
54 b->GetIntermediateCertificates(); | 53 b->GetIntermediateCertificates(); |
55 return a_intermediates.size() < b_intermediates.size(); | 54 return a_intermediates.size() < b_intermediates.size(); |
56 } | 55 } |
57 | 56 |
58 bool CreateKeyAndSelfSignedCert(const std::string& subject, | 57 bool CreateKeyAndSelfSignedCert(const std::string& subject, |
59 uint32 serial_number, | 58 uint32_t serial_number, |
60 base::Time not_valid_before, | 59 base::Time not_valid_before, |
61 base::Time not_valid_after, | 60 base::Time not_valid_after, |
62 scoped_ptr<crypto::RSAPrivateKey>* key, | 61 scoped_ptr<crypto::RSAPrivateKey>* key, |
63 std::string* der_cert) { | 62 std::string* der_cert) { |
64 scoped_ptr<crypto::RSAPrivateKey> new_key( | 63 scoped_ptr<crypto::RSAPrivateKey> new_key( |
65 crypto::RSAPrivateKey::Create(kRSAKeyLength)); | 64 crypto::RSAPrivateKey::Create(kRSAKeyLength)); |
66 if (!new_key.get()) | 65 if (!new_key.get()) |
67 return false; | 66 return false; |
68 | 67 |
69 bool success = CreateSelfSignedCert(new_key.get(), | 68 bool success = CreateSelfSignedCert(new_key.get(), |
70 kSignatureDigestAlgorithm, | 69 kSignatureDigestAlgorithm, |
71 subject, | 70 subject, |
72 serial_number, | 71 serial_number, |
73 not_valid_before, | 72 not_valid_before, |
74 not_valid_after, | 73 not_valid_after, |
75 der_cert); | 74 der_cert); |
76 if (success) | 75 if (success) |
77 key->reset(new_key.release()); | 76 key->reset(new_key.release()); |
78 | 77 |
79 return success; | 78 return success; |
80 } | 79 } |
81 | 80 |
82 } // namespace x509_util | 81 } // namespace x509_util |
83 | 82 |
84 } // namespace net | 83 } // namespace net |
OLD | NEW |