OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/cert/x509_util_ios_and_mac.h" |
| 6 |
| 7 #include "net/cert/x509_certificate.h" |
| 8 #if defined(OS_IOS) |
| 9 #include "net/cert/x509_util_ios.h" |
| 10 #else |
| 11 #include "net/cert/x509_util_mac.h" |
| 12 #endif |
| 13 #include "third_party/boringssl/src/include/openssl/pool.h" |
| 14 |
| 15 namespace net { |
| 16 |
| 17 namespace x509_util { |
| 18 |
| 19 base::ScopedCFTypeRef<CFMutableArrayRef> |
| 20 CreateSecCertificateArrayForX509Certificate(X509Certificate* cert) { |
| 21 base::ScopedCFTypeRef<CFMutableArrayRef> cert_list( |
| 22 CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks)); |
| 23 if (!cert_list) |
| 24 return base::ScopedCFTypeRef<CFMutableArrayRef>(); |
| 25 #if BUILDFLAG(USE_BYTE_CERTS) |
| 26 std::string bytes; |
| 27 base::ScopedCFTypeRef<SecCertificateRef> sec_cert( |
| 28 CreateSecCertificateFromBytes(CRYPTO_BUFFER_data(cert->os_cert_handle()), |
| 29 CRYPTO_BUFFER_len(cert->os_cert_handle()))); |
| 30 if (!sec_cert) |
| 31 return base::ScopedCFTypeRef<CFMutableArrayRef>(); |
| 32 CFArrayAppendValue(cert_list, sec_cert); |
| 33 for (X509Certificate::OSCertHandle intermediate : |
| 34 cert->GetIntermediateCertificates()) { |
| 35 base::ScopedCFTypeRef<SecCertificateRef> sec_cert( |
| 36 CreateSecCertificateFromBytes(CRYPTO_BUFFER_data(intermediate), |
| 37 CRYPTO_BUFFER_len(intermediate))); |
| 38 if (!sec_cert) |
| 39 return base::ScopedCFTypeRef<CFMutableArrayRef>(); |
| 40 CFArrayAppendValue(cert_list, sec_cert); |
| 41 } |
| 42 #else |
| 43 X509Certificate::OSCertHandles intermediate_ca_certs = |
| 44 cert->GetIntermediateCertificates(); |
| 45 CFArrayAppendValue(cert_list, cert->os_cert_handle()); |
| 46 for (size_t i = 0; i < intermediate_ca_certs.size(); ++i) |
| 47 CFArrayAppendValue(cert_list, intermediate_ca_certs[i]); |
| 48 #endif |
| 49 return cert_list; |
| 50 } |
| 51 |
| 52 } // namespace x509_util |
| 53 |
| 54 } // namespace net |
OLD | NEW |