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 <cert.h> | 5 #include <cert.h> |
6 #include <cryptohi.h> | 6 #include <cryptohi.h> |
7 #include <keyhi.h> | 7 #include <keyhi.h> |
8 #include <nss.h> | 8 #include <nss.h> |
9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
10 #include <prtime.h> | 10 #include <prtime.h> |
11 #include <seccomon.h> | 11 #include <seccomon.h> |
12 #include <secder.h> | 12 #include <secder.h> |
13 #include <sechash.h> | 13 #include <sechash.h> |
14 | 14 |
15 #include <memory> | 15 #include <memory> |
16 | 16 |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.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/time.h" | 21 #include "base/time/time.h" |
22 #include "crypto/nss_util.h" | 22 #include "crypto/nss_util.h" |
23 #include "crypto/scoped_nss_types.h" | 23 #include "crypto/scoped_nss_types.h" |
24 #include "net/cert/x509_certificate.h" | 24 #include "net/cert/x509_certificate.h" |
25 #include "net/cert/x509_util_nss.h" | 25 #include "net/cert/x509_util_nss.h" |
26 | 26 |
27 namespace net { | 27 namespace net { |
28 | 28 |
29 void X509Certificate::Initialize() { | 29 bool X509Certificate::Initialize() { |
30 x509_util::ParsePrincipal(&cert_handle_->subject, &subject_); | 30 serial_number_ = x509_util::ParseSerialNumber(cert_handle_); |
31 x509_util::ParsePrincipal(&cert_handle_->issuer, &issuer_); | |
32 | 31 |
33 x509_util::ParseDate(&cert_handle_->validity.notBefore, &valid_start_); | 32 return ( |
34 x509_util::ParseDate(&cert_handle_->validity.notAfter, &valid_expiry_); | 33 !serial_number_.empty() && |
35 | 34 x509_util::ParsePrincipal(&cert_handle_->subject, &subject_) && |
36 serial_number_ = x509_util::ParseSerialNumber(cert_handle_); | 35 x509_util::ParsePrincipal(&cert_handle_->issuer, &issuer_) && |
| 36 x509_util::ParseDate(&cert_handle_->validity.notBefore, &valid_start_) && |
| 37 x509_util::ParseDate(&cert_handle_->validity.notAfter, &valid_expiry_)); |
37 } | 38 } |
38 | 39 |
39 std::string X509Certificate::GetDefaultNickname(CertType type) const { | 40 std::string X509Certificate::GetDefaultNickname(CertType type) const { |
40 std::string result; | 41 std::string result; |
41 if (type == USER_CERT && cert_handle_->slot) { | 42 if (type == USER_CERT && cert_handle_->slot) { |
42 // Find the private key for this certificate and see if it has a | 43 // Find the private key for this certificate and see if it has a |
43 // nickname. If there is a private key, and it has a nickname, then | 44 // nickname. If there is a private key, and it has a nickname, then |
44 // return that nickname. | 45 // return that nickname. |
45 SECKEYPrivateKey* private_key = PK11_FindPrivateKeyFromCert( | 46 SECKEYPrivateKey* private_key = PK11_FindPrivateKeyFromCert( |
46 cert_handle_->slot, | 47 cert_handle_->slot, |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 return false; | 246 return false; |
246 if (SECSuccess != CERT_VerifySignedDataWithPublicKey( | 247 if (SECSuccess != CERT_VerifySignedDataWithPublicKey( |
247 &cert_handle->signatureWrap, public_key.get(), NULL)) { | 248 &cert_handle->signatureWrap, public_key.get(), NULL)) { |
248 return false; | 249 return false; |
249 } | 250 } |
250 return CERT_CompareName(&cert_handle->subject, &cert_handle->issuer) == | 251 return CERT_CompareName(&cert_handle->subject, &cert_handle->issuer) == |
251 SECEqual; | 252 SECEqual; |
252 } | 253 } |
253 | 254 |
254 } // namespace net | 255 } // namespace net |
OLD | NEW |