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_certificate.h" | 5 #include "net/cert/x509_certificate.h" |
6 | 6 |
7 #include <cert.h> | 7 #include <cert.h> |
8 #include <cryptohi.h> | 8 #include <cryptohi.h> |
9 #include <keyhi.h> | 9 #include <keyhi.h> |
10 #include <nss.h> | 10 #include <nss.h> |
11 #include <pk11pub.h> | 11 #include <pk11pub.h> |
12 #include <prtime.h> | 12 #include <prtime.h> |
13 #include <seccomon.h> | 13 #include <seccomon.h> |
14 #include <secder.h> | 14 #include <secder.h> |
15 #include <sechash.h> | 15 #include <sechash.h> |
16 | 16 |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/pickle.h" | 19 #include "base/pickle.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/time.h" | 21 #include "base/time.h" |
22 #include "crypto/nss_util.h" | 22 #include "crypto/nss_util.h" |
23 #include "crypto/rsa_private_key.h" | |
24 #include "crypto/scoped_nss_types.h" | 23 #include "crypto/scoped_nss_types.h" |
25 #include "net/cert/x509_util_nss.h" | 24 #include "net/cert/x509_util_nss.h" |
26 | 25 |
27 namespace net { | 26 namespace net { |
28 | 27 |
29 void X509Certificate::Initialize() { | 28 void X509Certificate::Initialize() { |
30 x509_util::ParsePrincipal(&cert_handle_->subject, &subject_); | 29 x509_util::ParsePrincipal(&cert_handle_->subject, &subject_); |
31 x509_util::ParsePrincipal(&cert_handle_->issuer, &issuer_); | 30 x509_util::ParsePrincipal(&cert_handle_->issuer, &issuer_); |
32 | 31 |
33 x509_util::ParseDate(&cert_handle_->validity.notBefore, &valid_start_); | 32 x509_util::ParseDate(&cert_handle_->validity.notBefore, &valid_start_); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 case SERVER_CERT: | 106 case SERVER_CERT: |
108 result = subject_.GetDisplayName(); | 107 result = subject_.GetDisplayName(); |
109 break; | 108 break; |
110 case UNKNOWN_CERT: | 109 case UNKNOWN_CERT: |
111 default: | 110 default: |
112 break; | 111 break; |
113 } | 112 } |
114 return result; | 113 return result; |
115 } | 114 } |
116 | 115 |
117 // static | |
118 X509Certificate* X509Certificate::CreateSelfSigned( | |
119 crypto::RSAPrivateKey* key, | |
120 const std::string& subject, | |
121 uint32 serial_number, | |
122 base::TimeDelta valid_duration) { | |
123 DCHECK(key); | |
124 base::Time not_valid_before = base::Time::Now(); | |
125 base::Time not_valid_after = not_valid_before + valid_duration; | |
126 CERTCertificate* cert = x509_util::CreateSelfSignedCert(key->public_key(), | |
127 key->key(), | |
128 subject, | |
129 serial_number, | |
130 not_valid_before, | |
131 not_valid_after); | |
132 if (!cert) | |
133 return NULL; | |
134 | |
135 X509Certificate* x509_cert = X509Certificate::CreateFromHandle( | |
136 cert, X509Certificate::OSCertHandles()); | |
137 CERT_DestroyCertificate(cert); | |
138 return x509_cert; | |
139 } | |
140 | |
141 void X509Certificate::GetSubjectAltName( | 116 void X509Certificate::GetSubjectAltName( |
142 std::vector<std::string>* dns_names, | 117 std::vector<std::string>* dns_names, |
143 std::vector<std::string>* ip_addrs) const { | 118 std::vector<std::string>* ip_addrs) const { |
144 x509_util::GetSubjectAltName(cert_handle_, dns_names, ip_addrs); | 119 x509_util::GetSubjectAltName(cert_handle_, dns_names, ip_addrs); |
145 } | 120 } |
146 | 121 |
147 bool X509Certificate::IsIssuedByEncoded( | 122 bool X509Certificate::IsIssuedByEncoded( |
148 const std::vector<std::string>& valid_issuers) { | 123 const std::vector<std::string>& valid_issuers) { |
149 // Get certificate chain as scoped list of CERTCertificate objects. | 124 // Get certificate chain as scoped list of CERTCertificate objects. |
150 std::vector<CERTCertificate*> cert_chain; | 125 std::vector<CERTCertificate*> cert_chain; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } | 260 } |
286 | 261 |
287 // static | 262 // static |
288 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle, | 263 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle, |
289 size_t* size_bits, | 264 size_t* size_bits, |
290 PublicKeyType* type) { | 265 PublicKeyType* type) { |
291 x509_util::GetPublicKeyInfo(cert_handle, size_bits, type); | 266 x509_util::GetPublicKeyInfo(cert_handle, size_bits, type); |
292 } | 267 } |
293 | 268 |
294 } // namespace net | 269 } // namespace net |
OLD | NEW |