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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/free_deleter.h" | 10 #include "base/memory/free_deleter.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 BOOL rb = CertCompareCertificateName( | 126 BOOL rb = CertCompareCertificateName( |
127 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, &issuer_blob, name_blob); | 127 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, &issuer_blob, name_blob); |
128 if (rb) | 128 if (rb) |
129 return true; | 129 return true; |
130 } | 130 } |
131 return false; | 131 return false; |
132 } | 132 } |
133 | 133 |
134 } // namespace | 134 } // namespace |
135 | 135 |
136 void X509Certificate::Initialize() { | 136 bool X509Certificate::Initialize() { |
137 DCHECK(cert_handle_); | 137 DCHECK(cert_handle_); |
138 subject_.ParseDistinguishedName(cert_handle_->pCertInfo->Subject.pbData, | 138 if (!subject_.ParseDistinguishedName( |
139 cert_handle_->pCertInfo->Subject.cbData); | 139 cert_handle_->pCertInfo->Subject.pbData, |
140 issuer_.ParseDistinguishedName(cert_handle_->pCertInfo->Issuer.pbData, | 140 cert_handle_->pCertInfo->Subject.cbData) || |
141 cert_handle_->pCertInfo->Issuer.cbData); | 141 !issuer_.ParseDistinguishedName(cert_handle_->pCertInfo->Issuer.pbData, |
| 142 cert_handle_->pCertInfo->Issuer.cbData)) |
| 143 return false; |
142 | 144 |
143 valid_start_ = Time::FromFileTime(cert_handle_->pCertInfo->NotBefore); | 145 valid_start_ = Time::FromFileTime(cert_handle_->pCertInfo->NotBefore); |
144 valid_expiry_ = Time::FromFileTime(cert_handle_->pCertInfo->NotAfter); | 146 valid_expiry_ = Time::FromFileTime(cert_handle_->pCertInfo->NotAfter); |
145 | 147 |
146 const CRYPT_INTEGER_BLOB* serial = &cert_handle_->pCertInfo->SerialNumber; | 148 const CRYPT_INTEGER_BLOB* serial = &cert_handle_->pCertInfo->SerialNumber; |
147 std::unique_ptr<uint8_t[]> serial_bytes(new uint8_t[serial->cbData]); | 149 std::unique_ptr<uint8_t[]> serial_bytes(new uint8_t[serial->cbData]); |
148 for (unsigned i = 0; i < serial->cbData; i++) | 150 for (unsigned i = 0; i < serial->cbData; i++) |
149 serial_bytes[i] = serial->pbData[serial->cbData - i - 1]; | 151 serial_bytes[i] = serial->pbData[serial->cbData - i - 1]; |
150 serial_number_ = std::string( | 152 serial_number_ = std::string( |
151 reinterpret_cast<char*>(serial_bytes.get()), serial->cbData); | 153 reinterpret_cast<char*>(serial_bytes.get()), serial->cbData); |
| 154 |
| 155 return true; |
152 } | 156 } |
153 | 157 |
154 bool X509Certificate::GetSubjectAltName( | 158 bool X509Certificate::GetSubjectAltName( |
155 std::vector<std::string>* dns_names, | 159 std::vector<std::string>* dns_names, |
156 std::vector<std::string>* ip_addrs) const { | 160 std::vector<std::string>* ip_addrs) const { |
157 if (dns_names) | 161 if (dns_names) |
158 dns_names->clear(); | 162 dns_names->clear(); |
159 if (ip_addrs) | 163 if (ip_addrs) |
160 ip_addrs->clear(); | 164 ip_addrs->clear(); |
161 | 165 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT, | 464 CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT, |
461 reinterpret_cast<void*>(const_cast<PCERT_CONTEXT>(cert_handle)), 0, NULL); | 465 reinterpret_cast<void*>(const_cast<PCERT_CONTEXT>(cert_handle)), 0, NULL); |
462 if (!valid_signature) | 466 if (!valid_signature) |
463 return false; | 467 return false; |
464 return !!CertCompareCertificateName(X509_ASN_ENCODING, | 468 return !!CertCompareCertificateName(X509_ASN_ENCODING, |
465 &cert_handle->pCertInfo->Subject, | 469 &cert_handle->pCertInfo->Subject, |
466 &cert_handle->pCertInfo->Issuer); | 470 &cert_handle->pCertInfo->Issuer); |
467 } | 471 } |
468 | 472 |
469 } // namespace net | 473 } // namespace net |
OLD | NEW |