Chromium Code Reviews| 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/cert_verify_proc_openssl.h" | 5 #include "net/cert/cert_verify_proc_openssl.h" |
| 6 | 6 |
| 7 #include <openssl/x509v3.h> | 7 #include <openssl/x509v3.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/sha1.h" | 13 #include "base/sha1.h" |
| 14 #include "crypto/openssl_util.h" | 14 #include "crypto/openssl_util.h" |
| 15 #include "crypto/scoped_openssl_types.h" | |
| 16 #include "crypto/sha2.h" | 15 #include "crypto/sha2.h" |
| 17 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 18 #include "net/cert/asn1_util.h" | 17 #include "net/cert/asn1_util.h" |
| 19 #include "net/cert/cert_status_flags.h" | 18 #include "net/cert/cert_status_flags.h" |
| 20 #include "net/cert/cert_verifier.h" | 19 #include "net/cert/cert_verifier.h" |
| 21 #include "net/cert/cert_verify_result.h" | 20 #include "net/cert/cert_verify_result.h" |
| 22 #include "net/cert/test_root_certs.h" | 21 #include "net/cert/test_root_certs.h" |
| 23 #include "net/cert/x509_certificate.h" | 22 #include "net/cert/x509_certificate.h" |
| 24 | 23 |
| 25 namespace net { | 24 namespace net { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 case X509_V_ERR_NO_EXPLICIT_POLICY: | 82 case X509_V_ERR_NO_EXPLICIT_POLICY: |
| 84 case X509_V_ERR_UNNESTED_RESOURCE: | 83 case X509_V_ERR_UNNESTED_RESOURCE: |
| 85 case X509_V_ERR_APPLICATION_VERIFICATION: | 84 case X509_V_ERR_APPLICATION_VERIFICATION: |
| 86 return CERT_STATUS_INVALID; | 85 return CERT_STATUS_INVALID; |
| 87 default: | 86 default: |
| 88 NOTREACHED() << "Invalid X509 err " << err; | 87 NOTREACHED() << "Invalid X509 err " << err; |
| 89 return CERT_STATUS_INVALID; | 88 return CERT_STATUS_INVALID; |
| 90 } | 89 } |
| 91 } | 90 } |
| 92 | 91 |
| 93 // sk_X509_free is a function-style macro, so can't be used as a template | 92 struct ShallowX509Stack { |
|
eroman
2016/10/10 22:45:54
Can you add "Deleter" in the name?
davidben
2016/10/10 23:24:40
Done.
PS: I'm pretty sure nothing builds this fil
| |
| 94 // param directly. | 93 void operator()(STACK_OF(X509) * st) const { sk_X509_free(st); } |
| 95 void sk_X509_free_fn(STACK_OF(X509)* st) { | 94 }; |
| 96 sk_X509_free(st); | |
| 97 } | |
| 98 | 95 |
| 99 void GetCertChainInfo(X509_STORE_CTX* store_ctx, | 96 void GetCertChainInfo(X509_STORE_CTX* store_ctx, |
| 100 CertVerifyResult* verify_result) { | 97 CertVerifyResult* verify_result) { |
| 101 STACK_OF(X509)* chain = X509_STORE_CTX_get_chain(store_ctx); | 98 STACK_OF(X509)* chain = X509_STORE_CTX_get_chain(store_ctx); |
| 102 X509* verified_cert = NULL; | 99 X509* verified_cert = NULL; |
| 103 std::vector<X509*> verified_chain; | 100 std::vector<X509*> verified_chain; |
| 104 for (size_t i = 0; i < sk_X509_num(chain); ++i) { | 101 for (size_t i = 0; i < sk_X509_num(chain); ++i) { |
| 105 X509* cert = sk_X509_value(chain, i); | 102 X509* cert = sk_X509_value(chain, i); |
| 106 if (i == 0) { | 103 if (i == 0) { |
| 107 verified_cert = cert; | 104 verified_cert = cert; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 CRLSet* crl_set, | 201 CRLSet* crl_set, |
| 205 const CertificateList& additional_trust_anchors, | 202 const CertificateList& additional_trust_anchors, |
| 206 CertVerifyResult* verify_result) { | 203 CertVerifyResult* verify_result) { |
| 207 crypto::EnsureOpenSSLInit(); | 204 crypto::EnsureOpenSSLInit(); |
| 208 | 205 |
| 209 if (!cert->VerifyNameMatch(hostname, | 206 if (!cert->VerifyNameMatch(hostname, |
| 210 &verify_result->common_name_fallback_used)) { | 207 &verify_result->common_name_fallback_used)) { |
| 211 verify_result->cert_status |= CERT_STATUS_COMMON_NAME_INVALID; | 208 verify_result->cert_status |= CERT_STATUS_COMMON_NAME_INVALID; |
| 212 } | 209 } |
| 213 | 210 |
| 214 crypto::ScopedOpenSSL<X509_STORE_CTX, X509_STORE_CTX_free> ctx( | 211 bssl::UniquePtr<X509_STORE_CTX> ctx(X509_STORE_CTX_new()); |
| 215 X509_STORE_CTX_new()); | |
| 216 | 212 |
| 217 crypto::ScopedOpenSSL<STACK_OF(X509), sk_X509_free_fn> intermediates( | 213 std::unique_ptr<STACK_OF(X509), ShallowX509Stack> intermediates( |
| 218 sk_X509_new_null()); | 214 sk_X509_new_null()); |
| 219 if (!intermediates.get()) | 215 if (!intermediates.get()) |
| 220 return ERR_OUT_OF_MEMORY; | 216 return ERR_OUT_OF_MEMORY; |
| 221 | 217 |
| 222 const X509Certificate::OSCertHandles& os_intermediates = | 218 const X509Certificate::OSCertHandles& os_intermediates = |
| 223 cert->GetIntermediateCertificates(); | 219 cert->GetIntermediateCertificates(); |
| 224 for (X509Certificate::OSCertHandles::const_iterator it = | 220 for (X509Certificate::OSCertHandles::const_iterator it = |
| 225 os_intermediates.begin(); it != os_intermediates.end(); ++it) { | 221 os_intermediates.begin(); it != os_intermediates.end(); ++it) { |
| 226 if (!sk_X509_push(intermediates.get(), *it)) | 222 if (!sk_X509_push(intermediates.get(), *it)) |
| 227 return ERR_OUT_OF_MEMORY; | 223 return ERR_OUT_OF_MEMORY; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 245 | 241 |
| 246 GetCertChainInfo(ctx.get(), verify_result); | 242 GetCertChainInfo(ctx.get(), verify_result); |
| 247 AppendPublicKeyHashes(ctx.get(), &verify_result->public_key_hashes); | 243 AppendPublicKeyHashes(ctx.get(), &verify_result->public_key_hashes); |
| 248 if (IsCertStatusError(verify_result->cert_status)) | 244 if (IsCertStatusError(verify_result->cert_status)) |
| 249 return MapCertStatusToNetError(verify_result->cert_status); | 245 return MapCertStatusToNetError(verify_result->cert_status); |
| 250 | 246 |
| 251 return OK; | 247 return OK; |
| 252 } | 248 } |
| 253 | 249 |
| 254 } // namespace net | 250 } // namespace net |
| OLD | NEW |