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_mac.h" | 5 #include "net/cert/x509_util_mac.h" |
6 | 6 |
7 #include <CommonCrypto/CommonDigest.h> | 7 #include <CommonCrypto/CommonDigest.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 return CreateSecCertificateFromBytes( | 85 return CreateSecCertificateFromBytes( |
86 CRYPTO_BUFFER_data(cert->os_cert_handle()), | 86 CRYPTO_BUFFER_data(cert->os_cert_handle()), |
87 CRYPTO_BUFFER_len(cert->os_cert_handle())); | 87 CRYPTO_BUFFER_len(cert->os_cert_handle())); |
88 #else | 88 #else |
89 return base::ScopedCFTypeRef<SecCertificateRef>( | 89 return base::ScopedCFTypeRef<SecCertificateRef>( |
90 reinterpret_cast<SecCertificateRef>( | 90 reinterpret_cast<SecCertificateRef>( |
91 const_cast<void*>(CFRetain(cert->os_cert_handle())))); | 91 const_cast<void*>(CFRetain(cert->os_cert_handle())))); |
92 #endif | 92 #endif |
93 } | 93 } |
94 | 94 |
95 base::ScopedCFTypeRef<CFMutableArrayRef> | |
96 CreateSecCertificateArrayForX509Certificate(X509Certificate* cert) { | |
97 base::ScopedCFTypeRef<CFMutableArrayRef> cert_list( | |
98 CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks)); | |
99 if (!cert_list) | |
100 return base::ScopedCFTypeRef<CFMutableArrayRef>(); | |
101 #if BUILDFLAG(USE_BYTE_CERTS) | |
102 std::string bytes; | |
103 base::ScopedCFTypeRef<SecCertificateRef> sec_cert( | |
104 CreateSecCertificateFromBytes(CRYPTO_BUFFER_data(cert->os_cert_handle()), | |
105 CRYPTO_BUFFER_len(cert->os_cert_handle()))); | |
106 if (!sec_cert) | |
107 return base::ScopedCFTypeRef<CFMutableArrayRef>(); | |
108 CFArrayAppendValue(cert_list, sec_cert); | |
109 for (X509Certificate::OSCertHandle intermediate : | |
110 cert->GetIntermediateCertificates()) { | |
111 base::ScopedCFTypeRef<SecCertificateRef> sec_cert( | |
112 CreateSecCertificateFromBytes(CRYPTO_BUFFER_data(intermediate), | |
113 CRYPTO_BUFFER_len(intermediate))); | |
114 if (!sec_cert) | |
115 return base::ScopedCFTypeRef<CFMutableArrayRef>(); | |
116 CFArrayAppendValue(cert_list, sec_cert); | |
117 } | |
118 #else | |
119 X509Certificate::OSCertHandles intermediate_ca_certs = | |
120 cert->GetIntermediateCertificates(); | |
121 CFArrayAppendValue(cert_list, cert->os_cert_handle()); | |
122 for (size_t i = 0; i < intermediate_ca_certs.size(); ++i) | |
123 CFArrayAppendValue(cert_list, intermediate_ca_certs[i]); | |
124 #endif | |
125 return cert_list; | |
126 } | |
127 | |
128 scoped_refptr<X509Certificate> CreateX509CertificateFromSecCertificate( | 95 scoped_refptr<X509Certificate> CreateX509CertificateFromSecCertificate( |
129 SecCertificateRef sec_cert, | 96 SecCertificateRef sec_cert, |
130 const std::vector<SecCertificateRef>& sec_chain) { | 97 const std::vector<SecCertificateRef>& sec_chain) { |
131 #if BUILDFLAG(USE_BYTE_CERTS) | 98 #if BUILDFLAG(USE_BYTE_CERTS) |
132 CSSM_DATA der_data; | 99 CSSM_DATA der_data; |
133 if (!sec_cert || SecCertificateGetData(sec_cert, &der_data) != noErr) | 100 if (!sec_cert || SecCertificateGetData(sec_cert, &der_data) != noErr) |
134 return nullptr; | 101 return nullptr; |
135 bssl::UniquePtr<CRYPTO_BUFFER> cert_handle( | 102 bssl::UniquePtr<CRYPTO_BUFFER> cert_handle( |
136 X509Certificate::CreateOSCertHandleFromBytes( | 103 X509Certificate::CreateOSCertHandleFromBytes( |
137 reinterpret_cast<const char*>(der_data.Data), der_data.Length)); | 104 reinterpret_cast<const char*>(der_data.Data), der_data.Length)); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 CSSM_CL_CertAbortQuery(cl_handle_, results_handle); | 379 CSSM_CL_CertAbortQuery(cl_handle_, results_handle); |
413 field->Reset(cl_handle_, oid, field_ptr); | 380 field->Reset(cl_handle_, oid, field_ptr); |
414 return CSSM_OK; | 381 return CSSM_OK; |
415 } | 382 } |
416 | 383 |
417 } // namespace x509_util | 384 } // namespace x509_util |
418 | 385 |
419 #pragma clang diagnostic pop // "-Wdeprecated-declarations" | 386 #pragma clang diagnostic pop // "-Wdeprecated-declarations" |
420 | 387 |
421 } // namespace net | 388 } // namespace net |
OLD | NEW |