| 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.h" | 5 #include "net/cert/cert_verify_proc.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "net/test/test_certificate_data.h" | 31 #include "net/test/test_certificate_data.h" |
| 32 #include "net/test/test_data_directory.h" | 32 #include "net/test/test_data_directory.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 35 |
| 36 #if defined(OS_ANDROID) | 36 #if defined(OS_ANDROID) |
| 37 #include "base/android/build_info.h" | 37 #include "base/android/build_info.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 #if defined(OS_MACOSX) && !defined(OS_IOS) | 40 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 41 #include "base/mac/mac_util.h" |
| 41 #include "net/cert/test_keychain_search_list_mac.h" | 42 #include "net/cert/test_keychain_search_list_mac.h" |
| 42 #endif | 43 #endif |
| 43 | 44 |
| 44 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
| 45 #include "base/win/windows_version.h" | 46 #include "base/win/windows_version.h" |
| 46 #endif | 47 #endif |
| 47 | 48 |
| 48 using net::test::IsError; | 49 using net::test::IsError; |
| 49 using net::test::IsOk; | 50 using net::test::IsOk; |
| 50 | 51 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // the verified certificate chain and detect known roots. | 116 // the verified certificate chain and detect known roots. |
| 116 if (base::android::BuildInfo::GetInstance()->sdk_int() < 17) | 117 if (base::android::BuildInfo::GetInstance()->sdk_int() < 17) |
| 117 return false; | 118 return false; |
| 118 #elif defined(OS_IOS) | 119 #elif defined(OS_IOS) |
| 119 // iOS does not expose the APIs necessary to get the known system roots. | 120 // iOS does not expose the APIs necessary to get the known system roots. |
| 120 return false; | 121 return false; |
| 121 #endif | 122 #endif |
| 122 return true; | 123 return true; |
| 123 } | 124 } |
| 124 | 125 |
| 126 bool WeakKeysAreInvalid() { |
| 127 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 128 // Starting with Mac OS 10.12, certs with weak keys are treated as |
| 129 // (recoverable) invalid certificate errors. |
| 130 return base::mac::IsAtLeastOS10_12(); |
| 131 #else |
| 132 return false; |
| 133 #endif |
| 134 } |
| 135 |
| 125 // Template helper to load a series of certificate files into a CertificateList. | 136 // Template helper to load a series of certificate files into a CertificateList. |
| 126 // Like CertTestUtil's CreateCertificateListFromFile, except it can load a | 137 // Like CertTestUtil's CreateCertificateListFromFile, except it can load a |
| 127 // series of individual certificates (to make the tests clearer). | 138 // series of individual certificates (to make the tests clearer). |
| 128 template <size_t N> | 139 template <size_t N> |
| 129 void LoadCertificateFiles(const char* const (&cert_files)[N], | 140 void LoadCertificateFiles(const char* const (&cert_files)[N], |
| 130 CertificateList* certs) { | 141 CertificateList* certs) { |
| 131 certs->clear(); | 142 certs->clear(); |
| 132 for (size_t i = 0; i < N; ++i) { | 143 for (size_t i = 0; i < N; ++i) { |
| 133 SCOPED_TRACE(cert_files[i]); | 144 SCOPED_TRACE(cert_files[i]); |
| 134 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( | 145 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 "127.0.0.1", | 411 "127.0.0.1", |
| 401 0, | 412 0, |
| 402 NULL, | 413 NULL, |
| 403 empty_cert_list_, | 414 empty_cert_list_, |
| 404 &verify_result); | 415 &verify_result); |
| 405 | 416 |
| 406 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { | 417 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { |
| 407 EXPECT_NE(OK, error); | 418 EXPECT_NE(OK, error); |
| 408 EXPECT_EQ(CERT_STATUS_WEAK_KEY, | 419 EXPECT_EQ(CERT_STATUS_WEAK_KEY, |
| 409 verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 420 verify_result.cert_status & CERT_STATUS_WEAK_KEY); |
| 410 EXPECT_NE(CERT_STATUS_INVALID, | 421 EXPECT_EQ(WeakKeysAreInvalid() ? CERT_STATUS_INVALID : 0, |
| 411 verify_result.cert_status & CERT_STATUS_INVALID); | 422 verify_result.cert_status & CERT_STATUS_INVALID); |
| 412 } else { | 423 } else { |
| 413 EXPECT_THAT(error, IsOk()); | 424 EXPECT_THAT(error, IsOk()); |
| 414 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 425 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); |
| 415 } | 426 } |
| 416 } | 427 } |
| 417 } | 428 } |
| 418 } | 429 } |
| 419 | 430 |
| 420 // Regression test for http://crbug.com/108514. | 431 // Regression test for http://crbug.com/108514. |
| (...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2065 int flags = 0; | 2076 int flags = 0; |
| 2066 CertVerifyResult verify_result; | 2077 CertVerifyResult verify_result; |
| 2067 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 2078 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, |
| 2068 &verify_result); | 2079 &verify_result); |
| 2069 EXPECT_EQ(OK, error); | 2080 EXPECT_EQ(OK, error); |
| 2070 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2081 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); |
| 2071 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2082 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); |
| 2072 } | 2083 } |
| 2073 | 2084 |
| 2074 } // namespace net | 2085 } // namespace net |
| OLD | NEW |