| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 <CommonCrypto/CommonDigest.h> | 7 #include <CommonCrypto/CommonDigest.h> |
| 8 #include <Security/Security.h> | 8 #include <Security/Security.h> |
| 9 | 9 |
| 10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // invalid/unparsable certificate. Force parsing to occur to ensure that the | 32 // invalid/unparsable certificate. Force parsing to occur to ensure that the |
| 33 // SecCertificateRef is correct. On later versions where | 33 // SecCertificateRef is correct. On later versions where |
| 34 // SecCertificateCreateFromData() immediately parses, rather than lazily, this | 34 // SecCertificateCreateFromData() immediately parses, rather than lazily, this |
| 35 // call is cheap, as the subject is cached. | 35 // call is cheap, as the subject is cached. |
| 36 bool IsValidOSCertHandle(SecCertificateRef cert_handle) { | 36 bool IsValidOSCertHandle(SecCertificateRef cert_handle) { |
| 37 ScopedCFTypeRef<CFStringRef> sanity_check( | 37 ScopedCFTypeRef<CFStringRef> sanity_check( |
| 38 SecCertificateCopySubjectSummary(cert_handle)); | 38 SecCertificateCopySubjectSummary(cert_handle)); |
| 39 return sanity_check != nullptr; | 39 return sanity_check != nullptr; |
| 40 } | 40 } |
| 41 | 41 |
| 42 bssl::UniquePtr<X509> OSCertHandleToOpenSSL( |
| 43 X509Certificate::OSCertHandle os_handle) { |
| 44 std::string der_encoded; |
| 45 if (!X509Certificate::GetDEREncoded(os_handle, &der_encoded)) |
| 46 return nullptr; |
| 47 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(der_encoded.data()); |
| 48 return bssl::UniquePtr<X509>(d2i_X509(nullptr, &bytes, der_encoded.size())); |
| 49 } |
| 50 |
| 42 void CreateOSCertHandlesFromPKCS7Bytes( | 51 void CreateOSCertHandlesFromPKCS7Bytes( |
| 43 const char* data, | 52 const char* data, |
| 44 size_t length, | 53 size_t length, |
| 45 X509Certificate::OSCertHandles* handles) { | 54 X509Certificate::OSCertHandles* handles) { |
| 46 crypto::EnsureOpenSSLInit(); | 55 crypto::EnsureOpenSSLInit(); |
| 47 crypto::OpenSSLErrStackTracer err_cleaner(FROM_HERE); | 56 crypto::OpenSSLErrStackTracer err_cleaner(FROM_HERE); |
| 48 | 57 |
| 49 CBS der_data; | 58 CBS der_data; |
| 50 CBS_init(&der_data, reinterpret_cast<const uint8_t*>(data), length); | 59 CBS_init(&der_data, reinterpret_cast<const uint8_t*>(data), length); |
| 51 STACK_OF(X509)* certs = sk_X509_new_null(); | 60 STACK_OF(X509)* certs = sk_X509_new_null(); |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 return false; | 450 return false; |
| 442 bssl::UniquePtr<EVP_PKEY> scoped_key(X509_get_pubkey(cert.get())); | 451 bssl::UniquePtr<EVP_PKEY> scoped_key(X509_get_pubkey(cert.get())); |
| 443 if (!scoped_key) | 452 if (!scoped_key) |
| 444 return false; | 453 return false; |
| 445 if (!X509_verify(cert.get(), scoped_key.get())) | 454 if (!X509_verify(cert.get(), scoped_key.get())) |
| 446 return false; | 455 return false; |
| 447 return X509_check_issued(cert.get(), cert.get()) == X509_V_OK; | 456 return X509_check_issued(cert.get(), cert.get()) == X509_V_OK; |
| 448 } | 457 } |
| 449 | 458 |
| 450 } // namespace net | 459 } // namespace net |
| OLD | NEW |