| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/x509_certificate.h" | 5 #include "net/base/x509_certificate.h" |
| 6 | 6 |
| 7 #include <CommonCrypto/CommonDigest.h> | 7 #include <CommonCrypto/CommonDigest.h> |
| 8 #include <CoreServices/CoreServices.h> | 8 #include <CoreServices/CoreServices.h> |
| 9 #include <Security/Security.h> | 9 #include <Security/Security.h> |
| 10 #include <time.h> | 10 #include <time.h> |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 CSSM_CL_CertAbortQuery(cl_handle_, results_handle); | 251 CSSM_CL_CertAbortQuery(cl_handle_, results_handle); |
| 252 field->Reset(cl_handle_, oid, field_ptr); | 252 field->Reset(cl_handle_, oid, field_ptr); |
| 253 return CSSM_OK; | 253 return CSSM_OK; |
| 254 } | 254 } |
| 255 | 255 |
| 256 private: | 256 private: |
| 257 CSSM_CL_HANDLE cl_handle_; | 257 CSSM_CL_HANDLE cl_handle_; |
| 258 CSSM_HANDLE cached_cert_handle_; | 258 CSSM_HANDLE cached_cert_handle_; |
| 259 }; | 259 }; |
| 260 | 260 |
| 261 void GetCertDistinguishedName(const CSSMCachedCertificate& cached_cert, |
| 262 const CSSM_OID* oid, |
| 263 CertPrincipal* result) { |
| 264 CSSMFieldValue distinguished_name; |
| 265 OSStatus status = cached_cert.GetField(oid, &distinguished_name); |
| 266 if (status || !distinguished_name.field()) |
| 267 return; |
| 268 result->ParseDistinguishedName(distinguished_name.field()->Data, |
| 269 distinguished_name.field()->Length); |
| 270 } |
| 271 |
| 261 void GetCertDateForOID(const CSSMCachedCertificate& cached_cert, | 272 void GetCertDateForOID(const CSSMCachedCertificate& cached_cert, |
| 262 const CSSM_OID* oid, | 273 const CSSM_OID* oid, |
| 263 Time* result) { | 274 Time* result) { |
| 264 *result = Time::Time(); | 275 *result = Time::Time(); |
| 265 | 276 |
| 266 CSSMFieldValue field; | 277 CSSMFieldValue field; |
| 267 OSStatus status = cached_cert.GetField(oid, &field); | 278 OSStatus status = cached_cert.GetField(oid, &field); |
| 268 if (status) | 279 if (status) |
| 269 return; | 280 return; |
| 270 | 281 |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 | 681 |
| 671 SHA1Fingerprint hash; | 682 SHA1Fingerprint hash; |
| 672 CC_SHA1(spki_bytes.data(), spki_bytes.size(), hash.data); | 683 CC_SHA1(spki_bytes.data(), spki_bytes.size(), hash.data); |
| 673 hashes->push_back(hash); | 684 hashes->push_back(hash); |
| 674 } | 685 } |
| 675 } | 686 } |
| 676 | 687 |
| 677 } // namespace | 688 } // namespace |
| 678 | 689 |
| 679 void X509Certificate::Initialize() { | 690 void X509Certificate::Initialize() { |
| 680 const CSSM_X509_NAME* name; | |
| 681 OSStatus status = SecCertificateGetSubject(cert_handle_, &name); | |
| 682 if (!status) | |
| 683 subject_.Parse(name); | |
| 684 | |
| 685 status = SecCertificateGetIssuer(cert_handle_, &name); | |
| 686 if (!status) | |
| 687 issuer_.Parse(name); | |
| 688 | |
| 689 CSSMCachedCertificate cached_cert; | 691 CSSMCachedCertificate cached_cert; |
| 690 if (cached_cert.Init(cert_handle_) == CSSM_OK) { | 692 if (cached_cert.Init(cert_handle_) == CSSM_OK) { |
| 693 GetCertDistinguishedName(cached_cert, &CSSMOID_X509V1SubjectNameStd, |
| 694 &subject_); |
| 695 GetCertDistinguishedName(cached_cert, &CSSMOID_X509V1IssuerNameStd, |
| 696 &issuer_); |
| 691 GetCertDateForOID(cached_cert, &CSSMOID_X509V1ValidityNotBefore, | 697 GetCertDateForOID(cached_cert, &CSSMOID_X509V1ValidityNotBefore, |
| 692 &valid_start_); | 698 &valid_start_); |
| 693 GetCertDateForOID(cached_cert, &CSSMOID_X509V1ValidityNotAfter, | 699 GetCertDateForOID(cached_cert, &CSSMOID_X509V1ValidityNotAfter, |
| 694 &valid_expiry_); | 700 &valid_expiry_); |
| 695 serial_number_ = GetCertSerialNumber(cached_cert); | 701 serial_number_ = GetCertSerialNumber(cached_cert); |
| 696 } | 702 } |
| 697 | 703 |
| 698 fingerprint_ = CalculateFingerprint(cert_handle_); | 704 fingerprint_ = CalculateFingerprint(cert_handle_); |
| 699 ca_fingerprint_ = CalculateCAFingerprint(intermediate_ca_certs_); | 705 ca_fingerprint_ = CalculateCAFingerprint(intermediate_ca_certs_); |
| 700 } | 706 } |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1553 *type = kPublicKeyTypeDH; | 1559 *type = kPublicKeyTypeDH; |
| 1554 break; | 1560 break; |
| 1555 default: | 1561 default: |
| 1556 *type = kPublicKeyTypeUnknown; | 1562 *type = kPublicKeyTypeUnknown; |
| 1557 *size_bits = 0; | 1563 *size_bits = 0; |
| 1558 break; | 1564 break; |
| 1559 } | 1565 } |
| 1560 } | 1566 } |
| 1561 | 1567 |
| 1562 } // namespace net | 1568 } // namespace net |
| OLD | NEW |