| 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 <openssl/asn1.h> | 7 #include <openssl/asn1.h> |
| 8 #include <openssl/bytestring.h> | 8 #include <openssl/bytestring.h> |
| 9 #include <openssl/crypto.h> | 9 #include <openssl/crypto.h> |
| 10 #include <openssl/obj_mac.h> | 10 #include <openssl/obj_mac.h> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
| 29 #include "base/logging.h" | 29 #include "base/logging.h" |
| 30 #include "net/android/network_library.h" | 30 #include "net/android/network_library.h" |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 namespace net { | 33 namespace net { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 typedef crypto::ScopedOpenSSL<GENERAL_NAMES, GENERAL_NAMES_free>::Type | 37 using ScopedGENERAL_NAMES = |
| 38 ScopedGENERAL_NAMES; | 38 crypto::ScopedOpenSSL<GENERAL_NAMES, GENERAL_NAMES_free>; |
| 39 | 39 |
| 40 void CreateOSCertHandlesFromPKCS7Bytes( | 40 void CreateOSCertHandlesFromPKCS7Bytes( |
| 41 const char* data, int length, | 41 const char* data, int length, |
| 42 X509Certificate::OSCertHandles* handles) { | 42 X509Certificate::OSCertHandles* handles) { |
| 43 crypto::EnsureOpenSSLInit(); | 43 crypto::EnsureOpenSSLInit(); |
| 44 crypto::OpenSSLErrStackTracer err_cleaner(FROM_HERE); | 44 crypto::OpenSSLErrStackTracer err_cleaner(FROM_HERE); |
| 45 | 45 |
| 46 CBS der_data; | 46 CBS der_data; |
| 47 CBS_init(&der_data, reinterpret_cast<const uint8_t*>(data), length); | 47 CBS_init(&der_data, reinterpret_cast<const uint8_t*>(data), length); |
| 48 STACK_OF(X509)* certs = sk_X509_new_null(); | 48 STACK_OF(X509)* certs = sk_X509_new_null(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // TODO(joth): Enable CRL (see X509_STORE_set_flags(X509_V_FLAG_CRL_CHECK)). | 154 // TODO(joth): Enable CRL (see X509_STORE_set_flags(X509_V_FLAG_CRL_CHECK)). |
| 155 } | 155 } |
| 156 | 156 |
| 157 private: | 157 private: |
| 158 friend struct DefaultSingletonTraits<X509InitSingleton>; | 158 friend struct DefaultSingletonTraits<X509InitSingleton>; |
| 159 X509InitSingleton() { | 159 X509InitSingleton() { |
| 160 crypto::EnsureOpenSSLInit(); | 160 crypto::EnsureOpenSSLInit(); |
| 161 ResetCertStore(); | 161 ResetCertStore(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 crypto::ScopedOpenSSL<X509_STORE, X509_STORE_free>::Type store_; | 164 crypto::ScopedOpenSSL<X509_STORE, X509_STORE_free> store_; |
| 165 | 165 |
| 166 DISALLOW_COPY_AND_ASSIGN(X509InitSingleton); | 166 DISALLOW_COPY_AND_ASSIGN(X509InitSingleton); |
| 167 }; | 167 }; |
| 168 | 168 |
| 169 // Used to free a list of X509_NAMEs and the objects it points to. | 169 // Used to free a list of X509_NAMEs and the objects it points to. |
| 170 void sk_X509_NAME_free_all(STACK_OF(X509_NAME)* sk) { | 170 void sk_X509_NAME_free_all(STACK_OF(X509_NAME)* sk) { |
| 171 sk_X509_NAME_pop_free(sk, X509_NAME_free); | 171 sk_X509_NAME_pop_free(sk, X509_NAME_free); |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace | 174 } // namespace |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 397 } |
| 398 } | 398 } |
| 399 | 399 |
| 400 bool X509Certificate::IsIssuedByEncoded( | 400 bool X509Certificate::IsIssuedByEncoded( |
| 401 const std::vector<std::string>& valid_issuers) { | 401 const std::vector<std::string>& valid_issuers) { |
| 402 if (valid_issuers.empty()) | 402 if (valid_issuers.empty()) |
| 403 return false; | 403 return false; |
| 404 | 404 |
| 405 // Convert to a temporary list of X509_NAME objects. | 405 // Convert to a temporary list of X509_NAME objects. |
| 406 // It will own the objects it points to. | 406 // It will own the objects it points to. |
| 407 crypto::ScopedOpenSSL<STACK_OF(X509_NAME), sk_X509_NAME_free_all>::Type | 407 crypto::ScopedOpenSSL<STACK_OF(X509_NAME), sk_X509_NAME_free_all> |
| 408 issuer_names(sk_X509_NAME_new_null()); | 408 issuer_names(sk_X509_NAME_new_null()); |
| 409 if (!issuer_names.get()) | 409 if (!issuer_names.get()) |
| 410 return false; | 410 return false; |
| 411 | 411 |
| 412 for (std::vector<std::string>::const_iterator it = valid_issuers.begin(); | 412 for (std::vector<std::string>::const_iterator it = valid_issuers.begin(); |
| 413 it != valid_issuers.end(); ++it) { | 413 it != valid_issuers.end(); ++it) { |
| 414 const unsigned char* p = | 414 const unsigned char* p = |
| 415 reinterpret_cast<const unsigned char*>(it->data()); | 415 reinterpret_cast<const unsigned char*>(it->data()); |
| 416 long len = static_cast<long>(it->length()); | 416 long len = static_cast<long>(it->length()); |
| 417 X509_NAME* ca_name = d2i_X509_NAME(NULL, &p, len); | 417 X509_NAME* ca_name = d2i_X509_NAME(NULL, &p, len); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 bool X509Certificate::IsSelfSigned(OSCertHandle cert_handle) { | 453 bool X509Certificate::IsSelfSigned(OSCertHandle cert_handle) { |
| 454 crypto::ScopedEVP_PKEY scoped_key(X509_get_pubkey(cert_handle)); | 454 crypto::ScopedEVP_PKEY scoped_key(X509_get_pubkey(cert_handle)); |
| 455 if (!scoped_key) | 455 if (!scoped_key) |
| 456 return false; | 456 return false; |
| 457 | 457 |
| 458 // NOTE: X509_verify() returns 1 in case of success, 0 or -1 on error. | 458 // NOTE: X509_verify() returns 1 in case of success, 0 or -1 on error. |
| 459 return X509_verify(cert_handle, scoped_key.get()) == 1; | 459 return X509_verify(cert_handle, scoped_key.get()) == 1; |
| 460 } | 460 } |
| 461 | 461 |
| 462 } // namespace net | 462 } // namespace net |
| OLD | NEW |