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.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 15 matching lines...) Expand all Loading... | |
| 26 #include "net/cert/crl_set_storage.h" | 26 #include "net/cert/crl_set_storage.h" | 
| 27 #include "net/cert/test_root_certs.h" | 27 #include "net/cert/test_root_certs.h" | 
| 28 #include "net/cert/x509_certificate.h" | 28 #include "net/cert/x509_certificate.h" | 
| 29 #include "net/test/cert_test_util.h" | 29 #include "net/test/cert_test_util.h" | 
| 30 #include "net/test/gtest_util.h" | 30 #include "net/test/gtest_util.h" | 
| 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(USE_NSS_CERTS) | 
| 37 #include "net/cert/cert_verify_proc_nss.h" | |
| 38 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | |
| 39 #include "net/cert/cert_verify_proc_openssl.h" | |
| 40 #elif defined(OS_ANDROID) | |
| 37 #include "base/android/build_info.h" | 41 #include "base/android/build_info.h" | 
| 38 #endif | 42 #include "net/cert/cert_verify_proc_android.h" | 
| 39 | 43 #elif defined(OS_IOS) | 
| 40 #if defined(OS_MACOSX) && !defined(OS_IOS) | 44 #include "net/cert/cert_verify_proc_ios.h" | 
| 45 #elif defined(OS_MACOSX) | |
| 41 #include "base/mac/mac_util.h" | 46 #include "base/mac/mac_util.h" | 
| 47 #include "net/cert/cert_verify_proc_mac.h" | |
| 42 #include "net/cert/test_keychain_search_list_mac.h" | 48 #include "net/cert/test_keychain_search_list_mac.h" | 
| 43 #endif | 49 #elif defined(OS_WIN) | 
| 44 | |
| 45 #if defined(OS_WIN) | |
| 46 #include "base/win/windows_version.h" | 50 #include "base/win/windows_version.h" | 
| 51 #include "net/cert/cert_verify_proc_win.h" | |
| 52 #else | |
| 53 #error Implement certificate verification. | |
| 47 #endif | 54 #endif | 
| 48 | 55 | 
| 49 using net::test::IsError; | 56 using net::test::IsError; | 
| 50 using net::test::IsOk; | 57 using net::test::IsOk; | 
| 51 | 58 | 
| 52 using base::HexEncode; | 59 using base::HexEncode; | 
| 53 | 60 | 
| 54 namespace net { | 61 namespace net { | 
| 55 | 62 | 
| 56 namespace { | 63 namespace { | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 const std::string& ocsp_response, | 100 const std::string& ocsp_response, | 
| 94 int flags, | 101 int flags, | 
| 95 CRLSet* crl_set, | 102 CRLSet* crl_set, | 
| 96 const CertificateList& additional_trust_anchors, | 103 const CertificateList& additional_trust_anchors, | 
| 97 CertVerifyResult* verify_result) { | 104 CertVerifyResult* verify_result) { | 
| 98 *verify_result = result_; | 105 *verify_result = result_; | 
| 99 verify_result->verified_cert = cert; | 106 verify_result->verified_cert = cert; | 
| 100 return OK; | 107 return OK; | 
| 101 } | 108 } | 
| 102 | 109 | 
| 103 bool SupportsReturningVerifiedChain() { | 110 template <typename T> | 
| 104 #if defined(OS_ANDROID) | 111 bool IsCertVerifyProcNSS(T* verify_proc) { | 
| 105 // Before API level 17, Android does not expose the APIs necessary to get at | 112 return false; | 
| 106 // the verified certificate chain. | 113 } | 
| 
 
Ryan Sleevi
2017/01/14 01:50:28
As mentioned in the other review, the naming here
 
 | |
| 107 if (base::android::BuildInfo::GetInstance()->sdk_int() < 17) | 114 | 
| 108 return false; | 115 #if defined(USE_NSS_CERTS) | 
| 109 #endif | 116 template <> | 
| 117 bool IsCertVerifyProcNSS(CertVerifyProcNSS* verify_proc) { | |
| 110 return true; | 118 return true; | 
| 111 } | 119 } | 
| 120 #endif | |
| 112 | 121 | 
| 113 bool SupportsDetectingKnownRoots() { | 122 template <typename T> | 
| 114 #if defined(OS_ANDROID) | 123 bool IsCertVerifyProcOpenSSL(T* verify_proc) { | 
| 115 // Before API level 17, Android does not expose the APIs necessary to get at | |
| 116 // the verified certificate chain and detect known roots. | |
| 117 if (base::android::BuildInfo::GetInstance()->sdk_int() < 17) | |
| 118 return false; | |
| 119 #elif defined(OS_IOS) | |
| 120 // iOS does not expose the APIs necessary to get the known system roots. | |
| 121 return false; | 124 return false; | 
| 122 #endif | 125 } | 
| 126 | |
| 127 #if defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | |
| 128 template <> | |
| 129 bool IsCertVerifyProcOpenSSL(CertVerifyProcOpenSSL* verify_proc) { | |
| 123 return true; | 130 return true; | 
| 124 } | 131 } | 
| 132 #endif | |
| 125 | 133 | 
| 126 bool WeakKeysAreInvalid() { | 134 template <typename T> | 
| 135 bool IsCertVerifyProcAndroid(T* verify_proc) { | |
| 136 return false; | |
| 137 } | |
| 138 | |
| 139 #if defined(OS_ANDROID) | |
| 140 template <> | |
| 141 bool IsCertVerifyProcAndroid(CertVerifyProcAndroid* verify_proc) { | |
| 142 return true; | |
| 143 } | |
| 144 #endif | |
| 145 | |
| 146 template <typename T> | |
| 147 bool IsCertVerifyProcMac(T* verify_proc) { | |
| 148 return false; | |
| 149 } | |
| 150 | |
| 127 #if defined(OS_MACOSX) && !defined(OS_IOS) | 151 #if defined(OS_MACOSX) && !defined(OS_IOS) | 
| 128 // Starting with Mac OS 10.12, certs with weak keys are treated as | 152 template <> | 
| 129 // (recoverable) invalid certificate errors. | 153 bool IsCertVerifyProcMac(CertVerifyProcMac* verify_proc) { | 
| 130 return base::mac::IsAtLeastOS10_12(); | 154 return true; | 
| 155 } | |
| 156 #endif | |
| 157 | |
| 158 template <typename T> | |
| 159 bool IsCertVerifyProcIOS(T* verify_proc) { | |
| 160 return false; | |
| 161 } | |
| 162 | |
| 163 #if defined(OS_IOS) | |
| 164 template <> | |
| 165 bool IsCertVerifyProcIOS(CertVerifyProcIOS* verify_proc) { | |
| 166 return true; | |
| 167 } | |
| 168 #endif | |
| 169 | |
| 170 template <typename T> | |
| 171 bool IsCertVerifyProcWin(T* verify_proc) { | |
| 172 return false; | |
| 173 } | |
| 174 | |
| 175 #if defined(OS_WIN) | |
| 176 template <> | |
| 177 bool IsCertVerifyProcWin(CertVerifyProcWin* verify_proc) { | |
| 178 return true; | |
| 179 } | |
| 180 #endif | |
| 181 | |
| 182 bool TargetIsIphoneSimulator() { | |
| 183 #if TARGET_IPHONE_SIMULATOR | |
| 184 return true; | |
| 131 #else | 185 #else | 
| 132 return false; | 186 return false; | 
| 133 #endif | 187 #endif | 
| 134 } | 188 } | 
| 135 | 189 | 
| 190 template <typename T> | |
| 191 bool SupportsReturningVerifiedChain(T* verify_proc) { | |
| 192 return true; | |
| 193 } | |
| 194 | |
| 195 #if defined(OS_ANDROID) | |
| 196 template <> | |
| 197 bool SupportsReturningVerifiedChain(CertVerifyProcAndroid* verify_proc) { | |
| 198 // Before API level 17, Android does not expose the APIs necessary to get at | |
| 199 // the verified certificate chain. | |
| 200 return base::android::BuildInfo::GetInstance()->sdk_int() >= 17; | |
| 201 } | |
| 202 #endif | |
| 203 | |
| 204 template <typename T> | |
| 205 bool SupportsDetectingKnownRoots(T* verify_proc) { | |
| 206 return true; | |
| 207 } | |
| 208 | |
| 209 #if defined(OS_ANDROID) | |
| 210 template <> | |
| 211 bool SupportsDetectingKnownRoots(CertVerifyProcAndroid* verify_proc) { | |
| 212 // Before API level 17, Android does not expose the APIs necessary to get at | |
| 213 // the verified certificate chain and detect known roots. | |
| 214 return base::android::BuildInfo::GetInstance()->sdk_int() >= 17; | |
| 215 } | |
| 216 #endif | |
| 217 | |
| 218 #if defined(OS_IOS) | |
| 219 // iOS does not expose the APIs necessary to get the known system roots. | |
| 220 template <> | |
| 221 bool SupportsDetectingKnownRoots(CertVerifyProcIOS* verify_proc) { | |
| 222 return false; | |
| 223 } | |
| 224 #endif | |
| 225 | |
| 226 template <typename T> | |
| 227 bool WeakKeysAreInvalid(T* verify_proc) { | |
| 228 return false; | |
| 229 } | |
| 230 | |
| 231 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
| 232 template <> | |
| 233 bool WeakKeysAreInvalid(CertVerifyProcMac* verify_proc) { | |
| 234 // Starting with Mac OS 10.12, certs with weak keys are treated as | |
| 235 // (recoverable) invalid certificate errors. | |
| 236 return base::mac::IsAtLeastOS10_12(); | |
| 237 } | |
| 238 #endif | |
| 239 | |
| 136 // Template helper to load a series of certificate files into a CertificateList. | 240 // Template helper to load a series of certificate files into a CertificateList. | 
| 137 // Like CertTestUtil's CreateCertificateListFromFile, except it can load a | 241 // Like CertTestUtil's CreateCertificateListFromFile, except it can load a | 
| 138 // series of individual certificates (to make the tests clearer). | 242 // series of individual certificates (to make the tests clearer). | 
| 139 template <size_t N> | 243 template <size_t N> | 
| 140 void LoadCertificateFiles(const char* const (&cert_files)[N], | 244 void LoadCertificateFiles(const char* const (&cert_files)[N], | 
| 141 CertificateList* certs) { | 245 CertificateList* certs) { | 
| 142 certs->clear(); | 246 certs->clear(); | 
| 143 for (size_t i = 0; i < N; ++i) { | 247 for (size_t i = 0; i < N; ++i) { | 
| 144 SCOPED_TRACE(cert_files[i]); | 248 SCOPED_TRACE(cert_files[i]); | 
| 145 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( | 249 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( | 
| 146 GetTestCertsDirectory(), cert_files[i], X509Certificate::FORMAT_AUTO); | 250 GetTestCertsDirectory(), cert_files[i], X509Certificate::FORMAT_AUTO); | 
| 147 ASSERT_TRUE(cert); | 251 ASSERT_TRUE(cert); | 
| 148 certs->push_back(cert); | 252 certs->push_back(cert); | 
| 149 } | 253 } | 
| 150 } | 254 } | 
| 151 | 255 | 
| 256 template <typename T> | |
| 257 bool SupportsCRLSetsInPathBuilding(T* verify_proc) { | |
| 258 return false; | |
| 259 } | |
| 260 | |
| 261 #if defined(OS_WIN) | |
| 262 template <> | |
| 263 bool SupportsCRLSetsInPathBuilding(CertVerifyProcWin* verify_proc) { | |
| 264 return true; | |
| 265 } | |
| 266 #endif | |
| 267 | |
| 268 #if defined(USE_NSS_CERTS) | |
| 269 template <> | |
| 270 bool SupportsCRLSetsInPathBuilding(CertVerifyProcNSS* verify_proc) { | |
| 271 return true; | |
| 272 } | |
| 273 #endif | |
| 274 | |
| 275 const CertificateList& EmptyCertList() { | |
| 276 static CertificateList empty; | |
| 277 return empty; | |
| 278 } | |
| 279 | |
| 152 } // namespace | 280 } // namespace | 
| 153 | 281 | 
| 154 class CertVerifyProcTest : public testing::Test { | 282 // Fixture for tests that don't test a concrete CertVerifyProc implementation, | 
| 155 public: | 283 // but rather test methods of the base class CertVerifyProc. | 
| 156 CertVerifyProcTest() | 284 // | 
| 157 : verify_proc_(CertVerifyProc::CreateDefault()) { | 285 // Mainly its own fixture to have a central place to describe it. | 
| 286 class CertVerifyProcBaseClassTest : public testing::Test {}; | |
| 287 | |
| 288 // Fixture for tests that are to be run for each of the concrete CertVerifyProc | |
| 289 // subclasses. | |
| 290 template <typename VerifyProcType> | |
| 291 class CertVerifyProcTypedTest : public testing::Test { | |
| 292 protected: | |
| 293 void SetUp() override { | |
| 294 verify_proc_ = make_scoped_refptr(new VerifyProcType()); | |
| 158 } | 295 } | 
| 159 ~CertVerifyProcTest() override {} | |
| 160 | 296 | 
| 161 protected: | |
| 162 bool SupportsAdditionalTrustAnchors() { | 297 bool SupportsAdditionalTrustAnchors() { | 
| 163 return verify_proc_->SupportsAdditionalTrustAnchors(); | 298 return verify_proc_->SupportsAdditionalTrustAnchors(); | 
| 164 } | 299 } | 
| 165 | 300 | 
| 166 // Returns true if the underlying CertVerifyProc supports integrating CRLSets | |
| 167 // into path building logic, such as allowing the selection of alternatively | |
| 168 // valid paths when one or more are revoked. As the goal is to integrate this | |
| 169 // into all platforms, this is a temporary, test-only flag to centralize the | |
| 170 // conditionals in tests. | |
| 171 bool SupportsCRLSetsInPathBuilding() { | |
| 172 #if defined(OS_WIN) || defined(USE_NSS_CERTS) | |
| 173 return true; | |
| 174 #else | |
| 175 return false; | |
| 176 #endif | |
| 177 } | |
| 178 | |
| 179 int Verify(X509Certificate* cert, | 301 int Verify(X509Certificate* cert, | 
| 180 const std::string& hostname, | 302 const std::string& hostname, | 
| 181 int flags, | 303 int flags, | 
| 182 CRLSet* crl_set, | 304 CRLSet* crl_set, | 
| 183 const CertificateList& additional_trust_anchors, | 305 const CertificateList& additional_trust_anchors, | 
| 184 CertVerifyResult* verify_result) { | 306 CertVerifyResult* verify_result) { | 
| 185 return verify_proc_->Verify(cert, hostname, std::string(), flags, crl_set, | 307 return verify_proc_->Verify(cert, hostname, std::string(), flags, crl_set, | 
| 186 additional_trust_anchors, verify_result); | 308 additional_trust_anchors, verify_result); | 
| 187 } | 309 } | 
| 188 | 310 | 
| 189 int VerifyWithOCSPResponse(X509Certificate* cert, | 311 bool UsingCertVerifyProcAndroid() const { | 
| 190 const std::string& hostname, | 312 return IsCertVerifyProcAndroid(verify_proc_.get()); | 
| 191 const std::string& ocsp_response, | |
| 192 int flags, | |
| 193 CRLSet* crl_set, | |
| 194 const CertificateList& additional_trust_anchors, | |
| 195 CertVerifyResult* verify_result) { | |
| 196 return verify_proc_->Verify(cert, hostname, ocsp_response, flags, crl_set, | |
| 197 additional_trust_anchors, verify_result); | |
| 198 } | 313 } | 
| 199 | 314 | 
| 200 const CertificateList empty_cert_list_; | 315 bool UsingCertVerifyProcNSS() const { | 
| 201 scoped_refptr<CertVerifyProc> verify_proc_; | 316 return IsCertVerifyProcNSS(verify_proc_.get()); | 
| 317 } | |
| 318 | |
| 319 bool UsingCertVerifyProcOpenSSL() const { | |
| 320 return IsCertVerifyProcOpenSSL(verify_proc_.get()); | |
| 321 } | |
| 322 | |
| 323 bool UsingCertVerifyProcIOS() const { | |
| 324 return IsCertVerifyProcIOS(verify_proc_.get()); | |
| 325 } | |
| 326 | |
| 327 bool UsingCertVerifyProcWin() const { | |
| 328 return IsCertVerifyProcWin(verify_proc_.get()); | |
| 329 } | |
| 330 | |
| 331 bool UsingCertVerifyProcMac() const { | |
| 332 return IsCertVerifyProcMac(verify_proc_.get()); | |
| 333 } | |
| 334 | |
| 335 void VerifyCertName(const char* hostname, bool valid) { | |
| 336 CertificateList cert_list = CreateCertificateListFromFile( | |
| 337 GetTestCertsDirectory(), "subjectAltName_sanity_check.pem", | |
| 338 X509Certificate::FORMAT_AUTO); | |
| 339 ASSERT_EQ(1U, cert_list.size()); | |
| 340 scoped_refptr<X509Certificate> cert(cert_list[0]); | |
| 341 | |
| 342 ScopedTestRoot scoped_root(cert.get()); | |
| 343 | |
| 344 CertVerifyResult verify_result; | |
| 345 int error = | |
| 346 Verify(cert.get(), hostname, 0, NULL, EmptyCertList(), &verify_result); | |
| 347 if (valid) { | |
| 348 EXPECT_THAT(error, IsOk()); | |
| 349 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); | |
| 350 } else { | |
| 351 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); | |
| 352 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); | |
| 353 } | |
| 354 } | |
| 355 | |
| 356 scoped_refptr<VerifyProcType> verify_proc_; | |
| 202 }; | 357 }; | 
| 203 | 358 | 
| 204 #if defined(OS_ANDROID) || defined(USE_OPENSSL_CERTS) | 359 // InstantiateCertVerifyProcTypedTest with the supported concrete type(s) | 
| 205 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. | 360 // for the current platform. | 
| 206 #define MAYBE_EVVerification DISABLED_EVVerification | 361 #if defined(USE_NSS_CERTS) | 
| 362 typedef ::testing::Types<CertVerifyProcNSS> CertVerifyProcTypes; | |
| 363 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | |
| 364 typedef ::testing::Types<CertVerifyProcOpenSSL> CertVerifyProcTypes; | |
| 365 #elif defined(OS_ANDROID) | |
| 366 typedef ::testing::Types<CertVerifyProcAndroid> CertVerifyProcTypes; | |
| 367 #elif defined(OS_IOS) | |
| 368 typedef ::testing::Types<CertVerifyProcIOS> CertVerifyProcTypes; | |
| 369 #elif defined(OS_MACOSX) | |
| 370 typedef ::testing::Types<CertVerifyProcMac> CertVerifyProcTypes; | |
| 371 #elif defined(OS_WIN) | |
| 372 typedef ::testing::Types<CertVerifyProcWin> CertVerifyProcTypes; | |
| 207 #else | 373 #else | 
| 374 #error Implement certificate verification. | |
| 375 #endif | |
| 376 TYPED_TEST_CASE(CertVerifyProcTypedTest, CertVerifyProcTypes); | |
| 377 | |
| 208 // TODO(rsleevi): Reenable this test once comodo.chaim.pem is no longer | 378 // TODO(rsleevi): Reenable this test once comodo.chaim.pem is no longer | 
| 209 // expired, http://crbug.com/502818 | 379 // expired, http://crbug.com/502818 | 
| 210 #define MAYBE_EVVerification DISABLED_EVVerification | 380 TYPED_TEST(CertVerifyProcTypedTest, DISABLED_EVVerification) { | 
| 211 #endif | 381 if (this->UsingCertVerifyProcAndroid() || | 
| 212 TEST_F(CertVerifyProcTest, MAYBE_EVVerification) { | 382 this->UsingCertVerifyProcOpenSSL()) { | 
| 213 CertificateList certs = CreateCertificateListFromFile( | 383 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet | 
| 214 GetTestCertsDirectory(), | 384 // supported. | 
| 215 "comodo.chain.pem", | 385 LOG(INFO) << "Skipping test as EV verification is not yet supported"; | 
| 216 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | 386 return; | 
| 387 } | |
| 388 | |
| 389 CertificateList certs = | |
| 390 CreateCertificateListFromFile(GetTestCertsDirectory(), "comodo.chain.pem", | |
| 391 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | |
| 217 ASSERT_EQ(3U, certs.size()); | 392 ASSERT_EQ(3U, certs.size()); | 
| 218 | 393 | 
| 219 X509Certificate::OSCertHandles intermediates; | 394 X509Certificate::OSCertHandles intermediates; | 
| 220 intermediates.push_back(certs[1]->os_cert_handle()); | 395 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 221 intermediates.push_back(certs[2]->os_cert_handle()); | 396 intermediates.push_back(certs[2]->os_cert_handle()); | 
| 222 | 397 | 
| 223 scoped_refptr<X509Certificate> comodo_chain = | 398 scoped_refptr<X509Certificate> comodo_chain = | 
| 224 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 399 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 
| 225 intermediates); | 400 intermediates); | 
| 226 | 401 | 
| 227 scoped_refptr<CRLSet> crl_set(CRLSet::ForTesting(false, NULL, "")); | 402 scoped_refptr<CRLSet> crl_set(CRLSet::ForTesting(false, NULL, "")); | 
| 228 CertVerifyResult verify_result; | 403 CertVerifyResult verify_result; | 
| 229 int flags = CertVerifier::VERIFY_EV_CERT; | 404 int flags = CertVerifier::VERIFY_EV_CERT; | 
| 230 int error = Verify(comodo_chain.get(), | 405 int error = this->Verify(comodo_chain.get(), "comodo.com", flags, | 
| 231 "comodo.com", | 406 crl_set.get(), EmptyCertList(), &verify_result); | 
| 232 flags, | |
| 233 crl_set.get(), | |
| 234 empty_cert_list_, | |
| 235 &verify_result); | |
| 236 EXPECT_THAT(error, IsOk()); | 407 EXPECT_THAT(error, IsOk()); | 
| 237 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); | 408 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); | 
| 238 } | 409 } | 
| 239 | 410 | 
| 240 // TODO(crbug.com/605457): the test expectation was incorrect on some | 411 // TODO(crbug.com/605457): the test expectation was incorrect on some | 
| 241 // configurations, so disable the test until it is fixed (better to have | 412 // configurations, so disable the test until it is fixed (better to have | 
| 242 // a bug to track a failing test than a false sense of security due to | 413 // a bug to track a failing test than a false sense of security due to | 
| 243 // false positive). | 414 // false positive). | 
| 244 TEST_F(CertVerifyProcTest, DISABLED_PaypalNullCertParsing) { | 415 TYPED_TEST(CertVerifyProcTypedTest, DISABLED_PaypalNullCertParsing) { | 
| 245 // A certificate for www.paypal.com with a NULL byte in the common name. | 416 // A certificate for www.paypal.com with a NULL byte in the common name. | 
| 246 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363 | 417 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363 | 
| 247 SHA256HashValue paypal_null_fingerprint = {{0x00}}; | 418 SHA256HashValue paypal_null_fingerprint = {{0x00}}; | 
| 248 | 419 | 
| 249 scoped_refptr<X509Certificate> paypal_null_cert( | 420 scoped_refptr<X509Certificate> paypal_null_cert( | 
| 250 X509Certificate::CreateFromBytes( | 421 X509Certificate::CreateFromBytes( | 
| 251 reinterpret_cast<const char*>(paypal_null_der), | 422 reinterpret_cast<const char*>(paypal_null_der), | 
| 252 sizeof(paypal_null_der))); | 423 sizeof(paypal_null_der))); | 
| 253 | 424 | 
| 254 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert.get()); | 425 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert.get()); | 
| 255 | 426 | 
| 256 EXPECT_EQ(paypal_null_fingerprint, X509Certificate::CalculateFingerprint256( | 427 EXPECT_EQ(paypal_null_fingerprint, X509Certificate::CalculateFingerprint256( | 
| 257 paypal_null_cert->os_cert_handle())); | 428 paypal_null_cert->os_cert_handle())); | 
| 258 | 429 | 
| 259 int flags = 0; | 430 int flags = 0; | 
| 260 CertVerifyResult verify_result; | 431 CertVerifyResult verify_result; | 
| 261 int error = Verify(paypal_null_cert.get(), | 432 int error = this->Verify(paypal_null_cert.get(), "www.paypal.com", flags, | 
| 262 "www.paypal.com", | 433 NULL, EmptyCertList(), &verify_result); | 
| 263 flags, | 434 | 
| 264 NULL, | 435 if (this->UsingCertVerifyProcNSS() || this->UsingCertVerifyProcAndroid()) { | 
| 265 empty_cert_list_, | 436 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); | 
| 266 &verify_result); | 437 } else if (this->UsingCertVerifyProcIOS() && TargetIsIphoneSimulator()) { | 
| 267 #if defined(USE_NSS_CERTS) || defined(OS_ANDROID) | 438 // iOS returns a ERR_CERT_INVALID error on the simulator, while returning | 
| 268 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); | 439 // ERR_CERT_AUTHORITY_INVALID on the real device. | 
| 269 #elif defined(OS_IOS) && TARGET_IPHONE_SIMULATOR | 440 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 
| 270 // iOS returns a ERR_CERT_INVALID error on the simulator, while returning | 441 } else { | 
| 271 // ERR_CERT_AUTHORITY_INVALID on the real device. | 442 // TOOD(bulach): investigate why macosx and win aren't returning | 
| 272 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 443 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. | 
| 273 #else | 444 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 
| 274 // TOOD(bulach): investigate why macosx and win aren't returning | 445 } | 
| 275 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. | 446 | 
| 276 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | |
| 277 #endif | |
| 278 // Either the system crypto library should correctly report a certificate | 447 // Either the system crypto library should correctly report a certificate | 
| 279 // name mismatch, or our certificate blacklist should cause us to report an | 448 // name mismatch, or our certificate blacklist should cause us to report an | 
| 280 // invalid certificate. | 449 // invalid certificate. | 
| 281 #if defined(USE_NSS_CERTS) || defined(OS_WIN) | 450 if (this->UsingCertVerifyProcNSS() || this->UsingCertVerifyProcWin()) { | 
| 282 EXPECT_TRUE(verify_result.cert_status & | 451 EXPECT_TRUE(verify_result.cert_status & | 
| 283 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); | 452 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); | 
| 284 #endif | 453 } | 
| 454 | |
| 455 // TODO(crbug.com/649017): What expectations to use for the other verifiers? | |
| 285 } | 456 } | 
| 286 | 457 | 
| 287 // A regression test for http://crbug.com/31497. | 458 // A regression test for http://crbug.com/31497. | 
| 288 #if defined(OS_ANDROID) | 459 TYPED_TEST(CertVerifyProcTypedTest, IntermediateCARequireExplicitPolicy) { | 
| 289 // Disabled on Android, as the Android verification libraries require an | 460 if (this->UsingCertVerifyProcAndroid()) { | 
| 290 // explicit policy to be specified, even when anyPolicy is permitted. | 461 // Disabled on Android, as the Android verification libraries require an | 
| 291 #define MAYBE_IntermediateCARequireExplicitPolicy \ | 462 // explicit policy to be specified, even when anyPolicy is permitted. | 
| 292 DISABLED_IntermediateCARequireExplicitPolicy | 463 LOG(INFO) << "Skipping test on Android"; | 
| 293 #else | 464 return; | 
| 294 #define MAYBE_IntermediateCARequireExplicitPolicy \ | 465 } | 
| 295 IntermediateCARequireExplicitPolicy | 466 | 
| 296 #endif | |
| 297 TEST_F(CertVerifyProcTest, MAYBE_IntermediateCARequireExplicitPolicy) { | |
| 298 base::FilePath certs_dir = GetTestCertsDirectory(); | 467 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 299 | 468 | 
| 300 CertificateList certs = CreateCertificateListFromFile( | 469 CertificateList certs = CreateCertificateListFromFile( | 
| 301 certs_dir, "explicit-policy-chain.pem", | 470 certs_dir, "explicit-policy-chain.pem", X509Certificate::FORMAT_AUTO); | 
| 302 X509Certificate::FORMAT_AUTO); | |
| 303 ASSERT_EQ(3U, certs.size()); | 471 ASSERT_EQ(3U, certs.size()); | 
| 304 | 472 | 
| 305 X509Certificate::OSCertHandles intermediates; | 473 X509Certificate::OSCertHandles intermediates; | 
| 306 intermediates.push_back(certs[1]->os_cert_handle()); | 474 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 307 | 475 | 
| 308 scoped_refptr<X509Certificate> cert = | 476 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( | 
| 309 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 477 certs[0]->os_cert_handle(), intermediates); | 
| 310 intermediates); | |
| 311 ASSERT_TRUE(cert.get()); | 478 ASSERT_TRUE(cert.get()); | 
| 312 | 479 | 
| 313 ScopedTestRoot scoped_root(certs[2].get()); | 480 ScopedTestRoot scoped_root(certs[2].get()); | 
| 314 | 481 | 
| 315 int flags = 0; | 482 int flags = 0; | 
| 316 CertVerifyResult verify_result; | 483 CertVerifyResult verify_result; | 
| 317 int error = Verify(cert.get(), | 484 int error = this->Verify(cert.get(), "policy_test.example", flags, NULL, | 
| 318 "policy_test.example", | 485 EmptyCertList(), &verify_result); | 
| 319 flags, | |
| 320 NULL, | |
| 321 empty_cert_list_, | |
| 322 &verify_result); | |
| 323 EXPECT_THAT(error, IsOk()); | 486 EXPECT_THAT(error, IsOk()); | 
| 324 EXPECT_EQ(0u, verify_result.cert_status); | 487 EXPECT_EQ(0u, verify_result.cert_status); | 
| 325 } | 488 } | 
| 326 | 489 | 
| 327 TEST_F(CertVerifyProcTest, RejectExpiredCert) { | 490 TYPED_TEST(CertVerifyProcTypedTest, RejectExpiredCert) { | 
| 328 base::FilePath certs_dir = GetTestCertsDirectory(); | 491 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 329 | 492 | 
| 330 // Load root_ca_cert.pem into the test root store. | 493 // Load root_ca_cert.pem into the test root store. | 
| 331 ScopedTestRoot test_root( | 494 ScopedTestRoot test_root( | 
| 332 ImportCertFromFile(certs_dir, "root_ca_cert.pem").get()); | 495 ImportCertFromFile(certs_dir, "root_ca_cert.pem").get()); | 
| 333 | 496 | 
| 334 CertificateList certs = CreateCertificateListFromFile( | 497 CertificateList certs = CreateCertificateListFromFile( | 
| 335 certs_dir, "expired_cert.pem", X509Certificate::FORMAT_AUTO); | 498 certs_dir, "expired_cert.pem", X509Certificate::FORMAT_AUTO); | 
| 336 ASSERT_EQ(1U, certs.size()); | 499 ASSERT_EQ(1U, certs.size()); | 
| 337 | 500 | 
| 338 X509Certificate::OSCertHandles intermediates; | 501 X509Certificate::OSCertHandles intermediates; | 
| 339 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( | 502 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( | 
| 340 certs[0]->os_cert_handle(), intermediates); | 503 certs[0]->os_cert_handle(), intermediates); | 
| 341 | 504 | 
| 342 int flags = 0; | 505 int flags = 0; | 
| 343 CertVerifyResult verify_result; | 506 CertVerifyResult verify_result; | 
| 344 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 507 int error = this->Verify(cert.get(), "127.0.0.1", flags, NULL, | 
| 345 &verify_result); | 508 EmptyCertList(), &verify_result); | 
| 346 EXPECT_THAT(error, IsError(ERR_CERT_DATE_INVALID)); | 509 EXPECT_THAT(error, IsError(ERR_CERT_DATE_INVALID)); | 
| 347 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_DATE_INVALID); | 510 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_DATE_INVALID); | 
| 348 } | 511 } | 
| 349 | 512 | 
| 350 // Currently, only RSA and DSA keys are checked for weakness, and our example | 513 // Currently, only RSA and DSA keys are checked for weakness, and our example | 
| 351 // weak size is 768. These could change in the future. | 514 // weak size is 768. These could change in the future. | 
| 352 // | 515 // | 
| 353 // Note that this means there may be false negatives: keys for other | 516 // Note that this means there may be false negatives: keys for other | 
| 354 // algorithms and which are weak will pass this test. | 517 // algorithms and which are weak will pass this test. | 
| 355 static bool IsWeakKeyType(const std::string& key_type) { | 518 static bool IsWeakKeyType(const std::string& key_type) { | 
| 356 size_t pos = key_type.find("-"); | 519 size_t pos = key_type.find("-"); | 
| 357 std::string size = key_type.substr(0, pos); | 520 std::string size = key_type.substr(0, pos); | 
| 358 std::string type = key_type.substr(pos + 1); | 521 std::string type = key_type.substr(pos + 1); | 
| 359 | 522 | 
| 360 if (type == "rsa" || type == "dsa") | 523 if (type == "rsa" || type == "dsa") | 
| 361 return size == "768"; | 524 return size == "768"; | 
| 362 | 525 | 
| 363 return false; | 526 return false; | 
| 364 } | 527 } | 
| 365 | 528 | 
| 366 TEST_F(CertVerifyProcTest, RejectWeakKeys) { | 529 TYPED_TEST(CertVerifyProcTypedTest, RejectWeakKeys) { | 
| 367 base::FilePath certs_dir = GetTestCertsDirectory(); | 530 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 368 typedef std::vector<std::string> Strings; | 531 typedef std::vector<std::string> Strings; | 
| 369 Strings key_types; | 532 Strings key_types; | 
| 370 | 533 | 
| 371 // generate-weak-test-chains.sh currently has: | 534 // generate-weak-test-chains.sh currently has: | 
| 372 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa" | 535 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa" | 
| 373 // We must use the same key types here. The filenames generated look like: | 536 // We must use the same key types here. The filenames generated look like: | 
| 374 // 2048-rsa-ee-by-768-rsa-intermediate.pem | 537 // 2048-rsa-ee-by-768-rsa-intermediate.pem | 
| 375 key_types.push_back("768-rsa"); | 538 key_types.push_back("768-rsa"); | 
| 376 key_types.push_back("1024-rsa"); | 539 key_types.push_back("1024-rsa"); | 
| 377 key_types.push_back("2048-rsa"); | 540 key_types.push_back("2048-rsa"); | 
| 378 key_types.push_back("prime256v1-ecdsa"); | 541 key_types.push_back("prime256v1-ecdsa"); | 
| 379 | 542 | 
| 380 // Add the root that signed the intermediates for this test. | 543 // Add the root that signed the intermediates for this test. | 
| 381 scoped_refptr<X509Certificate> root_cert = | 544 scoped_refptr<X509Certificate> root_cert = | 
| 382 ImportCertFromFile(certs_dir, "2048-rsa-root.pem"); | 545 ImportCertFromFile(certs_dir, "2048-rsa-root.pem"); | 
| 383 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert.get()); | 546 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert.get()); | 
| 384 ScopedTestRoot scoped_root(root_cert.get()); | 547 ScopedTestRoot scoped_root(root_cert.get()); | 
| 385 | 548 | 
| 386 // Now test each chain. | 549 // Now test each chain. | 
| 387 for (Strings::const_iterator ee_type = key_types.begin(); | 550 for (Strings::const_iterator ee_type = key_types.begin(); | 
| 388 ee_type != key_types.end(); ++ee_type) { | 551 ee_type != key_types.end(); ++ee_type) { | 
| 389 for (Strings::const_iterator signer_type = key_types.begin(); | 552 for (Strings::const_iterator signer_type = key_types.begin(); | 
| 390 signer_type != key_types.end(); ++signer_type) { | 553 signer_type != key_types.end(); ++signer_type) { | 
| 391 std::string basename = *ee_type + "-ee-by-" + *signer_type + | 554 std::string basename = | 
| 392 "-intermediate.pem"; | 555 *ee_type + "-ee-by-" + *signer_type + "-intermediate.pem"; | 
| 393 SCOPED_TRACE(basename); | 556 SCOPED_TRACE(basename); | 
| 394 scoped_refptr<X509Certificate> ee_cert = | 557 scoped_refptr<X509Certificate> ee_cert = | 
| 395 ImportCertFromFile(certs_dir, basename); | 558 ImportCertFromFile(certs_dir, basename); | 
| 396 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert.get()); | 559 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert.get()); | 
| 397 | 560 | 
| 398 basename = *signer_type + "-intermediate.pem"; | 561 basename = *signer_type + "-intermediate.pem"; | 
| 399 scoped_refptr<X509Certificate> intermediate = | 562 scoped_refptr<X509Certificate> intermediate = | 
| 400 ImportCertFromFile(certs_dir, basename); | 563 ImportCertFromFile(certs_dir, basename); | 
| 401 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate.get()); | 564 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate.get()); | 
| 402 | 565 | 
| 403 X509Certificate::OSCertHandles intermediates; | 566 X509Certificate::OSCertHandles intermediates; | 
| 404 intermediates.push_back(intermediate->os_cert_handle()); | 567 intermediates.push_back(intermediate->os_cert_handle()); | 
| 405 scoped_refptr<X509Certificate> cert_chain = | 568 scoped_refptr<X509Certificate> cert_chain = | 
| 406 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), | 569 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), | 
| 407 intermediates); | 570 intermediates); | 
| 408 | 571 | 
| 409 CertVerifyResult verify_result; | 572 CertVerifyResult verify_result; | 
| 410 int error = Verify(cert_chain.get(), | 573 int error = this->Verify(cert_chain.get(), "127.0.0.1", 0, NULL, | 
| 411 "127.0.0.1", | 574 EmptyCertList(), &verify_result); | 
| 412 0, | |
| 413 NULL, | |
| 414 empty_cert_list_, | |
| 415 &verify_result); | |
| 416 | 575 | 
| 417 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { | 576 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { | 
| 418 EXPECT_NE(OK, error); | 577 EXPECT_NE(OK, error); | 
| 419 EXPECT_EQ(CERT_STATUS_WEAK_KEY, | 578 EXPECT_EQ(CERT_STATUS_WEAK_KEY, | 
| 420 verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 579 verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 
| 421 EXPECT_EQ(WeakKeysAreInvalid() ? CERT_STATUS_INVALID : 0, | 580 EXPECT_EQ(WeakKeysAreInvalid(this->verify_proc_.get()) | 
| 581 ? CERT_STATUS_INVALID | |
| 582 : 0, | |
| 422 verify_result.cert_status & CERT_STATUS_INVALID); | 583 verify_result.cert_status & CERT_STATUS_INVALID); | 
| 423 } else { | 584 } else { | 
| 424 EXPECT_THAT(error, IsOk()); | 585 EXPECT_THAT(error, IsOk()); | 
| 425 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 586 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 
| 426 } | 587 } | 
| 427 } | 588 } | 
| 428 } | 589 } | 
| 429 } | 590 } | 
| 430 | 591 | 
| 431 // Regression test for http://crbug.com/108514. | 592 // Regression test for http://crbug.com/108514. | 
| 432 #if defined(OS_MACOSX) && !defined(OS_IOS) | 593 TYPED_TEST(CertVerifyProcTypedTest, ExtraneousMD5RootCert) { | 
| 433 // Disabled on OS X - Security.framework doesn't ignore superflous certificates | 594 if (!SupportsReturningVerifiedChain(this->verify_proc_.get())) { | 
| 434 // provided by servers. See CertVerifyProcTest.CybertrustGTERoot for further | |
| 435 // details. | |
| 436 #define MAYBE_ExtraneousMD5RootCert DISABLED_ExtraneousMD5RootCert | |
| 437 #else | |
| 438 #define MAYBE_ExtraneousMD5RootCert ExtraneousMD5RootCert | |
| 439 #endif | |
| 440 TEST_F(CertVerifyProcTest, MAYBE_ExtraneousMD5RootCert) { | |
| 441 if (!SupportsReturningVerifiedChain()) { | |
| 442 LOG(INFO) << "Skipping this test in this platform."; | 595 LOG(INFO) << "Skipping this test in this platform."; | 
| 443 return; | 596 return; | 
| 444 } | 597 } | 
| 445 | 598 | 
| 599 if (this->UsingCertVerifyProcMac()) { | |
| 600 // Disabled on OS X - Security.framework doesn't ignore superflous | |
| 601 // certificates provided by servers. | |
| 602 LOG(INFO) << "Skipping this test as Security.framework doesn't ignore " | |
| 603 "superflous certificates provided by servers."; | |
| 604 return; | |
| 605 } | |
| 606 | |
| 446 base::FilePath certs_dir = GetTestCertsDirectory(); | 607 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 447 | 608 | 
| 448 scoped_refptr<X509Certificate> server_cert = | 609 scoped_refptr<X509Certificate> server_cert = | 
| 449 ImportCertFromFile(certs_dir, "cross-signed-leaf.pem"); | 610 ImportCertFromFile(certs_dir, "cross-signed-leaf.pem"); | 
| 450 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 611 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 
| 451 | 612 | 
| 452 scoped_refptr<X509Certificate> extra_cert = | 613 scoped_refptr<X509Certificate> extra_cert = | 
| 453 ImportCertFromFile(certs_dir, "cross-signed-root-md5.pem"); | 614 ImportCertFromFile(certs_dir, "cross-signed-root-md5.pem"); | 
| 454 ASSERT_NE(static_cast<X509Certificate*>(NULL), extra_cert.get()); | 615 ASSERT_NE(static_cast<X509Certificate*>(NULL), extra_cert.get()); | 
| 455 | 616 | 
| 456 scoped_refptr<X509Certificate> root_cert = | 617 scoped_refptr<X509Certificate> root_cert = | 
| 457 ImportCertFromFile(certs_dir, "cross-signed-root-sha256.pem"); | 618 ImportCertFromFile(certs_dir, "cross-signed-root-sha256.pem"); | 
| 458 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert.get()); | 619 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert.get()); | 
| 459 | 620 | 
| 460 ScopedTestRoot scoped_root(root_cert.get()); | 621 ScopedTestRoot scoped_root(root_cert.get()); | 
| 461 | 622 | 
| 462 X509Certificate::OSCertHandles intermediates; | 623 X509Certificate::OSCertHandles intermediates; | 
| 463 intermediates.push_back(extra_cert->os_cert_handle()); | 624 intermediates.push_back(extra_cert->os_cert_handle()); | 
| 464 scoped_refptr<X509Certificate> cert_chain = | 625 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle( | 
| 465 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), | 626 server_cert->os_cert_handle(), intermediates); | 
| 466 intermediates); | |
| 467 | 627 | 
| 468 CertVerifyResult verify_result; | 628 CertVerifyResult verify_result; | 
| 469 int flags = 0; | 629 int flags = 0; | 
| 470 int error = Verify(cert_chain.get(), | 630 int error = this->Verify(cert_chain.get(), "127.0.0.1", flags, NULL, | 
| 471 "127.0.0.1", | 631 EmptyCertList(), &verify_result); | 
| 472 flags, | |
| 473 NULL, | |
| 474 empty_cert_list_, | |
| 475 &verify_result); | |
| 476 EXPECT_THAT(error, IsOk()); | 632 EXPECT_THAT(error, IsOk()); | 
| 477 | 633 | 
| 478 // The extra MD5 root should be discarded | 634 // The extra MD5 root should be discarded | 
| 479 ASSERT_TRUE(verify_result.verified_cert.get()); | 635 ASSERT_TRUE(verify_result.verified_cert.get()); | 
| 480 ASSERT_EQ(1u, | 636 ASSERT_EQ(1u, | 
| 481 verify_result.verified_cert->GetIntermediateCertificates().size()); | 637 verify_result.verified_cert->GetIntermediateCertificates().size()); | 
| 482 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 638 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 
| 483 verify_result.verified_cert->GetIntermediateCertificates().front(), | 639 verify_result.verified_cert->GetIntermediateCertificates().front(), | 
| 484 root_cert->os_cert_handle())); | 640 root_cert->os_cert_handle())); | 
| 485 | 641 | 
| 486 EXPECT_FALSE(verify_result.has_md5); | 642 EXPECT_FALSE(verify_result.has_md5); | 
| 487 } | 643 } | 
| 488 | 644 | 
| 489 // Test for bug 94673. | 645 // Test for bug 94673. | 
| 490 TEST_F(CertVerifyProcTest, GoogleDigiNotarTest) { | 646 TYPED_TEST(CertVerifyProcTypedTest, GoogleDigiNotarTest) { | 
| 491 base::FilePath certs_dir = GetTestCertsDirectory(); | 647 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 492 | 648 | 
| 493 scoped_refptr<X509Certificate> server_cert = | 649 scoped_refptr<X509Certificate> server_cert = | 
| 494 ImportCertFromFile(certs_dir, "google_diginotar.pem"); | 650 ImportCertFromFile(certs_dir, "google_diginotar.pem"); | 
| 495 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 651 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 
| 496 | 652 | 
| 497 scoped_refptr<X509Certificate> intermediate_cert = | 653 scoped_refptr<X509Certificate> intermediate_cert = | 
| 498 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); | 654 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); | 
| 499 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert.get()); | 655 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert.get()); | 
| 500 | 656 | 
| 501 X509Certificate::OSCertHandles intermediates; | 657 X509Certificate::OSCertHandles intermediates; | 
| 502 intermediates.push_back(intermediate_cert->os_cert_handle()); | 658 intermediates.push_back(intermediate_cert->os_cert_handle()); | 
| 503 scoped_refptr<X509Certificate> cert_chain = | 659 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle( | 
| 504 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), | 660 server_cert->os_cert_handle(), intermediates); | 
| 505 intermediates); | |
| 506 | 661 | 
| 507 CertVerifyResult verify_result; | 662 CertVerifyResult verify_result; | 
| 508 int flags = CertVerifier::VERIFY_REV_CHECKING_ENABLED; | 663 int flags = CertVerifier::VERIFY_REV_CHECKING_ENABLED; | 
| 509 int error = Verify(cert_chain.get(), | 664 int error = this->Verify(cert_chain.get(), "mail.google.com", flags, NULL, | 
| 510 "mail.google.com", | 665 EmptyCertList(), &verify_result); | 
| 511 flags, | |
| 512 NULL, | |
| 513 empty_cert_list_, | |
| 514 &verify_result); | |
| 515 EXPECT_NE(OK, error); | 666 EXPECT_NE(OK, error); | 
| 516 | 667 | 
| 517 // Now turn off revocation checking. Certificate verification should still | 668 // Now turn off revocation checking. Certificate verification should still | 
| 518 // fail. | 669 // fail. | 
| 519 flags = 0; | 670 flags = 0; | 
| 520 error = Verify(cert_chain.get(), | 671 error = this->Verify(cert_chain.get(), "mail.google.com", flags, NULL, | 
| 521 "mail.google.com", | 672 EmptyCertList(), &verify_result); | 
| 522 flags, | |
| 523 NULL, | |
| 524 empty_cert_list_, | |
| 525 &verify_result); | |
| 526 EXPECT_NE(OK, error); | 673 EXPECT_NE(OK, error); | 
| 527 } | 674 } | 
| 528 | 675 | 
| 529 // Ensures the CertVerifyProc blacklist remains in sorted order, so that it | 676 // Ensures the CertVerifyProc blacklist remains in sorted order, so that it | 
| 530 // can be binary-searched. | 677 // can be binary-searched. | 
| 531 TEST_F(CertVerifyProcTest, BlacklistIsSorted) { | 678 TEST_F(CertVerifyProcBaseClassTest, BlacklistIsSorted) { | 
| 532 // Defines kBlacklistedSPKIs. | 679 // Defines kBlacklistedSPKIs. | 
| 533 #include "net/cert/cert_verify_proc_blacklist.inc" | 680 #include "net/cert/cert_verify_proc_blacklist.inc" | 
| 534 for (size_t i = 0; i < arraysize(kBlacklistedSPKIs) - 1; ++i) { | 681 for (size_t i = 0; i < arraysize(kBlacklistedSPKIs) - 1; ++i) { | 
| 535 EXPECT_GT(0, memcmp(kBlacklistedSPKIs[i], kBlacklistedSPKIs[i + 1], | 682 EXPECT_GT(0, memcmp(kBlacklistedSPKIs[i], kBlacklistedSPKIs[i + 1], | 
| 536 crypto::kSHA256Length)) | 683 crypto::kSHA256Length)) | 
| 537 << " at index " << i; | 684 << " at index " << i; | 
| 538 } | 685 } | 
| 539 } | 686 } | 
| 540 | 687 | 
| 541 TEST_F(CertVerifyProcTest, DigiNotarCerts) { | 688 TEST_F(CertVerifyProcBaseClassTest, DigiNotarCerts) { | 
| 542 static const char* const kDigiNotarFilenames[] = { | 689 static const char* const kDigiNotarFilenames[] = { | 
| 543 "diginotar_root_ca.pem", | 690 "diginotar_root_ca.pem", "diginotar_cyber_ca.pem", | 
| 544 "diginotar_cyber_ca.pem", | 691 "diginotar_services_1024_ca.pem", "diginotar_pkioverheid.pem", | 
| 545 "diginotar_services_1024_ca.pem", | 692 "diginotar_pkioverheid_g2.pem", NULL, | 
| 546 "diginotar_pkioverheid.pem", | |
| 547 "diginotar_pkioverheid_g2.pem", | |
| 548 NULL, | |
| 549 }; | 693 }; | 
| 550 | 694 | 
| 551 base::FilePath certs_dir = GetTestCertsDirectory(); | 695 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 552 | 696 | 
| 553 for (size_t i = 0; kDigiNotarFilenames[i]; i++) { | 697 for (size_t i = 0; kDigiNotarFilenames[i]; i++) { | 
| 554 scoped_refptr<X509Certificate> diginotar_cert = | 698 scoped_refptr<X509Certificate> diginotar_cert = | 
| 555 ImportCertFromFile(certs_dir, kDigiNotarFilenames[i]); | 699 ImportCertFromFile(certs_dir, kDigiNotarFilenames[i]); | 
| 556 std::string der_bytes; | 700 std::string der_bytes; | 
| 557 ASSERT_TRUE(X509Certificate::GetDEREncoded( | 701 ASSERT_TRUE(X509Certificate::GetDEREncoded(diginotar_cert->os_cert_handle(), | 
| 558 diginotar_cert->os_cert_handle(), &der_bytes)); | 702 &der_bytes)); | 
| 559 | 703 | 
| 560 base::StringPiece spki; | 704 base::StringPiece spki; | 
| 561 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(der_bytes, &spki)); | 705 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(der_bytes, &spki)); | 
| 562 | 706 | 
| 563 std::string spki_sha256 = crypto::SHA256HashString(spki.as_string()); | 707 std::string spki_sha256 = crypto::SHA256HashString(spki.as_string()); | 
| 564 | 708 | 
| 565 HashValueVector public_keys; | 709 HashValueVector public_keys; | 
| 566 HashValue hash(HASH_VALUE_SHA256); | 710 HashValue hash(HASH_VALUE_SHA256); | 
| 567 ASSERT_EQ(hash.size(), spki_sha256.size()); | 711 ASSERT_EQ(hash.size(), spki_sha256.size()); | 
| 568 memcpy(hash.data(), spki_sha256.data(), spki_sha256.size()); | 712 memcpy(hash.data(), spki_sha256.data(), spki_sha256.size()); | 
| 569 public_keys.push_back(hash); | 713 public_keys.push_back(hash); | 
| 570 | 714 | 
| 571 EXPECT_TRUE(CertVerifyProc::IsPublicKeyBlacklisted(public_keys)) << | 715 EXPECT_TRUE(CertVerifyProc::IsPublicKeyBlacklisted(public_keys)) | 
| 572 "Public key not blocked for " << kDigiNotarFilenames[i]; | 716 << "Public key not blocked for " << kDigiNotarFilenames[i]; | 
| 573 } | 717 } | 
| 574 } | 718 } | 
| 575 | 719 | 
| 576 TEST_F(CertVerifyProcTest, NameConstraintsOk) { | 720 TYPED_TEST(CertVerifyProcTypedTest, NameConstraintsOk) { | 
| 577 CertificateList ca_cert_list = | 721 CertificateList ca_cert_list = | 
| 578 CreateCertificateListFromFile(GetTestCertsDirectory(), | 722 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem", | 
| 579 "root_ca_cert.pem", | |
| 580 X509Certificate::FORMAT_AUTO); | 723 X509Certificate::FORMAT_AUTO); | 
| 581 ASSERT_EQ(1U, ca_cert_list.size()); | 724 ASSERT_EQ(1U, ca_cert_list.size()); | 
| 582 ScopedTestRoot test_root(ca_cert_list[0].get()); | 725 ScopedTestRoot test_root(ca_cert_list[0].get()); | 
| 583 | 726 | 
| 584 CertificateList cert_list = CreateCertificateListFromFile( | 727 CertificateList cert_list = CreateCertificateListFromFile( | 
| 585 GetTestCertsDirectory(), "name_constraint_good.pem", | 728 GetTestCertsDirectory(), "name_constraint_good.pem", | 
| 586 X509Certificate::FORMAT_AUTO); | 729 X509Certificate::FORMAT_AUTO); | 
| 587 ASSERT_EQ(1U, cert_list.size()); | 730 ASSERT_EQ(1U, cert_list.size()); | 
| 588 | 731 | 
| 589 X509Certificate::OSCertHandles intermediates; | 732 X509Certificate::OSCertHandles intermediates; | 
| 590 scoped_refptr<X509Certificate> leaf = | 733 scoped_refptr<X509Certificate> leaf = X509Certificate::CreateFromHandle( | 
| 591 X509Certificate::CreateFromHandle(cert_list[0]->os_cert_handle(), | 734 cert_list[0]->os_cert_handle(), intermediates); | 
| 592 intermediates); | |
| 593 | 735 | 
| 594 int flags = 0; | 736 int flags = 0; | 
| 595 CertVerifyResult verify_result; | 737 CertVerifyResult verify_result; | 
| 596 int error = Verify(leaf.get(), | 738 int error = this->Verify(leaf.get(), "test.example.com", flags, NULL, | 
| 597 "test.example.com", | 739 EmptyCertList(), &verify_result); | 
| 598 flags, | |
| 599 NULL, | |
| 600 empty_cert_list_, | |
| 601 &verify_result); | |
| 602 EXPECT_THAT(error, IsOk()); | 740 EXPECT_THAT(error, IsOk()); | 
| 603 EXPECT_EQ(0U, verify_result.cert_status); | 741 EXPECT_EQ(0U, verify_result.cert_status); | 
| 604 | 742 | 
| 605 error = Verify(leaf.get(), "foo.test2.example.com", flags, NULL, | 743 error = this->Verify(leaf.get(), "foo.test2.example.com", flags, NULL, | 
| 606 empty_cert_list_, &verify_result); | 744 EmptyCertList(), &verify_result); | 
| 607 EXPECT_THAT(error, IsOk()); | 745 EXPECT_THAT(error, IsOk()); | 
| 608 EXPECT_EQ(0U, verify_result.cert_status); | 746 EXPECT_EQ(0U, verify_result.cert_status); | 
| 609 } | 747 } | 
| 610 | 748 | 
| 611 TEST_F(CertVerifyProcTest, NameConstraintsFailure) { | 749 TYPED_TEST(CertVerifyProcTypedTest, NameConstraintsFailure) { | 
| 612 if (!SupportsReturningVerifiedChain()) { | 750 if (!SupportsReturningVerifiedChain(this->verify_proc_.get())) { | 
| 613 LOG(INFO) << "Skipping this test in this platform."; | 751 LOG(INFO) << "Skipping this test in this platform."; | 
| 614 return; | 752 return; | 
| 615 } | 753 } | 
| 616 | 754 | 
| 617 CertificateList ca_cert_list = | 755 CertificateList ca_cert_list = | 
| 618 CreateCertificateListFromFile(GetTestCertsDirectory(), | 756 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem", | 
| 619 "root_ca_cert.pem", | |
| 620 X509Certificate::FORMAT_AUTO); | 757 X509Certificate::FORMAT_AUTO); | 
| 621 ASSERT_EQ(1U, ca_cert_list.size()); | 758 ASSERT_EQ(1U, ca_cert_list.size()); | 
| 622 ScopedTestRoot test_root(ca_cert_list[0].get()); | 759 ScopedTestRoot test_root(ca_cert_list[0].get()); | 
| 623 | 760 | 
| 624 CertificateList cert_list = CreateCertificateListFromFile( | 761 CertificateList cert_list = CreateCertificateListFromFile( | 
| 625 GetTestCertsDirectory(), "name_constraint_bad.pem", | 762 GetTestCertsDirectory(), "name_constraint_bad.pem", | 
| 626 X509Certificate::FORMAT_AUTO); | 763 X509Certificate::FORMAT_AUTO); | 
| 627 ASSERT_EQ(1U, cert_list.size()); | 764 ASSERT_EQ(1U, cert_list.size()); | 
| 628 | 765 | 
| 629 X509Certificate::OSCertHandles intermediates; | 766 X509Certificate::OSCertHandles intermediates; | 
| 630 scoped_refptr<X509Certificate> leaf = | 767 scoped_refptr<X509Certificate> leaf = X509Certificate::CreateFromHandle( | 
| 631 X509Certificate::CreateFromHandle(cert_list[0]->os_cert_handle(), | 768 cert_list[0]->os_cert_handle(), intermediates); | 
| 632 intermediates); | |
| 633 | 769 | 
| 634 int flags = 0; | 770 int flags = 0; | 
| 635 CertVerifyResult verify_result; | 771 CertVerifyResult verify_result; | 
| 636 int error = Verify(leaf.get(), | 772 int error = this->Verify(leaf.get(), "test.example.com", flags, NULL, | 
| 637 "test.example.com", | 773 EmptyCertList(), &verify_result); | 
| 638 flags, | |
| 639 NULL, | |
| 640 empty_cert_list_, | |
| 641 &verify_result); | |
| 642 EXPECT_THAT(error, IsError(ERR_CERT_NAME_CONSTRAINT_VIOLATION)); | 774 EXPECT_THAT(error, IsError(ERR_CERT_NAME_CONSTRAINT_VIOLATION)); | 
| 643 EXPECT_EQ(CERT_STATUS_NAME_CONSTRAINT_VIOLATION, | 775 EXPECT_EQ(CERT_STATUS_NAME_CONSTRAINT_VIOLATION, | 
| 644 verify_result.cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION); | 776 verify_result.cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION); | 
| 645 } | 777 } | 
| 646 | 778 | 
| 647 TEST_F(CertVerifyProcTest, TestHasTooLongValidity) { | 779 TEST_F(CertVerifyProcBaseClassTest, TestHasTooLongValidity) { | 
| 648 struct { | 780 struct { | 
| 649 const char* const file; | 781 const char* const file; | 
| 650 bool is_valid_too_long; | 782 bool is_valid_too_long; | 
| 651 } tests[] = { | 783 } tests[] = { | 
| 652 {"twitter-chain.pem", false}, | 784 {"twitter-chain.pem", false}, | 
| 653 {"start_after_expiry.pem", true}, | 785 {"start_after_expiry.pem", true}, | 
| 654 {"pre_br_validity_ok.pem", false}, | 786 {"pre_br_validity_ok.pem", false}, | 
| 655 {"pre_br_validity_bad_121.pem", true}, | 787 {"pre_br_validity_bad_121.pem", true}, | 
| 656 {"pre_br_validity_bad_2020.pem", true}, | 788 {"pre_br_validity_bad_2020.pem", true}, | 
| 657 {"10_year_validity.pem", false}, | 789 {"10_year_validity.pem", false}, | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 668 scoped_refptr<X509Certificate> certificate = | 800 scoped_refptr<X509Certificate> certificate = | 
| 669 ImportCertFromFile(certs_dir, tests[i].file); | 801 ImportCertFromFile(certs_dir, tests[i].file); | 
| 670 SCOPED_TRACE(tests[i].file); | 802 SCOPED_TRACE(tests[i].file); | 
| 671 ASSERT_TRUE(certificate); | 803 ASSERT_TRUE(certificate); | 
| 672 EXPECT_EQ(tests[i].is_valid_too_long, | 804 EXPECT_EQ(tests[i].is_valid_too_long, | 
| 673 CertVerifyProc::HasTooLongValidity(*certificate)); | 805 CertVerifyProc::HasTooLongValidity(*certificate)); | 
| 674 } | 806 } | 
| 675 } | 807 } | 
| 676 | 808 | 
| 677 // TODO(crbug.com/610546): Fix and re-enable this test. | 809 // TODO(crbug.com/610546): Fix and re-enable this test. | 
| 678 TEST_F(CertVerifyProcTest, DISABLED_TestKnownRoot) { | 810 TYPED_TEST(CertVerifyProcTypedTest, DISABLED_TestKnownRoot) { | 
| 679 if (!SupportsDetectingKnownRoots()) { | 811 if (!SupportsDetectingKnownRoots(this->verify_proc_.get())) { | 
| 680 LOG(INFO) << "Skipping this test on this platform."; | 812 LOG(INFO) << "Skipping this test on this platform."; | 
| 681 return; | 813 return; | 
| 682 } | 814 } | 
| 683 | 815 | 
| 684 base::FilePath certs_dir = GetTestCertsDirectory(); | 816 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 685 CertificateList certs = CreateCertificateListFromFile( | 817 CertificateList certs = CreateCertificateListFromFile( | 
| 686 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); | 818 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); | 
| 687 ASSERT_EQ(3U, certs.size()); | 819 ASSERT_EQ(3U, certs.size()); | 
| 688 | 820 | 
| 689 X509Certificate::OSCertHandles intermediates; | 821 X509Certificate::OSCertHandles intermediates; | 
| 690 intermediates.push_back(certs[1]->os_cert_handle()); | 822 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 691 | 823 | 
| 692 scoped_refptr<X509Certificate> cert_chain = | 824 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle( | 
| 693 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 825 certs[0]->os_cert_handle(), intermediates); | 
| 694 intermediates); | |
| 695 | 826 | 
| 696 int flags = 0; | 827 int flags = 0; | 
| 697 CertVerifyResult verify_result; | 828 CertVerifyResult verify_result; | 
| 698 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug | 829 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug | 
| 699 // against agl. See also PublicKeyHashes. | 830 // against agl. See also PublicKeyHashes. | 
| 700 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, | 831 int error = this->Verify(cert_chain.get(), "twitter.com", flags, NULL, | 
| 701 empty_cert_list_, &verify_result); | 832 EmptyCertList(), &verify_result); | 
| 702 EXPECT_THAT(error, IsOk()); | 833 EXPECT_THAT(error, IsOk()); | 
| 703 EXPECT_TRUE(verify_result.is_issued_by_known_root); | 834 EXPECT_TRUE(verify_result.is_issued_by_known_root); | 
| 704 } | 835 } | 
| 705 | 836 | 
| 706 // TODO(crbug.com/610546): Fix and re-enable this test. | 837 // TODO(crbug.com/610546): Fix and re-enable this test. | 
| 707 TEST_F(CertVerifyProcTest, DISABLED_PublicKeyHashes) { | 838 TYPED_TEST(CertVerifyProcTypedTest, DISABLED_PublicKeyHashes) { | 
| 708 if (!SupportsReturningVerifiedChain()) { | 839 if (!SupportsReturningVerifiedChain(this->verify_proc_.get())) { | 
| 709 LOG(INFO) << "Skipping this test in this platform."; | 840 LOG(INFO) << "Skipping this test in this platform."; | 
| 710 return; | 841 return; | 
| 711 } | 842 } | 
| 712 | 843 | 
| 713 base::FilePath certs_dir = GetTestCertsDirectory(); | 844 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 714 CertificateList certs = CreateCertificateListFromFile( | 845 CertificateList certs = CreateCertificateListFromFile( | 
| 715 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); | 846 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); | 
| 716 ASSERT_EQ(3U, certs.size()); | 847 ASSERT_EQ(3U, certs.size()); | 
| 717 | 848 | 
| 718 X509Certificate::OSCertHandles intermediates; | 849 X509Certificate::OSCertHandles intermediates; | 
| 719 intermediates.push_back(certs[1]->os_cert_handle()); | 850 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 720 | 851 | 
| 721 scoped_refptr<X509Certificate> cert_chain = | 852 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle( | 
| 722 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 853 certs[0]->os_cert_handle(), intermediates); | 
| 723 intermediates); | |
| 724 int flags = 0; | 854 int flags = 0; | 
| 725 CertVerifyResult verify_result; | 855 CertVerifyResult verify_result; | 
| 726 | 856 | 
| 727 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug | 857 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug | 
| 728 // against agl. See also TestKnownRoot. | 858 // against agl. See also TestKnownRoot. | 
| 729 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, | 859 int error = this->Verify(cert_chain.get(), "twitter.com", flags, NULL, | 
| 730 empty_cert_list_, &verify_result); | 860 EmptyCertList(), &verify_result); | 
| 731 EXPECT_THAT(error, IsOk()); | 861 EXPECT_THAT(error, IsOk()); | 
| 732 ASSERT_LE(3U, verify_result.public_key_hashes.size()); | 862 ASSERT_LE(3U, verify_result.public_key_hashes.size()); | 
| 733 | 863 | 
| 734 HashValueVector sha1_hashes; | 864 HashValueVector sha1_hashes; | 
| 735 for (size_t i = 0; i < verify_result.public_key_hashes.size(); ++i) { | 865 for (size_t i = 0; i < verify_result.public_key_hashes.size(); ++i) { | 
| 736 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA1) | 866 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA1) | 
| 737 continue; | 867 continue; | 
| 738 sha1_hashes.push_back(verify_result.public_key_hashes[i]); | 868 sha1_hashes.push_back(verify_result.public_key_hashes[i]); | 
| 739 } | 869 } | 
| 740 ASSERT_LE(3u, sha1_hashes.size()); | 870 ASSERT_LE(3u, sha1_hashes.size()); | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 754 | 884 | 
| 755 for (size_t i = 0; i < 3; ++i) { | 885 for (size_t i = 0; i < 3; ++i) { | 
| 756 EXPECT_EQ(HexEncode(kTwitterSPKIsSHA256[i], crypto::kSHA256Length), | 886 EXPECT_EQ(HexEncode(kTwitterSPKIsSHA256[i], crypto::kSHA256Length), | 
| 757 HexEncode(sha256_hashes[i].data(), crypto::kSHA256Length)); | 887 HexEncode(sha256_hashes[i].data(), crypto::kSHA256Length)); | 
| 758 } | 888 } | 
| 759 } | 889 } | 
| 760 | 890 | 
| 761 // A regression test for http://crbug.com/70293. | 891 // A regression test for http://crbug.com/70293. | 
| 762 // The Key Usage extension in this RSA SSL server certificate does not have | 892 // The Key Usage extension in this RSA SSL server certificate does not have | 
| 763 // the keyEncipherment bit. | 893 // the keyEncipherment bit. | 
| 764 TEST_F(CertVerifyProcTest, InvalidKeyUsage) { | 894 TYPED_TEST(CertVerifyProcTypedTest, InvalidKeyUsage) { | 
| 765 base::FilePath certs_dir = GetTestCertsDirectory(); | 895 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 766 | 896 | 
| 767 scoped_refptr<X509Certificate> server_cert = | 897 scoped_refptr<X509Certificate> server_cert = | 
| 768 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); | 898 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); | 
| 769 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 899 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 
| 770 | 900 | 
| 771 int flags = 0; | 901 int flags = 0; | 
| 772 CertVerifyResult verify_result; | 902 CertVerifyResult verify_result; | 
| 773 int error = Verify(server_cert.get(), | 903 int error = this->Verify(server_cert.get(), "jira.aquameta.com", flags, NULL, | 
| 774 "jira.aquameta.com", | 904 EmptyCertList(), &verify_result); | 
| 775 flags, | 905 | 
| 776 NULL, | 906 if (this->UsingCertVerifyProcOpenSSL()) { | 
| 777 empty_cert_list_, | 907 // This certificate has two errors: "invalid key usage" and "untrusted CA". | 
| 778 &verify_result); | 908 // However, OpenSSL returns only one (the latter), and we can't detect | 
| 779 #if defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | 909 // the other errors. | 
| 780 // This certificate has two errors: "invalid key usage" and "untrusted CA". | 910 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 
| 781 // However, OpenSSL returns only one (the latter), and we can't detect | 911 } else { | 
| 782 // the other errors. | 912 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 
| 783 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 913 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 
| 784 #else | 914 } | 
| 785 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | |
| 786 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | |
| 787 #endif | |
| 788 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors | 915 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors | 
| 789 // from NSS. | 916 // from NSS. | 
| 790 #if !defined(USE_NSS_CERTS) && !defined(OS_IOS) && !defined(OS_ANDROID) | 917 if (!this->UsingCertVerifyProcNSS() && !this->UsingCertVerifyProcIOS() && | 
| 791 // The certificate is issued by an unknown CA. | 918 !this->UsingCertVerifyProcAndroid()) { | 
| 792 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); | 919 // The certificate is issued by an unknown CA. | 
| 793 #endif | 920 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); | 
| 921 } | |
| 922 | |
| 923 // TODO(crbug.com/649017): What expectations to use for the other verifiers? | |
| 794 } | 924 } | 
| 795 | 925 | 
| 796 // Basic test for returning the chain in CertVerifyResult. Note that the | 926 // Basic test for returning the chain in CertVerifyResult. Note that the | 
| 797 // returned chain may just be a reflection of the originally supplied chain; | 927 // returned chain may just be a reflection of the originally supplied chain; | 
| 798 // that is, if any errors occur, the default chain returned is an exact copy | 928 // that is, if any errors occur, the default chain returned is an exact copy | 
| 799 // of the certificate to be verified. The remaining VerifyReturn* tests are | 929 // of the certificate to be verified. The remaining VerifyReturn* tests are | 
| 800 // used to ensure that the actual, verified chain is being returned by | 930 // used to ensure that the actual, verified chain is being returned by | 
| 801 // Verify(). | 931 // Verify(). | 
| 802 TEST_F(CertVerifyProcTest, VerifyReturnChainBasic) { | 932 TYPED_TEST(CertVerifyProcTypedTest, VerifyReturnChainBasic) { | 
| 803 if (!SupportsReturningVerifiedChain()) { | 933 if (!SupportsReturningVerifiedChain(this->verify_proc_.get())) { | 
| 804 LOG(INFO) << "Skipping this test in this platform."; | 934 LOG(INFO) << "Skipping this test in this platform."; | 
| 805 return; | 935 return; | 
| 806 } | 936 } | 
| 807 | 937 | 
| 808 base::FilePath certs_dir = GetTestCertsDirectory(); | 938 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 809 CertificateList certs = CreateCertificateListFromFile( | 939 CertificateList certs = CreateCertificateListFromFile( | 
| 810 certs_dir, "x509_verify_results.chain.pem", | 940 certs_dir, "x509_verify_results.chain.pem", X509Certificate::FORMAT_AUTO); | 
| 811 X509Certificate::FORMAT_AUTO); | |
| 812 ASSERT_EQ(3U, certs.size()); | 941 ASSERT_EQ(3U, certs.size()); | 
| 813 | 942 | 
| 814 X509Certificate::OSCertHandles intermediates; | 943 X509Certificate::OSCertHandles intermediates; | 
| 815 intermediates.push_back(certs[1]->os_cert_handle()); | 944 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 816 intermediates.push_back(certs[2]->os_cert_handle()); | 945 intermediates.push_back(certs[2]->os_cert_handle()); | 
| 817 | 946 | 
| 818 ScopedTestRoot scoped_root(certs[2].get()); | 947 ScopedTestRoot scoped_root(certs[2].get()); | 
| 819 | 948 | 
| 820 scoped_refptr<X509Certificate> google_full_chain = | 949 scoped_refptr<X509Certificate> google_full_chain = | 
| 821 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 950 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 
| 822 intermediates); | 951 intermediates); | 
| 823 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain.get()); | 952 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain.get()); | 
| 824 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); | 953 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); | 
| 825 | 954 | 
| 826 CertVerifyResult verify_result; | 955 CertVerifyResult verify_result; | 
| 827 EXPECT_EQ(static_cast<X509Certificate*>(NULL), | 956 EXPECT_EQ(static_cast<X509Certificate*>(NULL), | 
| 828 verify_result.verified_cert.get()); | 957 verify_result.verified_cert.get()); | 
| 829 int error = Verify(google_full_chain.get(), | 958 int error = this->Verify(google_full_chain.get(), "127.0.0.1", 0, NULL, | 
| 830 "127.0.0.1", | 959 EmptyCertList(), &verify_result); | 
| 831 0, | |
| 832 NULL, | |
| 833 empty_cert_list_, | |
| 834 &verify_result); | |
| 835 EXPECT_THAT(error, IsOk()); | 960 EXPECT_THAT(error, IsOk()); | 
| 836 ASSERT_NE(static_cast<X509Certificate*>(NULL), | 961 ASSERT_NE(static_cast<X509Certificate*>(NULL), | 
| 837 verify_result.verified_cert.get()); | 962 verify_result.verified_cert.get()); | 
| 838 | 963 | 
| 839 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 964 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 
| 840 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 965 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 
| 841 google_full_chain->os_cert_handle(), | 966 google_full_chain->os_cert_handle(), | 
| 842 verify_result.verified_cert->os_cert_handle())); | 967 verify_result.verified_cert->os_cert_handle())); | 
| 843 const X509Certificate::OSCertHandles& return_intermediates = | 968 const X509Certificate::OSCertHandles& return_intermediates = | 
| 844 verify_result.verified_cert->GetIntermediateCertificates(); | 969 verify_result.verified_cert->GetIntermediateCertificates(); | 
| 845 ASSERT_EQ(2U, return_intermediates.size()); | 970 ASSERT_EQ(2U, return_intermediates.size()); | 
| 846 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 971 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 
| 847 certs[1]->os_cert_handle())); | 972 certs[1]->os_cert_handle())); | 
| 848 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 973 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 
| 849 certs[2]->os_cert_handle())); | 974 certs[2]->os_cert_handle())); | 
| 850 } | 975 } | 
| 851 | 976 | 
| 852 // Test that certificates issued for 'intranet' names (that is, containing no | 977 // Test that certificates issued for 'intranet' names (that is, containing no | 
| 853 // known public registry controlled domain information) issued by well-known | 978 // known public registry controlled domain information) issued by well-known | 
| 854 // CAs are flagged appropriately, while certificates that are issued by | 979 // CAs are flagged appropriately, while certificates that are issued by | 
| 855 // internal CAs are not flagged. | 980 // internal CAs are not flagged. | 
| 856 TEST_F(CertVerifyProcTest, IntranetHostsRejected) { | 981 TEST_F(CertVerifyProcBaseClassTest, IntranetHostsRejected) { | 
| 857 if (!SupportsDetectingKnownRoots()) { | 982 // TODO(eroman): Why the below cdoe? It doesn't depend on | 
| 858 LOG(INFO) << "Skipping this test in this platform."; | 983 // the CertVerifyProc concrete class. | 
| 859 return; | 984 // if (!SupportsDetectingKnownRoots(verify_proc_name_)) { | 
| 860 } | 985 // LOG(INFO) << "Skipping this test in this platform."; | 
| 986 // return; | |
| 987 //} | |
| 861 | 988 | 
| 862 CertificateList cert_list = CreateCertificateListFromFile( | 989 CertificateList cert_list = CreateCertificateListFromFile( | 
| 863 GetTestCertsDirectory(), "reject_intranet_hosts.pem", | 990 GetTestCertsDirectory(), "reject_intranet_hosts.pem", | 
| 864 X509Certificate::FORMAT_AUTO); | 991 X509Certificate::FORMAT_AUTO); | 
| 865 ASSERT_EQ(1U, cert_list.size()); | 992 ASSERT_EQ(1U, cert_list.size()); | 
| 866 scoped_refptr<X509Certificate> cert(cert_list[0]); | 993 scoped_refptr<X509Certificate> cert(cert_list[0]); | 
| 867 | 994 | 
| 868 CertVerifyResult verify_result; | 995 CertVerifyResult verify_result; | 
| 869 int error = 0; | 996 int error = 0; | 
| 870 | 997 | 
| 871 // Intranet names for public CAs should be flagged: | 998 // Intranet names for public CAs should be flagged: | 
| 872 CertVerifyResult dummy_result; | 999 CertVerifyResult dummy_result; | 
| 873 dummy_result.is_issued_by_known_root = true; | 1000 dummy_result.is_issued_by_known_root = true; | 
| 874 verify_proc_ = new MockCertVerifyProc(dummy_result); | 1001 auto verify_proc = make_scoped_refptr(new MockCertVerifyProc(dummy_result)); | 
| 875 error = | 1002 error = verify_proc->Verify(cert.get(), "intranet", std::string(), 0, NULL, | 
| 876 Verify(cert.get(), "intranet", 0, NULL, empty_cert_list_, &verify_result); | 1003 CertificateList(), &verify_result); | 
| 877 EXPECT_THAT(error, IsOk()); | 1004 EXPECT_THAT(error, IsOk()); | 
| 878 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); | 1005 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); | 
| 879 | 1006 | 
| 880 // However, if the CA is not well known, these should not be flagged: | 1007 // However, if the CA is not well known, these should not be flagged: | 
| 881 dummy_result.Reset(); | 1008 dummy_result.Reset(); | 
| 882 dummy_result.is_issued_by_known_root = false; | 1009 dummy_result.is_issued_by_known_root = false; | 
| 883 verify_proc_ = new MockCertVerifyProc(dummy_result); | 1010 verify_proc = make_scoped_refptr(new MockCertVerifyProc(dummy_result)); | 
| 884 error = | 1011 error = verify_proc->Verify(cert.get(), "intranet", std::string(), 0, NULL, | 
| 885 Verify(cert.get(), "intranet", 0, NULL, empty_cert_list_, &verify_result); | 1012 CertificateList(), &verify_result); | 
| 886 EXPECT_THAT(error, IsOk()); | 1013 EXPECT_THAT(error, IsOk()); | 
| 887 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); | 1014 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); | 
| 888 } | 1015 } | 
| 889 | 1016 | 
| 890 // While all SHA-1 certificates should be rejected, in the event that there | 1017 // While all SHA-1 certificates should be rejected, in the event that there | 
| 891 // emerges some unexpected bug, test that the 'legacy' behaviour works | 1018 // emerges some unexpected bug, test that the 'legacy' behaviour works | 
| 892 // correctly - rejecting all SHA-1 certificates from publicly trusted CAs | 1019 // correctly - rejecting all SHA-1 certificates from publicly trusted CAs | 
| 893 // that were issued after 1 January 2016, while still allowing those from | 1020 // that were issued after 1 January 2016, while still allowing those from | 
| 894 // before that date, with SHA-1 in the intermediate, or from an enterprise | 1021 // before that date, with SHA-1 in the intermediate, or from an enterprise | 
| 895 // CA. | 1022 // CA. | 
| 896 TEST_F(CertVerifyProcTest, VerifyRejectsSHA1AfterDeprecationLegacyMode) { | 1023 TEST_F(CertVerifyProcBaseClassTest, | 
| 1024 VerifyRejectsSHA1AfterDeprecationLegacyMode) { | |
| 897 base::test::ScopedFeatureList scoped_feature_list; | 1025 base::test::ScopedFeatureList scoped_feature_list; | 
| 898 scoped_feature_list.InitAndEnableFeature(CertVerifyProc::kSHA1LegacyMode); | 1026 scoped_feature_list.InitAndEnableFeature(CertVerifyProc::kSHA1LegacyMode); | 
| 899 | 1027 | 
| 900 CertVerifyResult dummy_result; | 1028 CertVerifyResult dummy_result; | 
| 901 CertVerifyResult verify_result; | 1029 CertVerifyResult verify_result; | 
| 902 int error = 0; | 1030 int error = 0; | 
| 903 scoped_refptr<X509Certificate> cert; | 1031 scoped_refptr<X509Certificate> cert; | 
| 904 | 1032 | 
| 905 // Publicly trusted SHA-1 leaf certificates issued before 1 January 2016 | 1033 // Publicly trusted SHA-1 leaf certificates issued before 1 January 2016 | 
| 906 // are accepted. | 1034 // are accepted. | 
| 907 verify_result.Reset(); | 1035 verify_result.Reset(); | 
| 908 dummy_result.Reset(); | 1036 dummy_result.Reset(); | 
| 909 dummy_result.is_issued_by_known_root = true; | 1037 dummy_result.is_issued_by_known_root = true; | 
| 910 dummy_result.has_sha1 = true; | 1038 dummy_result.has_sha1 = true; | 
| 911 dummy_result.has_sha1_leaf = true; | 1039 dummy_result.has_sha1_leaf = true; | 
| 912 verify_proc_ = new MockCertVerifyProc(dummy_result); | 1040 auto verify_proc = make_scoped_refptr(new MockCertVerifyProc(dummy_result)); | 
| 913 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), | 1041 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), | 
| 914 "sha1_dec_2015.pem", | 1042 "sha1_dec_2015.pem", | 
| 915 X509Certificate::FORMAT_AUTO); | 1043 X509Certificate::FORMAT_AUTO); | 
| 916 ASSERT_TRUE(cert); | 1044 ASSERT_TRUE(cert); | 
| 917 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, | 1045 error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), 0, NULL, | 
| 918 &verify_result); | 1046 CertificateList(), &verify_result); | 
| 919 EXPECT_THAT(error, IsOk()); | 1047 EXPECT_THAT(error, IsOk()); | 
| 920 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 1048 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 
| 921 | 1049 | 
| 922 // Publicly trusted SHA-1 leaf certificates issued on/after 1 January 2016 | 1050 // Publicly trusted SHA-1 leaf certificates issued on/after 1 January 2016 | 
| 923 // are rejected. | 1051 // are rejected. | 
| 924 verify_result.Reset(); | 1052 verify_result.Reset(); | 
| 925 dummy_result.Reset(); | 1053 dummy_result.Reset(); | 
| 926 dummy_result.is_issued_by_known_root = true; | 1054 dummy_result.is_issued_by_known_root = true; | 
| 927 dummy_result.has_sha1 = true; | 1055 dummy_result.has_sha1 = true; | 
| 928 dummy_result.has_sha1_leaf = true; | 1056 dummy_result.has_sha1_leaf = true; | 
| 929 verify_proc_ = new MockCertVerifyProc(dummy_result); | 1057 verify_proc = make_scoped_refptr(new MockCertVerifyProc(dummy_result)); | 
| 930 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), | 1058 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), | 
| 931 "sha1_jan_2016.pem", | 1059 "sha1_jan_2016.pem", | 
| 932 X509Certificate::FORMAT_AUTO); | 1060 X509Certificate::FORMAT_AUTO); | 
| 933 ASSERT_TRUE(cert); | 1061 ASSERT_TRUE(cert); | 
| 934 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, | 1062 error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), 0, NULL, | 
| 935 &verify_result); | 1063 CertificateList(), &verify_result); | 
| 936 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 1064 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 
| 937 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 1065 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 
| 938 | 1066 | 
| 939 // Enterprise issued SHA-1 leaf certificates issued on/after 1 January 2016 | 1067 // Enterprise issued SHA-1 leaf certificates issued on/after 1 January 2016 | 
| 940 // remain accepted. | 1068 // remain accepted. | 
| 941 verify_result.Reset(); | 1069 verify_result.Reset(); | 
| 942 dummy_result.Reset(); | 1070 dummy_result.Reset(); | 
| 943 dummy_result.is_issued_by_known_root = false; | 1071 dummy_result.is_issued_by_known_root = false; | 
| 944 dummy_result.has_sha1 = true; | 1072 dummy_result.has_sha1 = true; | 
| 945 dummy_result.has_sha1_leaf = true; | 1073 dummy_result.has_sha1_leaf = true; | 
| 946 verify_proc_ = new MockCertVerifyProc(dummy_result); | 1074 verify_proc = make_scoped_refptr(new MockCertVerifyProc(dummy_result)); | 
| 947 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), | 1075 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), | 
| 948 "sha1_jan_2016.pem", | 1076 "sha1_jan_2016.pem", | 
| 949 X509Certificate::FORMAT_AUTO); | 1077 X509Certificate::FORMAT_AUTO); | 
| 950 ASSERT_TRUE(cert); | 1078 ASSERT_TRUE(cert); | 
| 951 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, | 1079 error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), 0, NULL, | 
| 952 &verify_result); | 1080 CertificateList(), &verify_result); | 
| 953 EXPECT_THAT(error, IsOk()); | 1081 EXPECT_THAT(error, IsOk()); | 
| 954 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 1082 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 
| 955 | 1083 | 
| 956 // Publicly trusted SHA-1 intermediates issued on/after 1 January 2016 are, | 1084 // Publicly trusted SHA-1 intermediates issued on/after 1 January 2016 are, | 
| 957 // unfortunately, accepted. This can arise due to OS path building quirks. | 1085 // unfortunately, accepted. This can arise due to OS path building quirks. | 
| 958 verify_result.Reset(); | 1086 verify_result.Reset(); | 
| 959 dummy_result.Reset(); | 1087 dummy_result.Reset(); | 
| 960 dummy_result.is_issued_by_known_root = true; | 1088 dummy_result.is_issued_by_known_root = true; | 
| 961 dummy_result.has_sha1 = true; | 1089 dummy_result.has_sha1 = true; | 
| 962 dummy_result.has_sha1_leaf = false; | 1090 dummy_result.has_sha1_leaf = false; | 
| 963 verify_proc_ = new MockCertVerifyProc(dummy_result); | 1091 verify_proc = make_scoped_refptr(new MockCertVerifyProc(dummy_result)); | 
| 964 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), | 1092 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), | 
| 965 "sha1_jan_2016.pem", | 1093 "sha1_jan_2016.pem", | 
| 966 X509Certificate::FORMAT_AUTO); | 1094 X509Certificate::FORMAT_AUTO); | 
| 967 ASSERT_TRUE(cert); | 1095 ASSERT_TRUE(cert); | 
| 968 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, | 1096 error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), 0, NULL, | 
| 969 &verify_result); | 1097 CertificateList(), &verify_result); | 
| 970 EXPECT_THAT(error, IsOk()); | 1098 EXPECT_THAT(error, IsOk()); | 
| 971 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 1099 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 
| 972 } | 1100 } | 
| 973 | 1101 | 
| 974 // Test that the certificate returned in CertVerifyResult is able to reorder | 1102 // Test that the certificate returned in CertVerifyResult is able to reorder | 
| 975 // certificates that are not ordered from end-entity to root. While this is | 1103 // certificates that are not ordered from end-entity to root. While this is | 
| 976 // a protocol violation if sent during a TLS handshake, if multiple sources | 1104 // a protocol violation if sent during a TLS handshake, if multiple sources | 
| 977 // of intermediate certificates are combined, it's possible that order may | 1105 // of intermediate certificates are combined, it's possible that order may | 
| 978 // not be maintained. | 1106 // not be maintained. | 
| 979 TEST_F(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) { | 1107 TYPED_TEST(CertVerifyProcTypedTest, VerifyReturnChainProperlyOrdered) { | 
| 980 if (!SupportsReturningVerifiedChain()) { | 1108 if (!SupportsReturningVerifiedChain(this->verify_proc_.get())) { | 
| 981 LOG(INFO) << "Skipping this test in this platform."; | 1109 LOG(INFO) << "Skipping this test in this platform."; | 
| 982 return; | 1110 return; | 
| 983 } | 1111 } | 
| 984 | 1112 | 
| 985 base::FilePath certs_dir = GetTestCertsDirectory(); | 1113 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 986 CertificateList certs = CreateCertificateListFromFile( | 1114 CertificateList certs = CreateCertificateListFromFile( | 
| 987 certs_dir, "x509_verify_results.chain.pem", | 1115 certs_dir, "x509_verify_results.chain.pem", X509Certificate::FORMAT_AUTO); | 
| 988 X509Certificate::FORMAT_AUTO); | |
| 989 ASSERT_EQ(3U, certs.size()); | 1116 ASSERT_EQ(3U, certs.size()); | 
| 990 | 1117 | 
| 991 // Construct the chain out of order. | 1118 // Construct the chain out of order. | 
| 992 X509Certificate::OSCertHandles intermediates; | 1119 X509Certificate::OSCertHandles intermediates; | 
| 993 intermediates.push_back(certs[2]->os_cert_handle()); | 1120 intermediates.push_back(certs[2]->os_cert_handle()); | 
| 994 intermediates.push_back(certs[1]->os_cert_handle()); | 1121 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 995 | 1122 | 
| 996 ScopedTestRoot scoped_root(certs[2].get()); | 1123 ScopedTestRoot scoped_root(certs[2].get()); | 
| 997 | 1124 | 
| 998 scoped_refptr<X509Certificate> google_full_chain = | 1125 scoped_refptr<X509Certificate> google_full_chain = | 
| 999 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 1126 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 
| 1000 intermediates); | 1127 intermediates); | 
| 1001 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain.get()); | 1128 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain.get()); | 
| 1002 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); | 1129 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); | 
| 1003 | 1130 | 
| 1004 CertVerifyResult verify_result; | 1131 CertVerifyResult verify_result; | 
| 1005 EXPECT_EQ(static_cast<X509Certificate*>(NULL), | 1132 EXPECT_EQ(static_cast<X509Certificate*>(NULL), | 
| 1006 verify_result.verified_cert.get()); | 1133 verify_result.verified_cert.get()); | 
| 1007 int error = Verify(google_full_chain.get(), | 1134 int error = this->Verify(google_full_chain.get(), "127.0.0.1", 0, NULL, | 
| 1008 "127.0.0.1", | 1135 EmptyCertList(), &verify_result); | 
| 1009 0, | |
| 1010 NULL, | |
| 1011 empty_cert_list_, | |
| 1012 &verify_result); | |
| 1013 EXPECT_THAT(error, IsOk()); | 1136 EXPECT_THAT(error, IsOk()); | 
| 1014 ASSERT_NE(static_cast<X509Certificate*>(NULL), | 1137 ASSERT_NE(static_cast<X509Certificate*>(NULL), | 
| 1015 verify_result.verified_cert.get()); | 1138 verify_result.verified_cert.get()); | 
| 1016 | 1139 | 
| 1017 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 1140 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 
| 1018 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 1141 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 
| 1019 google_full_chain->os_cert_handle(), | 1142 google_full_chain->os_cert_handle(), | 
| 1020 verify_result.verified_cert->os_cert_handle())); | 1143 verify_result.verified_cert->os_cert_handle())); | 
| 1021 const X509Certificate::OSCertHandles& return_intermediates = | 1144 const X509Certificate::OSCertHandles& return_intermediates = | 
| 1022 verify_result.verified_cert->GetIntermediateCertificates(); | 1145 verify_result.verified_cert->GetIntermediateCertificates(); | 
| 1023 ASSERT_EQ(2U, return_intermediates.size()); | 1146 ASSERT_EQ(2U, return_intermediates.size()); | 
| 1024 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 1147 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 
| 1025 certs[1]->os_cert_handle())); | 1148 certs[1]->os_cert_handle())); | 
| 1026 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 1149 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 
| 1027 certs[2]->os_cert_handle())); | 1150 certs[2]->os_cert_handle())); | 
| 1028 } | 1151 } | 
| 1029 | 1152 | 
| 1030 // Test that Verify() filters out certificates which are not related to | 1153 // Test that Verify() filters out certificates which are not related to | 
| 1031 // or part of the certificate chain being verified. | 1154 // or part of the certificate chain being verified. | 
| 1032 TEST_F(CertVerifyProcTest, VerifyReturnChainFiltersUnrelatedCerts) { | 1155 TYPED_TEST(CertVerifyProcTypedTest, VerifyReturnChainFiltersUnrelatedCerts) { | 
| 1033 if (!SupportsReturningVerifiedChain()) { | 1156 if (!SupportsReturningVerifiedChain(this->verify_proc_.get())) { | 
| 1034 LOG(INFO) << "Skipping this test in this platform."; | 1157 LOG(INFO) << "Skipping this test in this platform."; | 
| 1035 return; | 1158 return; | 
| 1036 } | 1159 } | 
| 1037 | 1160 | 
| 1038 base::FilePath certs_dir = GetTestCertsDirectory(); | 1161 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 1039 CertificateList certs = CreateCertificateListFromFile( | 1162 CertificateList certs = CreateCertificateListFromFile( | 
| 1040 certs_dir, "x509_verify_results.chain.pem", | 1163 certs_dir, "x509_verify_results.chain.pem", X509Certificate::FORMAT_AUTO); | 
| 1041 X509Certificate::FORMAT_AUTO); | |
| 1042 ASSERT_EQ(3U, certs.size()); | 1164 ASSERT_EQ(3U, certs.size()); | 
| 1043 ScopedTestRoot scoped_root(certs[2].get()); | 1165 ScopedTestRoot scoped_root(certs[2].get()); | 
| 1044 | 1166 | 
| 1045 scoped_refptr<X509Certificate> unrelated_certificate = | 1167 scoped_refptr<X509Certificate> unrelated_certificate = | 
| 1046 ImportCertFromFile(certs_dir, "duplicate_cn_1.pem"); | 1168 ImportCertFromFile(certs_dir, "duplicate_cn_1.pem"); | 
| 1047 scoped_refptr<X509Certificate> unrelated_certificate2 = | 1169 scoped_refptr<X509Certificate> unrelated_certificate2 = | 
| 1048 ImportCertFromFile(certs_dir, "aia-cert.pem"); | 1170 ImportCertFromFile(certs_dir, "aia-cert.pem"); | 
| 1049 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_certificate.get()); | 1171 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_certificate.get()); | 
| 1050 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_certificate2.get()); | 1172 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_certificate2.get()); | 
| 1051 | 1173 | 
| 1052 // Interject unrelated certificates into the list of intermediates. | 1174 // Interject unrelated certificates into the list of intermediates. | 
| 1053 X509Certificate::OSCertHandles intermediates; | 1175 X509Certificate::OSCertHandles intermediates; | 
| 1054 intermediates.push_back(unrelated_certificate->os_cert_handle()); | 1176 intermediates.push_back(unrelated_certificate->os_cert_handle()); | 
| 1055 intermediates.push_back(certs[1]->os_cert_handle()); | 1177 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 1056 intermediates.push_back(unrelated_certificate2->os_cert_handle()); | 1178 intermediates.push_back(unrelated_certificate2->os_cert_handle()); | 
| 1057 intermediates.push_back(certs[2]->os_cert_handle()); | 1179 intermediates.push_back(certs[2]->os_cert_handle()); | 
| 1058 | 1180 | 
| 1059 scoped_refptr<X509Certificate> google_full_chain = | 1181 scoped_refptr<X509Certificate> google_full_chain = | 
| 1060 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 1182 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 
| 1061 intermediates); | 1183 intermediates); | 
| 1062 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain.get()); | 1184 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain.get()); | 
| 1063 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size()); | 1185 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size()); | 
| 1064 | 1186 | 
| 1065 CertVerifyResult verify_result; | 1187 CertVerifyResult verify_result; | 
| 1066 EXPECT_EQ(static_cast<X509Certificate*>(NULL), | 1188 EXPECT_EQ(static_cast<X509Certificate*>(NULL), | 
| 1067 verify_result.verified_cert.get()); | 1189 verify_result.verified_cert.get()); | 
| 1068 int error = Verify(google_full_chain.get(), | 1190 int error = this->Verify(google_full_chain.get(), "127.0.0.1", 0, NULL, | 
| 1069 "127.0.0.1", | 1191 EmptyCertList(), &verify_result); | 
| 1070 0, | |
| 1071 NULL, | |
| 1072 empty_cert_list_, | |
| 1073 &verify_result); | |
| 1074 EXPECT_THAT(error, IsOk()); | 1192 EXPECT_THAT(error, IsOk()); | 
| 1075 ASSERT_NE(static_cast<X509Certificate*>(NULL), | 1193 ASSERT_NE(static_cast<X509Certificate*>(NULL), | 
| 1076 verify_result.verified_cert.get()); | 1194 verify_result.verified_cert.get()); | 
| 1077 | 1195 | 
| 1078 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 1196 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 
| 1079 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 1197 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 
| 1080 google_full_chain->os_cert_handle(), | 1198 google_full_chain->os_cert_handle(), | 
| 1081 verify_result.verified_cert->os_cert_handle())); | 1199 verify_result.verified_cert->os_cert_handle())); | 
| 1082 const X509Certificate::OSCertHandles& return_intermediates = | 1200 const X509Certificate::OSCertHandles& return_intermediates = | 
| 1083 verify_result.verified_cert->GetIntermediateCertificates(); | 1201 verify_result.verified_cert->GetIntermediateCertificates(); | 
| 1084 ASSERT_EQ(2U, return_intermediates.size()); | 1202 ASSERT_EQ(2U, return_intermediates.size()); | 
| 1085 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 1203 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 
| 1086 certs[1]->os_cert_handle())); | 1204 certs[1]->os_cert_handle())); | 
| 1087 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 1205 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 
| 1088 certs[2]->os_cert_handle())); | 1206 certs[2]->os_cert_handle())); | 
| 1089 } | 1207 } | 
| 1090 | 1208 | 
| 1091 TEST_F(CertVerifyProcTest, AdditionalTrustAnchors) { | 1209 TYPED_TEST(CertVerifyProcTypedTest, AdditionalTrustAnchors) { | 
| 1092 if (!SupportsAdditionalTrustAnchors()) { | 1210 if (!this->SupportsAdditionalTrustAnchors()) { | 
| 1093 LOG(INFO) << "Skipping this test in this platform."; | 1211 LOG(INFO) << "Skipping this test in this platform."; | 
| 1094 return; | 1212 return; | 
| 1095 } | 1213 } | 
| 1096 | 1214 | 
| 1097 // |ca_cert| is the issuer of |cert|. | 1215 // |ca_cert| is the issuer of |cert|. | 
| 1098 CertificateList ca_cert_list = CreateCertificateListFromFile( | 1216 CertificateList ca_cert_list = | 
| 1099 GetTestCertsDirectory(), "root_ca_cert.pem", | 1217 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem", | 
| 1100 X509Certificate::FORMAT_AUTO); | 1218 X509Certificate::FORMAT_AUTO); | 
| 1101 ASSERT_EQ(1U, ca_cert_list.size()); | 1219 ASSERT_EQ(1U, ca_cert_list.size()); | 
| 1102 scoped_refptr<X509Certificate> ca_cert(ca_cert_list[0]); | 1220 scoped_refptr<X509Certificate> ca_cert(ca_cert_list[0]); | 
| 1103 | 1221 | 
| 1104 CertificateList cert_list = CreateCertificateListFromFile( | 1222 CertificateList cert_list = CreateCertificateListFromFile( | 
| 1105 GetTestCertsDirectory(), "ok_cert.pem", | 1223 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO); | 
| 1106 X509Certificate::FORMAT_AUTO); | |
| 1107 ASSERT_EQ(1U, cert_list.size()); | 1224 ASSERT_EQ(1U, cert_list.size()); | 
| 1108 scoped_refptr<X509Certificate> cert(cert_list[0]); | 1225 scoped_refptr<X509Certificate> cert(cert_list[0]); | 
| 1109 | 1226 | 
| 1110 // Verification of |cert| fails when |ca_cert| is not in the trust anchors | 1227 // Verification of |cert| fails when |ca_cert| is not in the trust anchors | 
| 1111 // list. | 1228 // list. | 
| 1112 int flags = 0; | 1229 int flags = 0; | 
| 1113 CertVerifyResult verify_result; | 1230 CertVerifyResult verify_result; | 
| 1114 int error = Verify( | 1231 int error = this->Verify(cert.get(), "127.0.0.1", flags, NULL, | 
| 1115 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 1232 EmptyCertList(), &verify_result); | 
| 1116 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 1233 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 
| 1117 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); | 1234 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); | 
| 1118 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); | 1235 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); | 
| 1119 | 1236 | 
| 1120 // Now add the |ca_cert| to the |trust_anchors|, and verification should pass. | 1237 // Now add the |ca_cert| to the |trust_anchors|, and verification should pass. | 
| 1121 CertificateList trust_anchors; | 1238 CertificateList trust_anchors; | 
| 1122 trust_anchors.push_back(ca_cert); | 1239 trust_anchors.push_back(ca_cert); | 
| 1123 error = Verify( | 1240 error = this->Verify(cert.get(), "127.0.0.1", flags, NULL, trust_anchors, | 
| 1124 cert.get(), "127.0.0.1", flags, NULL, trust_anchors, &verify_result); | 1241 &verify_result); | 
| 1125 EXPECT_THAT(error, IsOk()); | 1242 EXPECT_THAT(error, IsOk()); | 
| 1126 EXPECT_EQ(0U, verify_result.cert_status); | 1243 EXPECT_EQ(0U, verify_result.cert_status); | 
| 1127 EXPECT_TRUE(verify_result.is_issued_by_additional_trust_anchor); | 1244 EXPECT_TRUE(verify_result.is_issued_by_additional_trust_anchor); | 
| 1128 | 1245 | 
| 1129 // Clearing the |trust_anchors| makes verification fail again (the cache | 1246 // Clearing the |trust_anchors| makes verification fail again (the cache | 
| 1130 // should be skipped). | 1247 // should be skipped). | 
| 1131 error = Verify( | 1248 error = this->Verify(cert.get(), "127.0.0.1", flags, NULL, EmptyCertList(), | 
| 1132 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 1249 &verify_result); | 
| 1133 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 1250 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 
| 1134 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); | 1251 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); | 
| 1135 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); | 1252 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); | 
| 1136 } | 1253 } | 
| 1137 | 1254 | 
| 1138 // Tests that certificates issued by user-supplied roots are not flagged as | 1255 // Tests that certificates issued by user-supplied roots are not flagged as | 
| 1139 // issued by a known root. This should pass whether or not the platform supports | 1256 // issued by a known root. This should pass whether or not the platform supports | 
| 1140 // detecting known roots. | 1257 // detecting known roots. | 
| 1141 TEST_F(CertVerifyProcTest, IsIssuedByKnownRootIgnoresTestRoots) { | 1258 TYPED_TEST(CertVerifyProcTypedTest, IsIssuedByKnownRootIgnoresTestRoots) { | 
| 1142 // Load root_ca_cert.pem into the test root store. | 1259 // Load root_ca_cert.pem into the test root store. | 
| 1143 ScopedTestRoot test_root( | 1260 ScopedTestRoot test_root( | 
| 1144 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); | 1261 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); | 
| 1145 | 1262 | 
| 1146 scoped_refptr<X509Certificate> cert( | 1263 scoped_refptr<X509Certificate> cert( | 
| 1147 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1264 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 1148 | 1265 | 
| 1149 // Verification should pass. | 1266 // Verification should pass. | 
| 1150 int flags = 0; | 1267 int flags = 0; | 
| 1151 CertVerifyResult verify_result; | 1268 CertVerifyResult verify_result; | 
| 1152 int error = Verify( | 1269 int error = this->Verify(cert.get(), "127.0.0.1", flags, NULL, | 
| 1153 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 1270 EmptyCertList(), &verify_result); | 
| 1154 EXPECT_THAT(error, IsOk()); | 1271 EXPECT_THAT(error, IsOk()); | 
| 1155 EXPECT_EQ(0U, verify_result.cert_status); | 1272 EXPECT_EQ(0U, verify_result.cert_status); | 
| 1156 // But should not be marked as a known root. | 1273 // But should not be marked as a known root. | 
| 1157 EXPECT_FALSE(verify_result.is_issued_by_known_root); | 1274 EXPECT_FALSE(verify_result.is_issued_by_known_root); | 
| 1158 } | 1275 } | 
| 1159 | 1276 | 
| 1160 #if defined(USE_NSS_CERTS) || defined(OS_WIN) || \ | 1277 template <typename T> | 
| 1161 (defined(OS_MACOSX) && !defined(OS_IOS)) | 1278 bool SupportsCRLSet(T* verify_proc) { | 
| 1279 return false; | |
| 1280 } | |
| 1281 | |
| 1282 #if defined(USE_NSS_CERTS) | |
| 1283 template <> | |
| 1284 bool SupportsCRLSet(CertVerifyProcNSS* verify_proc) { | |
| 1285 return true; | |
| 1286 } | |
| 1287 #endif | |
| 1288 | |
| 1289 #if defined(OS_WIN) | |
| 1290 template <> | |
| 1291 bool SupportsCRLSet(CertVerifyProcWin* verify_proc) { | |
| 1292 return true; | |
| 1293 } | |
| 1294 #endif | |
| 1295 | |
| 1296 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
| 1297 template <> | |
| 1298 bool SupportsCRLSet(CertVerifyProcMac* verify_proc) { | |
| 1299 return true; | |
| 1300 } | |
| 1301 #endif | |
| 1302 | |
| 1162 // Test that CRLSets are effective in making a certificate appear to be | 1303 // Test that CRLSets are effective in making a certificate appear to be | 
| 1163 // revoked. | 1304 // revoked. | 
| 1164 TEST_F(CertVerifyProcTest, CRLSet) { | 1305 TYPED_TEST(CertVerifyProcTypedTest, CRLSet) { | 
| 1306 if (!SupportsCRLSet(this->verify_proc_.get())) { | |
| 1307 LOG(INFO) << "Skipping test as verifier doesn't support CRLSet"; | |
| 1308 return; | |
| 1309 } | |
| 1310 | |
| 1165 CertificateList ca_cert_list = | 1311 CertificateList ca_cert_list = | 
| 1166 CreateCertificateListFromFile(GetTestCertsDirectory(), | 1312 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem", | 
| 1167 "root_ca_cert.pem", | |
| 1168 X509Certificate::FORMAT_AUTO); | 1313 X509Certificate::FORMAT_AUTO); | 
| 1169 ASSERT_EQ(1U, ca_cert_list.size()); | 1314 ASSERT_EQ(1U, ca_cert_list.size()); | 
| 1170 ScopedTestRoot test_root(ca_cert_list[0].get()); | 1315 ScopedTestRoot test_root(ca_cert_list[0].get()); | 
| 1171 | 1316 | 
| 1172 CertificateList cert_list = CreateCertificateListFromFile( | 1317 CertificateList cert_list = CreateCertificateListFromFile( | 
| 1173 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO); | 1318 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO); | 
| 1174 ASSERT_EQ(1U, cert_list.size()); | 1319 ASSERT_EQ(1U, cert_list.size()); | 
| 1175 scoped_refptr<X509Certificate> cert(cert_list[0]); | 1320 scoped_refptr<X509Certificate> cert(cert_list[0]); | 
| 1176 | 1321 | 
| 1177 int flags = 0; | 1322 int flags = 0; | 
| 1178 CertVerifyResult verify_result; | 1323 CertVerifyResult verify_result; | 
| 1179 int error = Verify( | 1324 int error = this->Verify(cert.get(), "127.0.0.1", flags, NULL, | 
| 1180 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 1325 EmptyCertList(), &verify_result); | 
| 1181 EXPECT_THAT(error, IsOk()); | 1326 EXPECT_THAT(error, IsOk()); | 
| 1182 EXPECT_EQ(0U, verify_result.cert_status); | 1327 EXPECT_EQ(0U, verify_result.cert_status); | 
| 1183 | 1328 | 
| 1184 scoped_refptr<CRLSet> crl_set; | 1329 scoped_refptr<CRLSet> crl_set; | 
| 1185 std::string crl_set_bytes; | 1330 std::string crl_set_bytes; | 
| 1186 | 1331 | 
| 1187 // First test blocking by SPKI. | 1332 // First test blocking by SPKI. | 
| 1188 EXPECT_TRUE(base::ReadFileToString( | 1333 EXPECT_TRUE(base::ReadFileToString( | 
| 1189 GetTestCertsDirectory().AppendASCII("crlset_by_leaf_spki.raw"), | 1334 GetTestCertsDirectory().AppendASCII("crlset_by_leaf_spki.raw"), | 
| 1190 &crl_set_bytes)); | 1335 &crl_set_bytes)); | 
| 1191 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 1336 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 
| 1192 | 1337 | 
| 1193 error = Verify(cert.get(), | 1338 error = this->Verify(cert.get(), "127.0.0.1", flags, crl_set.get(), | 
| 1194 "127.0.0.1", | 1339 EmptyCertList(), &verify_result); | 
| 1195 flags, | |
| 1196 crl_set.get(), | |
| 1197 empty_cert_list_, | |
| 1198 &verify_result); | |
| 1199 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); | 1340 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); | 
| 1200 | 1341 | 
| 1201 // Second, test revocation by serial number of a cert directly under the | 1342 // Second, test revocation by serial number of a cert directly under the | 
| 1202 // root. | 1343 // root. | 
| 1203 crl_set_bytes.clear(); | 1344 crl_set_bytes.clear(); | 
| 1204 EXPECT_TRUE(base::ReadFileToString( | 1345 EXPECT_TRUE(base::ReadFileToString( | 
| 1205 GetTestCertsDirectory().AppendASCII("crlset_by_root_serial.raw"), | 1346 GetTestCertsDirectory().AppendASCII("crlset_by_root_serial.raw"), | 
| 1206 &crl_set_bytes)); | 1347 &crl_set_bytes)); | 
| 1207 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 1348 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 
| 1208 | 1349 | 
| 1209 error = Verify(cert.get(), | 1350 error = this->Verify(cert.get(), "127.0.0.1", flags, crl_set.get(), | 
| 1210 "127.0.0.1", | 1351 EmptyCertList(), &verify_result); | 
| 1211 flags, | |
| 1212 crl_set.get(), | |
| 1213 empty_cert_list_, | |
| 1214 &verify_result); | |
| 1215 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); | 1352 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); | 
| 1216 } | 1353 } | 
| 1217 | 1354 | 
| 1218 TEST_F(CertVerifyProcTest, CRLSetLeafSerial) { | 1355 TYPED_TEST(CertVerifyProcTypedTest, CRLSetLeafSerial) { | 
| 1356 if (!SupportsCRLSet(this->verify_proc_.get())) { | |
| 1357 LOG(INFO) << "Skipping test as verifier doesn't support CRLSet"; | |
| 1358 return; | |
| 1359 } | |
| 1360 | |
| 1219 CertificateList ca_cert_list = | 1361 CertificateList ca_cert_list = | 
| 1220 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem", | 1362 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem", | 
| 1221 X509Certificate::FORMAT_AUTO); | 1363 X509Certificate::FORMAT_AUTO); | 
| 1222 ASSERT_EQ(1U, ca_cert_list.size()); | 1364 ASSERT_EQ(1U, ca_cert_list.size()); | 
| 1223 ScopedTestRoot test_root(ca_cert_list[0].get()); | 1365 ScopedTestRoot test_root(ca_cert_list[0].get()); | 
| 1224 | 1366 | 
| 1225 CertificateList intermediate_cert_list = CreateCertificateListFromFile( | 1367 CertificateList intermediate_cert_list = CreateCertificateListFromFile( | 
| 1226 GetTestCertsDirectory(), "intermediate_ca_cert.pem", | 1368 GetTestCertsDirectory(), "intermediate_ca_cert.pem", | 
| 1227 X509Certificate::FORMAT_AUTO); | 1369 X509Certificate::FORMAT_AUTO); | 
| 1228 ASSERT_EQ(1U, intermediate_cert_list.size()); | 1370 ASSERT_EQ(1U, intermediate_cert_list.size()); | 
| 1229 X509Certificate::OSCertHandles intermediates; | 1371 X509Certificate::OSCertHandles intermediates; | 
| 1230 intermediates.push_back(intermediate_cert_list[0]->os_cert_handle()); | 1372 intermediates.push_back(intermediate_cert_list[0]->os_cert_handle()); | 
| 1231 | 1373 | 
| 1232 CertificateList cert_list = CreateCertificateListFromFile( | 1374 CertificateList cert_list = CreateCertificateListFromFile( | 
| 1233 GetTestCertsDirectory(), "ok_cert_by_intermediate.pem", | 1375 GetTestCertsDirectory(), "ok_cert_by_intermediate.pem", | 
| 1234 X509Certificate::FORMAT_AUTO); | 1376 X509Certificate::FORMAT_AUTO); | 
| 1235 ASSERT_EQ(1U, cert_list.size()); | 1377 ASSERT_EQ(1U, cert_list.size()); | 
| 1236 | 1378 | 
| 1237 scoped_refptr<X509Certificate> leaf = X509Certificate::CreateFromHandle( | 1379 scoped_refptr<X509Certificate> leaf = X509Certificate::CreateFromHandle( | 
| 1238 cert_list[0]->os_cert_handle(), intermediates); | 1380 cert_list[0]->os_cert_handle(), intermediates); | 
| 1239 ASSERT_TRUE(leaf); | 1381 ASSERT_TRUE(leaf); | 
| 1240 | 1382 | 
| 1241 int flags = 0; | 1383 int flags = 0; | 
| 1242 CertVerifyResult verify_result; | 1384 CertVerifyResult verify_result; | 
| 1243 int error = Verify(leaf.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 1385 int error = this->Verify(leaf.get(), "127.0.0.1", flags, NULL, | 
| 1244 &verify_result); | 1386 EmptyCertList(), &verify_result); | 
| 1245 EXPECT_THAT(error, IsOk()); | 1387 EXPECT_THAT(error, IsOk()); | 
| 1246 | 1388 | 
| 1247 // Test revocation by serial number of a certificate not under the root. | 1389 // Test revocation by serial number of a certificate not under the root. | 
| 1248 scoped_refptr<CRLSet> crl_set; | 1390 scoped_refptr<CRLSet> crl_set; | 
| 1249 std::string crl_set_bytes; | 1391 std::string crl_set_bytes; | 
| 1250 ASSERT_TRUE(base::ReadFileToString( | 1392 ASSERT_TRUE(base::ReadFileToString( | 
| 1251 GetTestCertsDirectory().AppendASCII("crlset_by_intermediate_serial.raw"), | 1393 GetTestCertsDirectory().AppendASCII("crlset_by_intermediate_serial.raw"), | 
| 1252 &crl_set_bytes)); | 1394 &crl_set_bytes)); | 
| 1253 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 1395 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 
| 1254 | 1396 | 
| 1255 error = Verify(leaf.get(), "127.0.0.1", flags, crl_set.get(), | 1397 error = this->Verify(leaf.get(), "127.0.0.1", flags, crl_set.get(), | 
| 1256 empty_cert_list_, &verify_result); | 1398 EmptyCertList(), &verify_result); | 
| 1257 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); | 1399 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); | 
| 1258 } | 1400 } | 
| 1259 | 1401 | 
| 1260 // Tests that CRLSets participate in path building functions, and that as | 1402 // Tests that CRLSets participate in path building functions, and that as | 
| 1261 // long as a valid path exists within the verification graph, verification | 1403 // long as a valid path exists within the verification graph, verification | 
| 1262 // succeeds. | 1404 // succeeds. | 
| 1263 // | 1405 // | 
| 1264 // In this test, there are two roots (D and E), and three possible paths | 1406 // In this test, there are two roots (D and E), and three possible paths | 
| 1265 // to validate a leaf (A): | 1407 // to validate a leaf (A): | 
| 1266 // 1. A(B) -> B(C) -> C(D) -> D(D) | 1408 // 1. A(B) -> B(C) -> C(D) -> D(D) | 
| 1267 // 2. A(B) -> B(C) -> C(E) -> E(E) | 1409 // 2. A(B) -> B(C) -> C(E) -> E(E) | 
| 1268 // 3. A(B) -> B(F) -> F(E) -> E(E) | 1410 // 3. A(B) -> B(F) -> F(E) -> E(E) | 
| 1269 // | 1411 // | 
| 1270 // Each permutation of revocation is tried: | 1412 // Each permutation of revocation is tried: | 
| 1271 // 1. Revoking E by SPKI, so that only Path 1 is valid (as E is in Paths 2 & 3) | 1413 // 1. Revoking E by SPKI, so that only Path 1 is valid (as E is in Paths 2 & 3) | 
| 1272 // 2. Revoking C(D) and F(E) by serial, so that only Path 2 is valid. | 1414 // 2. Revoking C(D) and F(E) by serial, so that only Path 2 is valid. | 
| 1273 // 3. Revoking C by SPKI, so that only Path 3 is valid (as C is in Paths 1 & 2) | 1415 // 3. Revoking C by SPKI, so that only Path 3 is valid (as C is in Paths 1 & 2) | 
| 1274 TEST_F(CertVerifyProcTest, CRLSetDuringPathBuilding) { | 1416 TYPED_TEST(CertVerifyProcTypedTest, CRLSetDuringPathBuilding) { | 
| 1275 if (!SupportsCRLSetsInPathBuilding()) { | 1417 if (!SupportsCRLSetsInPathBuilding(this->verify_proc_.get())) { | 
| 1276 LOG(INFO) << "Skipping this test on this platform."; | 1418 LOG(INFO) << "Skipping this test on this platform."; | 
| 1277 return; | 1419 return; | 
| 1278 } | 1420 } | 
| 1279 | 1421 | 
| 1280 const char* const kPath1Files[] = { | 1422 const char* const kPath1Files[] = { | 
| 1281 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-D.pem", | 1423 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-D.pem", | 
| 1282 "multi-root-D-by-D.pem"}; | 1424 "multi-root-D-by-D.pem"}; | 
| 1283 const char* const kPath2Files[] = { | 1425 const char* const kPath2Files[] = { | 
| 1284 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-E.pem", | 1426 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-E.pem", | 
| 1285 "multi-root-E-by-E.pem"}; | 1427 "multi-root-E-by-E.pem"}; | 
| 1286 const char* const kPath3Files[] = { | 1428 const char* const kPath3Files[] = { | 
| 1287 "multi-root-A-by-B.pem", "multi-root-B-by-F.pem", "multi-root-F-by-E.pem", | 1429 "multi-root-A-by-B.pem", "multi-root-B-by-F.pem", "multi-root-F-by-E.pem", | 
| 1288 "multi-root-E-by-E.pem"}; | 1430 "multi-root-E-by-E.pem"}; | 
| 1289 | 1431 | 
| 1290 CertificateList path_1_certs; | 1432 CertificateList path_1_certs; | 
| 1291 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath1Files, &path_1_certs)); | 1433 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath1Files, &path_1_certs)); | 
| 1292 | 1434 | 
| 1293 CertificateList path_2_certs; | 1435 CertificateList path_2_certs; | 
| 1294 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath2Files, &path_2_certs)); | 1436 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath2Files, &path_2_certs)); | 
| 1295 | 1437 | 
| 1296 CertificateList path_3_certs; | 1438 CertificateList path_3_certs; | 
| 1297 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath3Files, &path_3_certs)); | 1439 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath3Files, &path_3_certs)); | 
| 1298 | 1440 | 
| 1299 // Add D and E as trust anchors. | 1441 // Add D and E as trust anchors. | 
| 1300 ScopedTestRoot test_root_D(path_1_certs[3].get()); // D-by-D | 1442 ScopedTestRoot test_root_D(path_1_certs[3].get()); // D-by-D | 
| 1301 ScopedTestRoot test_root_E(path_2_certs[3].get()); // E-by-E | 1443 ScopedTestRoot test_root_E(path_2_certs[3].get()); // E-by-E | 
| 1302 | 1444 | 
| 1303 // Create a chain that contains all the certificate paths possible. | 1445 // Create a chain that contains all the certificate paths possible. | 
| 1304 // CertVerifyProcTest.VerifyReturnChainFiltersUnrelatedCerts already | 1446 // CertVerifyProcTypedTest.VerifyReturnChainFiltersUnrelatedCerts already | 
| 1305 // ensures that it's safe to send additional certificates as inputs, and | 1447 // ensures that it's safe to send additional certificates as inputs, and | 
| 1306 // that they're ignored if not necessary. | 1448 // that they're ignored if not necessary. | 
| 1307 // This is to avoid relying on AIA or internal object caches when | 1449 // This is to avoid relying on AIA or internal object caches when | 
| 1308 // interacting with the underlying library. | 1450 // interacting with the underlying library. | 
| 1309 X509Certificate::OSCertHandles intermediates; | 1451 X509Certificate::OSCertHandles intermediates; | 
| 1310 intermediates.push_back(path_1_certs[1]->os_cert_handle()); // B-by-C | 1452 intermediates.push_back(path_1_certs[1]->os_cert_handle()); // B-by-C | 
| 1311 intermediates.push_back(path_1_certs[2]->os_cert_handle()); // C-by-D | 1453 intermediates.push_back(path_1_certs[2]->os_cert_handle()); // C-by-D | 
| 1312 intermediates.push_back(path_2_certs[2]->os_cert_handle()); // C-by-E | 1454 intermediates.push_back(path_2_certs[2]->os_cert_handle()); // C-by-E | 
| 1313 intermediates.push_back(path_3_certs[1]->os_cert_handle()); // B-by-F | 1455 intermediates.push_back(path_3_certs[1]->os_cert_handle()); // B-by-F | 
| 1314 intermediates.push_back(path_3_certs[2]->os_cert_handle()); // F-by-E | 1456 intermediates.push_back(path_3_certs[2]->os_cert_handle()); // F-by-E | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1330 for (const auto& testcase : kTests) { | 1472 for (const auto& testcase : kTests) { | 
| 1331 SCOPED_TRACE(testcase.crlset); | 1473 SCOPED_TRACE(testcase.crlset); | 
| 1332 scoped_refptr<CRLSet> crl_set; | 1474 scoped_refptr<CRLSet> crl_set; | 
| 1333 std::string crl_set_bytes; | 1475 std::string crl_set_bytes; | 
| 1334 EXPECT_TRUE(base::ReadFileToString( | 1476 EXPECT_TRUE(base::ReadFileToString( | 
| 1335 GetTestCertsDirectory().AppendASCII(testcase.crlset), &crl_set_bytes)); | 1477 GetTestCertsDirectory().AppendASCII(testcase.crlset), &crl_set_bytes)); | 
| 1336 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 1478 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 
| 1337 | 1479 | 
| 1338 int flags = 0; | 1480 int flags = 0; | 
| 1339 CertVerifyResult verify_result; | 1481 CertVerifyResult verify_result; | 
| 1340 int error = Verify(cert.get(), "127.0.0.1", flags, crl_set.get(), | 1482 int error = this->Verify(cert.get(), "127.0.0.1", flags, crl_set.get(), | 
| 1341 empty_cert_list_, &verify_result); | 1483 EmptyCertList(), &verify_result); | 
| 1342 | 1484 | 
| 1343 if (!testcase.expect_valid) { | 1485 if (!testcase.expect_valid) { | 
| 1344 EXPECT_NE(OK, error); | 1486 EXPECT_NE(OK, error); | 
| 1345 EXPECT_NE(0U, verify_result.cert_status); | 1487 EXPECT_NE(0U, verify_result.cert_status); | 
| 1346 continue; | 1488 continue; | 
| 1347 } | 1489 } | 
| 1348 | 1490 | 
| 1349 ASSERT_THAT(error, IsOk()); | 1491 ASSERT_THAT(error, IsOk()); | 
| 1350 ASSERT_EQ(0U, verify_result.cert_status); | 1492 ASSERT_EQ(0U, verify_result.cert_status); | 
| 1351 ASSERT_TRUE(verify_result.verified_cert.get()); | 1493 ASSERT_TRUE(verify_result.verified_cert.get()); | 
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1363 ASSERT_TRUE(intermediate); | 1505 ASSERT_TRUE(intermediate); | 
| 1364 | 1506 | 
| 1365 EXPECT_TRUE(testcase.expected_intermediate->Equals(intermediate.get())) | 1507 EXPECT_TRUE(testcase.expected_intermediate->Equals(intermediate.get())) | 
| 1366 << "Expected: " << testcase.expected_intermediate->subject().common_name | 1508 << "Expected: " << testcase.expected_intermediate->subject().common_name | 
| 1367 << " issued by " << testcase.expected_intermediate->issuer().common_name | 1509 << " issued by " << testcase.expected_intermediate->issuer().common_name | 
| 1368 << "; Got: " << intermediate->subject().common_name << " issued by " | 1510 << "; Got: " << intermediate->subject().common_name << " issued by " | 
| 1369 << intermediate->issuer().common_name; | 1511 << intermediate->issuer().common_name; | 
| 1370 } | 1512 } | 
| 1371 } | 1513 } | 
| 1372 | 1514 | 
| 1373 #endif | 1515 #if defined(OS_MACOSX) && !defined(OS_IOS) | 
| 1516 class CertVerifyProcMacTest | |
| 1517 : public CertVerifyProcTypedTest<CertVerifyProcMac> {}; | |
| 1374 | 1518 | 
| 1375 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
| 1376 // Test that a CRLSet blocking one of the intermediates supplied by the server | 1519 // Test that a CRLSet blocking one of the intermediates supplied by the server | 
| 1377 // can be worked around by the chopping workaround for path building. (Once the | 1520 // can be worked around by the chopping workaround for path building. (Once the | 
| 1378 // supplied chain is chopped back to just the target, a better path can be | 1521 // supplied chain is chopped back to just the target, a better path can be | 
| 1379 // found out-of-band. Normally that would be by AIA fetching, for the purposes | 1522 // found out-of-band. Normally that would be by AIA fetching, for the purposes | 
| 1380 // of this test the better path is supplied by a test keychain.) | 1523 // of this test the better path is supplied by a test keychain.) | 
| 1381 // | 1524 // | 
| 1382 // In this test, there are two possible paths to validate a leaf (A): | 1525 // In this test, there are two possible paths to validate a leaf (A): | 
| 1383 // 1. A(B) -> B(C) -> C(E) -> E(E) | 1526 // 1. A(B) -> B(C) -> C(E) -> E(E) | 
| 1384 // 2. A(B) -> B(F) -> F(E) -> E(E) | 1527 // 2. A(B) -> B(F) -> F(E) -> E(E) | 
| 1385 // | 1528 // | 
| 1386 // A(B) -> B(C) -> C(E) is supplied to the verifier. | 1529 // A(B) -> B(C) -> C(E) is supplied to the verifier. | 
| 1387 // B(F) and F(E) are supplied in a test keychain. | 1530 // B(F) and F(E) are supplied in a test keychain. | 
| 1388 // C is blocked by a CRLset. | 1531 // C is blocked by a CRLset. | 
| 1389 // | 1532 // | 
| 1390 // The verifier should rollback until it just tries A(B) alone, at which point | 1533 // The verifier should rollback until it just tries A(B) alone, at which point | 
| 1391 // it will pull B(F) & F(E) from the keychain and succeed. | 1534 // it will pull B(F) & F(E) from the keychain and succeed. | 
| 1392 TEST_F(CertVerifyProcTest, MacCRLIntermediate) { | 1535 TEST_F(CertVerifyProcMacTest, MacCRLIntermediate) { | 
| 1393 if (base::mac::IsAtLeastOS10_12()) { | 1536 if (base::mac::IsAtLeastOS10_12()) { | 
| 1394 // TODO(crbug.com/671889): Investigate SecTrustSetKeychains issue on Sierra. | 1537 // TODO(crbug.com/671889): Investigate SecTrustSetKeychains issue on Sierra. | 
| 1395 LOG(INFO) << "Skipping test, SecTrustSetKeychains does not work on 10.12"; | 1538 LOG(INFO) << "Skipping test, SecTrustSetKeychains does not work on 10.12"; | 
| 1396 return; | 1539 return; | 
| 1397 } | 1540 } | 
| 1398 const char* const kPath2Files[] = { | 1541 const char* const kPath2Files[] = { | 
| 1399 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-E.pem", | 1542 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-E.pem", | 
| 1400 "multi-root-E-by-E.pem"}; | 1543 "multi-root-E-by-E.pem"}; | 
| 1401 CertificateList path_2_certs; | 1544 CertificateList path_2_certs; | 
| 1402 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath2Files, &path_2_certs)); | 1545 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath2Files, &path_2_certs)); | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1439 std::string crl_set_bytes; | 1582 std::string crl_set_bytes; | 
| 1440 // CRL which blocks C by SPKI. | 1583 // CRL which blocks C by SPKI. | 
| 1441 EXPECT_TRUE(base::ReadFileToString( | 1584 EXPECT_TRUE(base::ReadFileToString( | 
| 1442 GetTestCertsDirectory().AppendASCII("multi-root-crlset-C.raw"), | 1585 GetTestCertsDirectory().AppendASCII("multi-root-crlset-C.raw"), | 
| 1443 &crl_set_bytes)); | 1586 &crl_set_bytes)); | 
| 1444 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 1587 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 
| 1445 | 1588 | 
| 1446 int flags = 0; | 1589 int flags = 0; | 
| 1447 CertVerifyResult verify_result; | 1590 CertVerifyResult verify_result; | 
| 1448 int error = Verify(cert.get(), "127.0.0.1", flags, crl_set.get(), | 1591 int error = Verify(cert.get(), "127.0.0.1", flags, crl_set.get(), | 
| 1449 empty_cert_list_, &verify_result); | 1592 EmptyCertList(), &verify_result); | 
| 1450 | 1593 | 
| 1451 ASSERT_EQ(OK, error); | 1594 ASSERT_EQ(OK, error); | 
| 1452 ASSERT_EQ(0U, verify_result.cert_status); | 1595 ASSERT_EQ(0U, verify_result.cert_status); | 
| 1453 ASSERT_TRUE(verify_result.verified_cert.get()); | 1596 ASSERT_TRUE(verify_result.verified_cert.get()); | 
| 1454 | 1597 | 
| 1455 const X509Certificate::OSCertHandles& verified_intermediates = | 1598 const X509Certificate::OSCertHandles& verified_intermediates = | 
| 1456 verify_result.verified_cert->GetIntermediateCertificates(); | 1599 verify_result.verified_cert->GetIntermediateCertificates(); | 
| 1457 ASSERT_EQ(3U, verified_intermediates.size()); | 1600 ASSERT_EQ(3U, verified_intermediates.size()); | 
| 1458 | 1601 | 
| 1459 scoped_refptr<X509Certificate> intermediate = | 1602 scoped_refptr<X509Certificate> intermediate = | 
| 1460 X509Certificate::CreateFromHandle(verified_intermediates[1], | 1603 X509Certificate::CreateFromHandle(verified_intermediates[1], | 
| 1461 X509Certificate::OSCertHandles()); | 1604 X509Certificate::OSCertHandles()); | 
| 1462 ASSERT_TRUE(intermediate); | 1605 ASSERT_TRUE(intermediate); | 
| 1463 | 1606 | 
| 1464 scoped_refptr<X509Certificate> expected_intermediate = path_3_certs[2]; | 1607 scoped_refptr<X509Certificate> expected_intermediate = path_3_certs[2]; | 
| 1465 EXPECT_TRUE(expected_intermediate->Equals(intermediate.get())) | 1608 EXPECT_TRUE(expected_intermediate->Equals(intermediate.get())) | 
| 1466 << "Expected: " << expected_intermediate->subject().common_name | 1609 << "Expected: " << expected_intermediate->subject().common_name | 
| 1467 << " issued by " << expected_intermediate->issuer().common_name | 1610 << " issued by " << expected_intermediate->issuer().common_name | 
| 1468 << "; Got: " << intermediate->subject().common_name << " issued by " | 1611 << "; Got: " << intermediate->subject().common_name << " issued by " | 
| 1469 << intermediate->issuer().common_name; | 1612 << intermediate->issuer().common_name; | 
| 1470 } | 1613 } | 
| 1471 | 1614 | 
| 1472 // Test that if a keychain is present which trusts a less-desirable root (ex, | 1615 // Test that if a keychain is present which trusts a less-desirable root (ex, | 
| 1473 // one using SHA1), that the keychain reordering hack will cause the better | 1616 // one using SHA1), that the keychain reordering hack will cause the better | 
| 1474 // root in the System Roots to be used instead. | 1617 // root in the System Roots to be used instead. | 
| 1475 TEST_F(CertVerifyProcTest, MacKeychainReordering) { | 1618 TEST_F(CertVerifyProcMacTest, MacKeychainReordering) { | 
| 1476 // Note: target cert expires Apr 2 23:59:59 2018 GMT | 1619 // Note: target cert expires Apr 2 23:59:59 2018 GMT | 
| 1477 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( | 1620 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( | 
| 1478 GetTestCertsDirectory(), "tripadvisor-verisign-chain.pem", | 1621 GetTestCertsDirectory(), "tripadvisor-verisign-chain.pem", | 
| 1479 X509Certificate::FORMAT_AUTO); | 1622 X509Certificate::FORMAT_AUTO); | 
| 1480 ASSERT_TRUE(cert); | 1623 ASSERT_TRUE(cert); | 
| 1481 | 1624 | 
| 1482 // Create a test keychain search list that will Always Trust the SHA1 | 1625 // Create a test keychain search list that will Always Trust the SHA1 | 
| 1483 // cross-signed VeriSign Class 3 Public Primary Certification Authority - G5 | 1626 // cross-signed VeriSign Class 3 Public Primary Certification Authority - G5 | 
| 1484 std::unique_ptr<TestKeychainSearchList> test_keychain_search_list( | 1627 std::unique_ptr<TestKeychainSearchList> test_keychain_search_list( | 
| 1485 TestKeychainSearchList::Create()); | 1628 TestKeychainSearchList::Create()); | 
| 1486 ASSERT_TRUE(test_keychain_search_list); | 1629 ASSERT_TRUE(test_keychain_search_list); | 
| 1487 | 1630 | 
| 1488 base::FilePath keychain_path(GetTestCertsDirectory().AppendASCII( | 1631 base::FilePath keychain_path(GetTestCertsDirectory().AppendASCII( | 
| 1489 "verisign_class3_g5_crosssigned-trusted.keychain")); | 1632 "verisign_class3_g5_crosssigned-trusted.keychain")); | 
| 1490 // SecKeychainOpen does not fail if the file doesn't exist, so assert it here | 1633 // SecKeychainOpen does not fail if the file doesn't exist, so assert it here | 
| 1491 // for easier debugging. | 1634 // for easier debugging. | 
| 1492 ASSERT_TRUE(base::PathExists(keychain_path)); | 1635 ASSERT_TRUE(base::PathExists(keychain_path)); | 
| 1493 SecKeychainRef keychain; | 1636 SecKeychainRef keychain; | 
| 1494 OSStatus status = | 1637 OSStatus status = | 
| 1495 SecKeychainOpen(keychain_path.MaybeAsASCII().c_str(), &keychain); | 1638 SecKeychainOpen(keychain_path.MaybeAsASCII().c_str(), &keychain); | 
| 1496 ASSERT_EQ(errSecSuccess, status); | 1639 ASSERT_EQ(errSecSuccess, status); | 
| 1497 ASSERT_TRUE(keychain); | 1640 ASSERT_TRUE(keychain); | 
| 1498 base::ScopedCFTypeRef<SecKeychainRef> scoped_keychain(keychain); | 1641 base::ScopedCFTypeRef<SecKeychainRef> scoped_keychain(keychain); | 
| 1499 test_keychain_search_list->AddKeychain(keychain); | 1642 test_keychain_search_list->AddKeychain(keychain); | 
| 1500 | 1643 | 
| 1501 int flags = 0; | 1644 int flags = 0; | 
| 1502 CertVerifyResult verify_result; | 1645 CertVerifyResult verify_result; | 
| 1503 int error = Verify(cert.get(), "www.tripadvisor.com", flags, | 1646 int error = Verify(cert.get(), "www.tripadvisor.com", flags, | 
| 1504 nullptr /* crl_set */, empty_cert_list_, &verify_result); | 1647 nullptr /* crl_set */, EmptyCertList(), &verify_result); | 
| 1505 | 1648 | 
| 1506 ASSERT_EQ(OK, error); | 1649 ASSERT_EQ(OK, error); | 
| 1507 EXPECT_EQ(0U, verify_result.cert_status); | 1650 EXPECT_EQ(0U, verify_result.cert_status); | 
| 1508 EXPECT_FALSE(verify_result.has_sha1); | 1651 EXPECT_FALSE(verify_result.has_sha1); | 
| 1509 ASSERT_TRUE(verify_result.verified_cert.get()); | 1652 ASSERT_TRUE(verify_result.verified_cert.get()); | 
| 1510 | 1653 | 
| 1511 const X509Certificate::OSCertHandles& verified_intermediates = | 1654 const X509Certificate::OSCertHandles& verified_intermediates = | 
| 1512 verify_result.verified_cert->GetIntermediateCertificates(); | 1655 verify_result.verified_cert->GetIntermediateCertificates(); | 
| 1513 ASSERT_EQ(2U, verified_intermediates.size()); | 1656 ASSERT_EQ(2U, verified_intermediates.size()); | 
| 1514 } | 1657 } | 
| 1515 | 1658 | 
| 1516 // Test that the system root certificate keychain is in the expected location | 1659 // Test that the system root certificate keychain is in the expected location | 
| 1517 // and can be opened. Other tests would fail if this was not true, but this | 1660 // and can be opened. Other tests would fail if this was not true, but this | 
| 1518 // test makes the reason for the failure obvious. | 1661 // test makes the reason for the failure obvious. | 
| 1519 TEST_F(CertVerifyProcTest, MacSystemRootCertificateKeychainLocation) { | 1662 TEST_F(CertVerifyProcMacTest, MacSystemRootCertificateKeychainLocation) { | 
| 1520 const char* root_keychain_path = | 1663 const char* root_keychain_path = | 
| 1521 "/System/Library/Keychains/SystemRootCertificates.keychain"; | 1664 "/System/Library/Keychains/SystemRootCertificates.keychain"; | 
| 1522 ASSERT_TRUE(base::PathExists(base::FilePath(root_keychain_path))); | 1665 ASSERT_TRUE(base::PathExists(base::FilePath(root_keychain_path))); | 
| 1523 | 1666 | 
| 1524 SecKeychainRef keychain; | 1667 SecKeychainRef keychain; | 
| 1525 OSStatus status = SecKeychainOpen(root_keychain_path, &keychain); | 1668 OSStatus status = SecKeychainOpen(root_keychain_path, &keychain); | 
| 1526 ASSERT_EQ(errSecSuccess, status); | 1669 ASSERT_EQ(errSecSuccess, status); | 
| 1527 CFRelease(keychain); | 1670 CFRelease(keychain); | 
| 1528 } | 1671 } | 
| 1529 #endif | 1672 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 
| 1530 | 1673 | 
| 1674 // TODO(crbug.com/649017): This is not parameterized by the CertVerifyProc | |
| 1675 // because the CertVerifyProc::Verify() does this unconditionally based on the | |
| 1676 // platform. | |
| 1531 bool AreSHA1IntermediatesAllowed() { | 1677 bool AreSHA1IntermediatesAllowed() { | 
| 1532 #if defined(OS_WIN) | 1678 #if defined(OS_WIN) | 
| 1533 // TODO(rsleevi): Remove this once https://crbug.com/588789 is resolved | 1679 // TODO(rsleevi): Remove this once https://crbug.com/588789 is resolved | 
| 1534 // for Windows 7/2008 users. | 1680 // for Windows 7/2008 users. | 
| 1535 // Note: This must be kept in sync with cert_verify_proc.cc | 1681 // Note: This must be kept in sync with cert_verify_proc.cc | 
| 1536 return base::win::GetVersion() < base::win::VERSION_WIN8; | 1682 return base::win::GetVersion() < base::win::VERSION_WIN8; | 
| 1537 #else | 1683 #else | 
| 1538 return false; | 1684 return false; | 
| 1539 #endif | 1685 #endif | 
| 1540 } | 1686 } | 
| 1541 | 1687 | 
| 1542 TEST_F(CertVerifyProcTest, RejectsMD2) { | 1688 TEST_F(CertVerifyProcBaseClassTest, RejectsMD2) { | 
| 1543 scoped_refptr<X509Certificate> cert( | 1689 scoped_refptr<X509Certificate> cert( | 
| 1544 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1690 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 1545 ASSERT_TRUE(cert); | 1691 ASSERT_TRUE(cert); | 
| 1546 | 1692 | 
| 1547 CertVerifyResult result; | 1693 CertVerifyResult result; | 
| 1548 result.has_md2 = true; | 1694 result.has_md2 = true; | 
| 1549 verify_proc_ = new MockCertVerifyProc(result); | 1695 auto verify_proc = make_scoped_refptr(new MockCertVerifyProc(result)); | 
| 1550 | 1696 | 
| 1551 int flags = 0; | 1697 int flags = 0; | 
| 1552 CertVerifyResult verify_result; | 1698 CertVerifyResult verify_result; | 
| 1553 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 1699 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 
| 1554 empty_cert_list_, &verify_result); | 1700 nullptr /* crl_set */, CertificateList(), | 
| 1701 &verify_result); | |
| 1555 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 1702 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 
| 1556 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 1703 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 
| 1557 } | 1704 } | 
| 1558 | 1705 | 
| 1559 TEST_F(CertVerifyProcTest, RejectsMD4) { | 1706 TEST_F(CertVerifyProcBaseClassTest, RejectsMD4) { | 
| 1560 scoped_refptr<X509Certificate> cert( | 1707 scoped_refptr<X509Certificate> cert( | 
| 1561 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1708 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 1562 ASSERT_TRUE(cert); | 1709 ASSERT_TRUE(cert); | 
| 1563 | 1710 | 
| 1564 CertVerifyResult result; | 1711 CertVerifyResult result; | 
| 1565 result.has_md4 = true; | 1712 result.has_md4 = true; | 
| 1566 verify_proc_ = new MockCertVerifyProc(result); | 1713 auto verify_proc = make_scoped_refptr(new MockCertVerifyProc(result)); | 
| 1567 | 1714 | 
| 1568 int flags = 0; | 1715 int flags = 0; | 
| 1569 CertVerifyResult verify_result; | 1716 CertVerifyResult verify_result; | 
| 1570 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 1717 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 
| 1571 empty_cert_list_, &verify_result); | 1718 nullptr /* crl_set */, CertificateList(), | 
| 1719 &verify_result); | |
| 1572 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 1720 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 
| 1573 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 1721 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 
| 1574 } | 1722 } | 
| 1575 | 1723 | 
| 1576 TEST_F(CertVerifyProcTest, RejectsMD5) { | 1724 TEST_F(CertVerifyProcBaseClassTest, RejectsMD5) { | 
| 1577 scoped_refptr<X509Certificate> cert( | 1725 scoped_refptr<X509Certificate> cert( | 
| 1578 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1726 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 1579 ASSERT_TRUE(cert); | 1727 ASSERT_TRUE(cert); | 
| 1580 | 1728 | 
| 1581 CertVerifyResult result; | 1729 CertVerifyResult result; | 
| 1582 result.has_md5 = true; | 1730 result.has_md5 = true; | 
| 1583 verify_proc_ = new MockCertVerifyProc(result); | 1731 auto verify_proc = make_scoped_refptr(new MockCertVerifyProc(result)); | 
| 1584 | 1732 | 
| 1585 int flags = 0; | 1733 int flags = 0; | 
| 1586 CertVerifyResult verify_result; | 1734 CertVerifyResult verify_result; | 
| 1587 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 1735 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 
| 1588 empty_cert_list_, &verify_result); | 1736 nullptr /* crl_set */, CertificateList(), | 
| 1737 &verify_result); | |
| 1589 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 1738 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 
| 1590 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 1739 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 
| 1591 } | 1740 } | 
| 1592 | 1741 | 
| 1593 TEST_F(CertVerifyProcTest, RejectsPublicSHA1Leaves) { | 1742 TEST_F(CertVerifyProcBaseClassTest, RejectsPublicSHA1Leaves) { | 
| 1594 scoped_refptr<X509Certificate> cert( | 1743 scoped_refptr<X509Certificate> cert( | 
| 1595 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1744 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 1596 ASSERT_TRUE(cert); | 1745 ASSERT_TRUE(cert); | 
| 1597 | 1746 | 
| 1598 CertVerifyResult result; | 1747 CertVerifyResult result; | 
| 1599 result.has_sha1 = true; | 1748 result.has_sha1 = true; | 
| 1600 result.has_sha1_leaf = true; | 1749 result.has_sha1_leaf = true; | 
| 1601 result.is_issued_by_known_root = true; | 1750 result.is_issued_by_known_root = true; | 
| 1602 verify_proc_ = new MockCertVerifyProc(result); | 1751 auto verify_proc = make_scoped_refptr(new MockCertVerifyProc(result)); | 
| 1603 | 1752 | 
| 1604 int flags = 0; | 1753 int flags = 0; | 
| 1605 CertVerifyResult verify_result; | 1754 CertVerifyResult verify_result; | 
| 1606 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 1755 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 
| 1607 empty_cert_list_, &verify_result); | 1756 nullptr /* crl_set */, CertificateList(), | 
| 1757 &verify_result); | |
| 1608 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 1758 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 
| 1609 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 1759 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 
| 1610 } | 1760 } | 
| 1611 | 1761 | 
| 1612 TEST_F(CertVerifyProcTest, RejectsPublicSHA1IntermediatesUnlessAllowed) { | 1762 TEST_F(CertVerifyProcBaseClassTest, | 
| 1763 RejectsPublicSHA1IntermediatesUnlessAllowed) { | |
| 1613 scoped_refptr<X509Certificate> cert(ImportCertFromFile( | 1764 scoped_refptr<X509Certificate> cert(ImportCertFromFile( | 
| 1614 GetTestCertsDirectory(), "39_months_after_2015_04.pem")); | 1765 GetTestCertsDirectory(), "39_months_after_2015_04.pem")); | 
| 1615 ASSERT_TRUE(cert); | 1766 ASSERT_TRUE(cert); | 
| 1616 | 1767 | 
| 1617 CertVerifyResult result; | 1768 CertVerifyResult result; | 
| 1618 result.has_sha1 = true; | 1769 result.has_sha1 = true; | 
| 1619 result.has_sha1_leaf = false; | 1770 result.has_sha1_leaf = false; | 
| 1620 result.is_issued_by_known_root = true; | 1771 result.is_issued_by_known_root = true; | 
| 1621 verify_proc_ = new MockCertVerifyProc(result); | 1772 auto verify_proc = make_scoped_refptr(new MockCertVerifyProc(result)); | 
| 1622 | 1773 | 
| 1623 int flags = 0; | 1774 int flags = 0; | 
| 1624 CertVerifyResult verify_result; | 1775 CertVerifyResult verify_result; | 
| 1625 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 1776 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 
| 1626 empty_cert_list_, &verify_result); | 1777 nullptr /* crl_set */, CertificateList(), | 
| 1778 &verify_result); | |
| 1627 if (AreSHA1IntermediatesAllowed()) { | 1779 if (AreSHA1IntermediatesAllowed()) { | 
| 1628 EXPECT_THAT(error, IsOk()); | 1780 EXPECT_THAT(error, IsOk()); | 
| 1629 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 1781 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 
| 1630 } else { | 1782 } else { | 
| 1631 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 1783 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 
| 1632 EXPECT_TRUE(verify_result.cert_status & | 1784 EXPECT_TRUE(verify_result.cert_status & | 
| 1633 CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 1785 CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 
| 1634 } | 1786 } | 
| 1635 } | 1787 } | 
| 1636 | 1788 | 
| 1637 TEST_F(CertVerifyProcTest, RejectsPrivateSHA1UnlessFlag) { | 1789 TEST_F(CertVerifyProcBaseClassTest, RejectsPrivateSHA1UnlessFlag) { | 
| 1638 scoped_refptr<X509Certificate> cert( | 1790 scoped_refptr<X509Certificate> cert( | 
| 1639 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1791 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 1640 ASSERT_TRUE(cert); | 1792 ASSERT_TRUE(cert); | 
| 1641 | 1793 | 
| 1642 CertVerifyResult result; | 1794 CertVerifyResult result; | 
| 1643 result.has_sha1 = true; | 1795 result.has_sha1 = true; | 
| 1644 result.has_sha1_leaf = true; | 1796 result.has_sha1_leaf = true; | 
| 1645 result.is_issued_by_known_root = false; | 1797 result.is_issued_by_known_root = false; | 
| 1646 verify_proc_ = new MockCertVerifyProc(result); | 1798 auto verify_proc = make_scoped_refptr(new MockCertVerifyProc(result)); | 
| 1647 | 1799 | 
| 1648 // SHA-1 should be rejected by default for private roots... | 1800 // SHA-1 should be rejected by default for private roots... | 
| 1649 int flags = 0; | 1801 int flags = 0; | 
| 1650 CertVerifyResult verify_result; | 1802 CertVerifyResult verify_result; | 
| 1651 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 1803 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 
| 1652 empty_cert_list_, &verify_result); | 1804 nullptr /* crl_set */, CertificateList(), | 
| 1805 &verify_result); | |
| 1653 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 1806 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 
| 1654 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 1807 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 
| 1655 | 1808 | 
| 1656 // ... unless VERIFY_ENABLE_SHA1_LOCAL_ANCHORS was supplied. | 1809 // ... unless VERIFY_ENABLE_SHA1_LOCAL_ANCHORS was supplied. | 
| 1657 flags = CertVerifier::VERIFY_ENABLE_SHA1_LOCAL_ANCHORS; | 1810 flags = CertVerifier::VERIFY_ENABLE_SHA1_LOCAL_ANCHORS; | 
| 1658 verify_result.Reset(); | 1811 verify_result.Reset(); | 
| 1659 error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 1812 error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 
| 1660 empty_cert_list_, &verify_result); | 1813 nullptr /* crl_set */, CertificateList(), | 
| 1814 &verify_result); | |
| 1661 EXPECT_THAT(error, IsOk()); | 1815 EXPECT_THAT(error, IsOk()); | 
| 1662 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 1816 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 
| 1663 } | 1817 } | 
| 1664 | 1818 | 
| 1665 enum ExpectedAlgorithms { | 1819 enum ExpectedAlgorithms { | 
| 1666 EXPECT_MD2 = 1 << 0, | 1820 EXPECT_MD2 = 1 << 0, | 
| 1667 EXPECT_MD4 = 1 << 1, | 1821 EXPECT_MD4 = 1 << 1, | 
| 1668 EXPECT_MD5 = 1 << 2, | 1822 EXPECT_MD5 = 1 << 2, | 
| 1669 EXPECT_SHA1 = 1 << 3, | 1823 EXPECT_SHA1 = 1 << 3, | 
| 1670 EXPECT_SHA1_LEAF = 1 << 4, | 1824 EXPECT_SHA1_LEAF = 1 << 4, | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1687 // to output the parameter that was passed. Without this, it will simply | 1841 // to output the parameter that was passed. Without this, it will simply | 
| 1688 // attempt to print out the first twenty bytes of the object, which depending | 1842 // attempt to print out the first twenty bytes of the object, which depending | 
| 1689 // on platform and alignment, may result in an invalid read. | 1843 // on platform and alignment, may result in an invalid read. | 
| 1690 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { | 1844 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { | 
| 1691 *os << "root: " << StringOrDefault(data.root_cert_filename, "none") | 1845 *os << "root: " << StringOrDefault(data.root_cert_filename, "none") | 
| 1692 << "; intermediate: " | 1846 << "; intermediate: " | 
| 1693 << StringOrDefault(data.intermediate_cert_filename, "none") | 1847 << StringOrDefault(data.intermediate_cert_filename, "none") | 
| 1694 << "; end-entity: " << data.ee_cert_filename; | 1848 << "; end-entity: " << data.ee_cert_filename; | 
| 1695 } | 1849 } | 
| 1696 | 1850 | 
| 1851 // Tests to ensure that CertVerifyProc::Verify() sets the has_* members for | |
| 1852 // hash algorithms. | |
| 1697 class CertVerifyProcWeakDigestTest | 1853 class CertVerifyProcWeakDigestTest | 
| 1698 : public CertVerifyProcTest, | 1854 : public CertVerifyProcBaseClassTest, | 
| 1699 public testing::WithParamInterface<WeakDigestTestData> { | 1855 public testing::WithParamInterface<WeakDigestTestData> { | 
| 1700 public: | 1856 public: | 
| 1701 CertVerifyProcWeakDigestTest() {} | 1857 CertVerifyProcWeakDigestTest() {} | 
| 1702 virtual ~CertVerifyProcWeakDigestTest() {} | 1858 virtual ~CertVerifyProcWeakDigestTest() {} | 
| 1703 }; | 1859 }; | 
| 1704 | 1860 | 
| 1705 // Test that the CertVerifyProc::Verify() properly surfaces the (weak) hashing | 1861 // Tests that the CertVerifyProc::Verify() properly surfaces the (weak) hash | 
| 1706 // algorithms used in the chain. | 1862 // algorithms used in the chain. | 
| 1707 TEST_P(CertVerifyProcWeakDigestTest, VerifyDetectsAlgorithm) { | 1863 TEST_P(CertVerifyProcWeakDigestTest, VerifyDetectsAlgorithm) { | 
| 1708 WeakDigestTestData data = GetParam(); | 1864 WeakDigestTestData data = GetParam(); | 
| 1709 base::FilePath certs_dir = GetTestCertsDirectory(); | 1865 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 1710 | 1866 | 
| 1711 scoped_refptr<X509Certificate> intermediate_cert; | 1867 scoped_refptr<X509Certificate> intermediate_cert; | 
| 1712 scoped_refptr<X509Certificate> root_cert; | 1868 scoped_refptr<X509Certificate> root_cert; | 
| 1713 | 1869 | 
| 1714 // Build |intermediates| as the full chain (including trust anchor). | 1870 // Build |intermediates| as the full chain (including trust anchor). | 
| 1715 X509Certificate::OSCertHandles intermediates; | 1871 X509Certificate::OSCertHandles intermediates; | 
| 1716 | 1872 | 
| 1717 if (data.intermediate_cert_filename) { | 1873 if (data.intermediate_cert_filename) { | 
| 1718 intermediate_cert = | 1874 intermediate_cert = | 
| 1719 ImportCertFromFile(certs_dir, data.intermediate_cert_filename); | 1875 ImportCertFromFile(certs_dir, data.intermediate_cert_filename); | 
| 1720 ASSERT_TRUE(intermediate_cert); | 1876 ASSERT_TRUE(intermediate_cert); | 
| 1721 intermediates.push_back(intermediate_cert->os_cert_handle()); | 1877 intermediates.push_back(intermediate_cert->os_cert_handle()); | 
| 1722 } | 1878 } | 
| 1723 | 1879 | 
| 1724 if (data.root_cert_filename) { | 1880 if (data.root_cert_filename) { | 
| 1725 root_cert = ImportCertFromFile(certs_dir, data.root_cert_filename); | 1881 root_cert = ImportCertFromFile(certs_dir, data.root_cert_filename); | 
| 1726 ASSERT_TRUE(root_cert); | 1882 ASSERT_TRUE(root_cert); | 
| 1727 intermediates.push_back(root_cert->os_cert_handle()); | 1883 intermediates.push_back(root_cert->os_cert_handle()); | 
| 1728 } | 1884 } | 
| 1729 | 1885 | 
| 1730 scoped_refptr<X509Certificate> ee_cert = | 1886 scoped_refptr<X509Certificate> ee_cert = | 
| 1731 ImportCertFromFile(certs_dir, data.ee_cert_filename); | 1887 ImportCertFromFile(certs_dir, data.ee_cert_filename); | 
| 1732 ASSERT_TRUE(ee_cert); | 1888 ASSERT_TRUE(ee_cert); | 
| 1733 | 1889 | 
| 1734 scoped_refptr<X509Certificate> ee_chain = | 1890 scoped_refptr<X509Certificate> ee_chain = X509Certificate::CreateFromHandle( | 
| 1735 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), | 1891 ee_cert->os_cert_handle(), intermediates); | 
| 1736 intermediates); | |
| 1737 ASSERT_TRUE(ee_chain); | 1892 ASSERT_TRUE(ee_chain); | 
| 1738 | 1893 | 
| 1739 int flags = 0; | 1894 int flags = 0; | 
| 1740 CertVerifyResult verify_result; | 1895 CertVerifyResult verify_result; | 
| 1741 | 1896 | 
| 1742 // Use a mock CertVerifyProc that returns success with a verified_cert of | 1897 // Use a mock CertVerifyProc that returns success with a verified_cert of | 
| 1743 // |ee_chain|. | 1898 // |ee_chain|. | 
| 1744 // | 1899 // | 
| 1745 // This is sufficient for the purposes of this test, as the checking for weak | 1900 // This is sufficient for the purposes of this test, as the checking for weak | 
| 1746 // hashing algorithms is done by CertVerifyProc::Verify(). | 1901 // hash algorithms is done by CertVerifyProc::Verify(). | 
| 1747 scoped_refptr<CertVerifyProc> proc = | 1902 scoped_refptr<CertVerifyProc> proc = | 
| 1748 new MockCertVerifyProc(CertVerifyResult()); | 1903 new MockCertVerifyProc(CertVerifyResult()); | 
| 1749 proc->Verify(ee_chain.get(), "127.0.0.1", std::string(), flags, nullptr, | 1904 proc->Verify(ee_chain.get(), "127.0.0.1", std::string(), flags, nullptr, | 
| 1750 empty_cert_list_, &verify_result); | 1905 CertificateList(), &verify_result); | 
| 1751 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD2), verify_result.has_md2); | 1906 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD2), verify_result.has_md2); | 
| 1752 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD4), verify_result.has_md4); | 1907 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD4), verify_result.has_md4); | 
| 1753 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD5), verify_result.has_md5); | 1908 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD5), verify_result.has_md5); | 
| 1754 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1), verify_result.has_sha1); | 1909 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1), verify_result.has_sha1); | 
| 1755 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1_LEAF), | 1910 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1_LEAF), | 
| 1756 verify_result.has_sha1_leaf); | 1911 verify_result.has_sha1_leaf); | 
| 1757 } | 1912 } | 
| 1758 | 1913 | 
| 1759 // The signature algorithm of the root CA should not matter. | 1914 // The signature algorithm of the root CA should not matter. | 
| 1760 const WeakDigestTestData kVerifyRootCATestData[] = { | 1915 const WeakDigestTestData kVerifyRootCATestData[] = { | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1778 {"weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", | 1933 {"weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", | 
| 1779 "weak_digest_sha1_ee.pem", EXPECT_MD2 | EXPECT_SHA1 | EXPECT_SHA1_LEAF}, | 1934 "weak_digest_sha1_ee.pem", EXPECT_MD2 | EXPECT_SHA1 | EXPECT_SHA1_LEAF}, | 
| 1780 }; | 1935 }; | 
| 1781 | 1936 | 
| 1782 INSTANTIATE_TEST_CASE_P(VerifyIntermediate, | 1937 INSTANTIATE_TEST_CASE_P(VerifyIntermediate, | 
| 1783 CertVerifyProcWeakDigestTest, | 1938 CertVerifyProcWeakDigestTest, | 
| 1784 testing::ValuesIn(kVerifyIntermediateCATestData)); | 1939 testing::ValuesIn(kVerifyIntermediateCATestData)); | 
| 1785 | 1940 | 
| 1786 // The signature algorithm of end-entity should be properly detected. | 1941 // The signature algorithm of end-entity should be properly detected. | 
| 1787 const WeakDigestTestData kVerifyEndEntityTestData[] = { | 1942 const WeakDigestTestData kVerifyEndEntityTestData[] = { | 
| 1788 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", | 1943 {"weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", | 
| 1789 "weak_digest_md5_ee.pem", EXPECT_MD5 | EXPECT_SHA1 }, | 1944 "weak_digest_md5_ee.pem", EXPECT_MD5 | EXPECT_SHA1}, | 
| 1790 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", | 1945 {"weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", | 
| 1791 "weak_digest_md4_ee.pem", EXPECT_MD4 | EXPECT_SHA1 }, | 1946 "weak_digest_md4_ee.pem", EXPECT_MD4 | EXPECT_SHA1}, | 
| 1792 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", | 1947 {"weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", | 
| 1793 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_SHA1 }, | 1948 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_SHA1}, | 
| 1794 }; | 1949 }; | 
| 1795 | 1950 | 
| 1796 INSTANTIATE_TEST_CASE_P(VerifyEndEntity, | 1951 INSTANTIATE_TEST_CASE_P(VerifyEndEntity, | 
| 1797 CertVerifyProcWeakDigestTest, | 1952 CertVerifyProcWeakDigestTest, | 
| 1798 testing::ValuesIn(kVerifyEndEntityTestData)); | 1953 testing::ValuesIn(kVerifyEndEntityTestData)); | 
| 1799 | 1954 | 
| 1800 // Incomplete chains do not report the status of the intermediate. | 1955 // Incomplete chains do not report the status of the intermediate. | 
| 1801 // Note: really each of these tests should also expect the digest algorithm of | 1956 // Note: really each of these tests should also expect the digest algorithm of | 
| 1802 // the intermediate (included as a comment). However CertVerifyProc::Verify() is | 1957 // the intermediate (included as a comment). However CertVerifyProc::Verify() is | 
| 1803 // unable to distinguish that this is an intermediate and not a trust anchor, so | 1958 // unable to distinguish that this is an intermediate and not a trust anchor, so | 
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1830 /*EXPECT_SHA1 |*/ EXPECT_MD2}, | 1985 /*EXPECT_SHA1 |*/ EXPECT_MD2}, | 
| 1831 }; | 1986 }; | 
| 1832 | 1987 | 
| 1833 INSTANTIATE_TEST_CASE_P(VerifyIncompleteEndEntity, | 1988 INSTANTIATE_TEST_CASE_P(VerifyIncompleteEndEntity, | 
| 1834 CertVerifyProcWeakDigestTest, | 1989 CertVerifyProcWeakDigestTest, | 
| 1835 testing::ValuesIn(kVerifyIncompleteEETestData)); | 1990 testing::ValuesIn(kVerifyIncompleteEETestData)); | 
| 1836 | 1991 | 
| 1837 // Differing algorithms between the intermediate and the EE should still be | 1992 // Differing algorithms between the intermediate and the EE should still be | 
| 1838 // reported. | 1993 // reported. | 
| 1839 const WeakDigestTestData kVerifyMixedTestData[] = { | 1994 const WeakDigestTestData kVerifyMixedTestData[] = { | 
| 1840 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem", | 1995 {"weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem", | 
| 1841 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_MD5 }, | 1996 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_MD5}, | 
| 1842 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", | 1997 {"weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", | 
| 1843 "weak_digest_md5_ee.pem", EXPECT_MD2 | EXPECT_MD5 }, | 1998 "weak_digest_md5_ee.pem", EXPECT_MD2 | EXPECT_MD5}, | 
| 1844 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem", | 1999 {"weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem", | 
| 1845 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_MD4 }, | 2000 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_MD4}, | 
| 1846 }; | 2001 }; | 
| 1847 | 2002 | 
| 1848 INSTANTIATE_TEST_CASE_P(VerifyMixed, | 2003 INSTANTIATE_TEST_CASE_P(VerifyMixed, | 
| 1849 CertVerifyProcWeakDigestTest, | 2004 CertVerifyProcWeakDigestTest, | 
| 1850 testing::ValuesIn(kVerifyMixedTestData)); | 2005 testing::ValuesIn(kVerifyMixedTestData)); | 
| 1851 | 2006 | 
| 1852 // The EE is a trusted certificate. Even though it uses weak hashes, these | 2007 // The EE is a trusted certificate. Even though it uses weak hashes, these | 
| 1853 // should not be reported. | 2008 // should not be reported. | 
| 1854 const WeakDigestTestData kVerifyTrustedEETestData[] = { | 2009 const WeakDigestTestData kVerifyTrustedEETestData[] = { | 
| 1855 {NULL, NULL, "weak_digest_md5_ee.pem", 0}, | 2010 {NULL, NULL, "weak_digest_md5_ee.pem", 0}, | 
| 1856 {NULL, NULL, "weak_digest_md4_ee.pem", 0}, | 2011 {NULL, NULL, "weak_digest_md4_ee.pem", 0}, | 
| 1857 {NULL, NULL, "weak_digest_md2_ee.pem", 0}, | 2012 {NULL, NULL, "weak_digest_md2_ee.pem", 0}, | 
| 1858 {NULL, NULL, "weak_digest_sha1_ee.pem", 0}, | 2013 {NULL, NULL, "weak_digest_sha1_ee.pem", 0}, | 
| 1859 }; | 2014 }; | 
| 1860 | 2015 | 
| 1861 INSTANTIATE_TEST_CASE_P(VerifyTrustedEE, | 2016 INSTANTIATE_TEST_CASE_P(VerifyTrustedEE, | 
| 1862 CertVerifyProcWeakDigestTest, | 2017 CertVerifyProcWeakDigestTest, | 
| 1863 testing::ValuesIn(kVerifyTrustedEETestData)); | 2018 testing::ValuesIn(kVerifyTrustedEETestData)); | 
| 1864 | 2019 | 
| 1865 // For the list of valid hostnames, see | 2020 // For the list of valid hostnames, see | 
| 1866 // net/cert/data/ssl/certificates/subjectAltName_sanity_check.pem | 2021 // net/cert/data/ssl/certificates/subjectAltName_sanity_check.pem | 
| 1867 static const struct CertVerifyProcNameData { | 2022 struct CertVerifyProcNameData { | 
| 1868 const char* hostname; | 2023 const char* hostname; | 
| 1869 bool valid; // Whether or not |hostname| matches a subjectAltName. | 2024 bool valid; // Whether or not |hostname| matches a subjectAltName. | 
| 1870 } kVerifyNameData[] = { | |
| 1871 { "127.0.0.1", false }, // Don't match the common name | |
| 1872 { "127.0.0.2", true }, // Matches the iPAddress SAN (IPv4) | |
| 1873 { "FE80:0:0:0:0:0:0:1", true }, // Matches the iPAddress SAN (IPv6) | |
| 1874 { "[FE80:0:0:0:0:0:0:1]", false }, // Should not match the iPAddress SAN | |
| 1875 { "FE80::1", true }, // Compressed form matches the iPAddress SAN (IPv6) | |
| 1876 { "::127.0.0.2", false }, // IPv6 mapped form should NOT match iPAddress SAN | |
| 1877 { "test.example", true }, // Matches the dNSName SAN | |
| 1878 { "test.example.", true }, // Matches the dNSName SAN (trailing . ignored) | |
| 1879 { "www.test.example", false }, // Should not match the dNSName SAN | |
| 1880 { "test..example", false }, // Should not match the dNSName SAN | |
| 1881 { "test.example..", false }, // Should not match the dNSName SAN | |
| 1882 { ".test.example.", false }, // Should not match the dNSName SAN | |
| 1883 { ".test.example", false }, // Should not match the dNSName SAN | |
| 1884 }; | 2025 }; | 
| 1885 | 2026 | 
| 1886 // GTest 'magic' pretty-printer, so that if/when a test fails, it knows how | 2027 // Don't match the common name | 
| 1887 // to output the parameter that was passed. Without this, it will simply | 2028 TYPED_TEST(CertVerifyProcTypedTest, DontMatchCommonName) { | 
| 1888 // attempt to print out the first twenty bytes of the object, which depending | 2029 this->VerifyCertName("127.0.0.1", false); | 
| 1889 // on platform and alignment, may result in an invalid read. | |
| 1890 void PrintTo(const CertVerifyProcNameData& data, std::ostream* os) { | |
| 1891 *os << "Hostname: " << data.hostname << "; valid=" << data.valid; | |
| 1892 } | 2030 } | 
| 1893 | 2031 | 
| 1894 class CertVerifyProcNameTest | 2032 // Matches the iPAddress SAN (IPv4) | 
| 1895 : public CertVerifyProcTest, | 2033 TYPED_TEST(CertVerifyProcTypedTest, MatchesIpSanIpv4) { | 
| 1896 public testing::WithParamInterface<CertVerifyProcNameData> { | 2034 this->VerifyCertName("127.0.0.2", true); | 
| 1897 public: | |
| 1898 CertVerifyProcNameTest() {} | |
| 1899 virtual ~CertVerifyProcNameTest() {} | |
| 1900 }; | |
| 1901 | |
| 1902 TEST_P(CertVerifyProcNameTest, VerifyCertName) { | |
| 1903 CertVerifyProcNameData data = GetParam(); | |
| 1904 | |
| 1905 CertificateList cert_list = CreateCertificateListFromFile( | |
| 1906 GetTestCertsDirectory(), "subjectAltName_sanity_check.pem", | |
| 1907 X509Certificate::FORMAT_AUTO); | |
| 1908 ASSERT_EQ(1U, cert_list.size()); | |
| 1909 scoped_refptr<X509Certificate> cert(cert_list[0]); | |
| 1910 | |
| 1911 ScopedTestRoot scoped_root(cert.get()); | |
| 1912 | |
| 1913 CertVerifyResult verify_result; | |
| 1914 int error = Verify(cert.get(), data.hostname, 0, NULL, empty_cert_list_, | |
| 1915 &verify_result); | |
| 1916 if (data.valid) { | |
| 1917 EXPECT_THAT(error, IsOk()); | |
| 1918 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); | |
| 1919 } else { | |
| 1920 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); | |
| 1921 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); | |
| 1922 } | |
| 1923 } | 2035 } | 
| 1924 | 2036 | 
| 1925 INSTANTIATE_TEST_CASE_P(VerifyName, | 2037 // Matches the iPAddress SAN (IPv6) | 
| 1926 CertVerifyProcNameTest, | 2038 TYPED_TEST(CertVerifyProcTypedTest, MatchesIpSanIpv6) { | 
| 1927 testing::ValuesIn(kVerifyNameData)); | 2039 this->VerifyCertName("FE80:0:0:0:0:0:0:1", true); | 
| 2040 } | |
| 2041 | |
| 2042 // Should not match the iPAddress SAN | |
| 2043 TYPED_TEST(CertVerifyProcTypedTest, DoesntMatchIpSanIpv6) { | |
| 2044 this->VerifyCertName("[FE80:0:0:0:0:0:0:1]", false); | |
| 2045 } | |
| 2046 | |
| 2047 // Compressed form matches the iPAddress SAN (IPv6) | |
| 2048 TYPED_TEST(CertVerifyProcTypedTest, MatchesIpSanCompressedIpv6) { | |
| 2049 this->VerifyCertName("FE80::1", true); | |
| 2050 } | |
| 2051 | |
| 2052 // IPv6 mapped form should NOT match iPAddress SAN | |
| 2053 TYPED_TEST(CertVerifyProcTypedTest, DoesntMatchIpSanIPv6Mapped) { | |
| 2054 this->VerifyCertName("::127.0.0.2", false); | |
| 2055 } | |
| 2056 | |
| 2057 // Matches the dNSName SAN | |
| 2058 TYPED_TEST(CertVerifyProcTypedTest, MatchesDnsSan) { | |
| 2059 this->VerifyCertName("test.example", true); | |
| 2060 } | |
| 2061 | |
| 2062 // Matches the dNSName SAN (trailing . ignored) | |
| 2063 TYPED_TEST(CertVerifyProcTypedTest, MatchesDnsSanTrailingDot) { | |
| 2064 this->VerifyCertName("test.example.", true); | |
| 2065 } | |
| 2066 | |
| 2067 // Should not match the dNSName SAN | |
| 2068 TYPED_TEST(CertVerifyProcTypedTest, DoesntMatchDnsSan) { | |
| 2069 this->VerifyCertName("www.test.example", false); | |
| 2070 } | |
| 2071 | |
| 2072 // Should not match the dNSName SAN | |
| 2073 TYPED_TEST(CertVerifyProcTypedTest, DoesntMatchDnsSanInvalid) { | |
| 2074 this->VerifyCertName("test..example", false); | |
| 2075 } | |
| 2076 | |
| 2077 // Should not match the dNSName SAN | |
| 2078 TYPED_TEST(CertVerifyProcTypedTest, DoesntMatchDnsSanTwoTrailingDots) { | |
| 2079 this->VerifyCertName("test.example..", false); | |
| 2080 } | |
| 2081 | |
| 2082 // Should not match the dNSName SAN | |
| 2083 TYPED_TEST(CertVerifyProcTypedTest, DoesntMatchDnsSanLeadingAndTrailingDot) { | |
| 2084 this->VerifyCertName(".test.example.", false); | |
| 2085 } | |
| 2086 | |
| 2087 // Should not match the dNSName SAN | |
| 2088 TYPED_TEST(CertVerifyProcTypedTest, DoesntMatchDnsSanTrailingDot) { | |
| 2089 this->VerifyCertName(".test.example", false); | |
| 2090 } | |
| 1928 | 2091 | 
| 1929 #if defined(OS_MACOSX) && !defined(OS_IOS) | 2092 #if defined(OS_MACOSX) && !defined(OS_IOS) | 
| 1930 // Test that CertVerifyProcMac reacts appropriately when Apple's certificate | 2093 // Test that CertVerifyProcMac reacts appropriately when Apple's certificate | 
| 1931 // verifier rejects a certificate with a fatal error. This is a regression | 2094 // verifier rejects a certificate with a fatal error. This is a regression | 
| 1932 // test for https://crbug.com/472291. | 2095 // test for https://crbug.com/472291. | 
| 1933 // (Since 10.12, this causes a recoverable error instead of a fatal one.) | 2096 // (Since 10.12, this causes a recoverable error instead of a fatal one.) | 
| 1934 // TODO(mattm): Try to find a different way to cause a fatal error that works | 2097 // TODO(mattm): Try to find a different way to cause a fatal error that works | 
| 1935 // on 10.12. | 2098 // on 10.12. | 
| 1936 TEST_F(CertVerifyProcTest, LargeKey) { | 2099 TEST_F(CertVerifyProcMacTest, LargeKey) { | 
| 1937 // Load root_ca_cert.pem into the test root store. | 2100 // Load root_ca_cert.pem into the test root store. | 
| 1938 ScopedTestRoot test_root( | 2101 ScopedTestRoot test_root( | 
| 1939 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); | 2102 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); | 
| 1940 | 2103 | 
| 1941 scoped_refptr<X509Certificate> cert( | 2104 scoped_refptr<X509Certificate> cert( | 
| 1942 ImportCertFromFile(GetTestCertsDirectory(), "large_key.pem")); | 2105 ImportCertFromFile(GetTestCertsDirectory(), "large_key.pem")); | 
| 1943 | 2106 | 
| 1944 // Apple's verifier rejects this certificate as invalid because the | 2107 // Apple's verifier rejects this certificate as invalid because the | 
| 1945 // RSA key is too large. If a future version of OS X changes this, | 2108 // RSA key is too large. If a future version of OS X changes this, | 
| 1946 // large_key.pem may need to be regenerated with a larger key. | 2109 // large_key.pem may need to be regenerated with a larger key. | 
| 1947 int flags = 0; | 2110 int flags = 0; | 
| 1948 CertVerifyResult verify_result; | 2111 CertVerifyResult verify_result; | 
| 1949 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 2112 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, EmptyCertList(), | 
| 1950 &verify_result); | 2113 &verify_result); | 
| 1951 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 2114 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 
| 1952 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 2115 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 
| 1953 } | 2116 } | 
| 1954 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 2117 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 
| 1955 | 2118 | 
| 1956 // Tests that CertVerifyProc records a histogram correctly when a | 2119 // Tests that CertVerifyProc records a histogram correctly when a | 
| 1957 // certificate chaining to a private root contains the TLS feature | 2120 // certificate chaining to a private root contains the TLS feature | 
| 1958 // extension and does not have a stapled OCSP response. | 2121 // extension and does not have a stapled OCSP response. | 
| 1959 TEST_F(CertVerifyProcTest, HasTLSFeatureExtensionUMA) { | 2122 TEST_F(CertVerifyProcBaseClassTest, HasTLSFeatureExtensionUMA) { | 
| 1960 base::HistogramTester histograms; | 2123 base::HistogramTester histograms; | 
| 1961 scoped_refptr<X509Certificate> cert( | 2124 scoped_refptr<X509Certificate> cert( | 
| 1962 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); | 2125 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); | 
| 1963 ASSERT_TRUE(cert); | 2126 ASSERT_TRUE(cert); | 
| 1964 CertVerifyResult result; | 2127 CertVerifyResult result; | 
| 1965 result.is_issued_by_known_root = false; | 2128 result.is_issued_by_known_root = false; | 
| 1966 verify_proc_ = new MockCertVerifyProc(result); | 2129 auto verify_proc = make_scoped_refptr(new MockCertVerifyProc(result)); | 
| 1967 | 2130 | 
| 1968 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2131 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 
| 1969 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2132 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 
| 1970 | 2133 | 
| 1971 int flags = 0; | 2134 int flags = 0; | 
| 1972 CertVerifyResult verify_result; | 2135 CertVerifyResult verify_result; | 
| 1973 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 2136 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 
| 1974 &verify_result); | 2137 NULL, EmptyCertList(), &verify_result); | 
| 1975 EXPECT_EQ(OK, error); | 2138 EXPECT_EQ(OK, error); | 
| 1976 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); | 2139 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); | 
| 1977 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, true, 1); | 2140 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, true, 1); | 
| 1978 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 1); | 2141 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 1); | 
| 1979 histograms.ExpectBucketCount(kTLSFeatureExtensionOCSPHistogram, false, 1); | 2142 histograms.ExpectBucketCount(kTLSFeatureExtensionOCSPHistogram, false, 1); | 
| 1980 } | 2143 } | 
| 1981 | 2144 | 
| 1982 // Tests that CertVerifyProc records a histogram correctly when a | 2145 // Tests that CertVerifyProc records a histogram correctly when a | 
| 1983 // certificate chaining to a private root contains the TLS feature | 2146 // certificate chaining to a private root contains the TLS feature | 
| 1984 // extension and does have a stapled OCSP response. | 2147 // extension and does have a stapled OCSP response. | 
| 1985 TEST_F(CertVerifyProcTest, HasTLSFeatureExtensionWithStapleUMA) { | 2148 TEST_F(CertVerifyProcBaseClassTest, HasTLSFeatureExtensionWithStapleUMA) { | 
| 1986 base::HistogramTester histograms; | 2149 base::HistogramTester histograms; | 
| 1987 scoped_refptr<X509Certificate> cert( | 2150 scoped_refptr<X509Certificate> cert( | 
| 1988 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); | 2151 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); | 
| 1989 ASSERT_TRUE(cert); | 2152 ASSERT_TRUE(cert); | 
| 1990 CertVerifyResult result; | 2153 CertVerifyResult result; | 
| 1991 result.is_issued_by_known_root = false; | 2154 result.is_issued_by_known_root = false; | 
| 1992 verify_proc_ = new MockCertVerifyProc(result); | 2155 auto verify_proc = make_scoped_refptr(new MockCertVerifyProc(result)); | 
| 1993 | 2156 | 
| 1994 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2157 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 
| 1995 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2158 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 
| 1996 | 2159 | 
| 1997 int flags = 0; | 2160 int flags = 0; | 
| 1998 CertVerifyResult verify_result; | 2161 CertVerifyResult verify_result; | 
| 1999 int error = | 2162 int error = | 
| 2000 VerifyWithOCSPResponse(cert.get(), "127.0.0.1", "dummy response", flags, | 2163 verify_proc->Verify(cert.get(), "127.0.0.1", "dummy response", flags, | 
| 2001 NULL, empty_cert_list_, &verify_result); | 2164 nullptr, EmptyCertList(), &verify_result); | 
| 2002 EXPECT_EQ(OK, error); | 2165 EXPECT_EQ(OK, error); | 
| 2003 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); | 2166 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); | 
| 2004 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, true, 1); | 2167 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, true, 1); | 
| 2005 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 1); | 2168 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 1); | 
| 2006 histograms.ExpectBucketCount(kTLSFeatureExtensionOCSPHistogram, true, 1); | 2169 histograms.ExpectBucketCount(kTLSFeatureExtensionOCSPHistogram, true, 1); | 
| 2007 } | 2170 } | 
| 2008 | 2171 | 
| 2009 // Tests that CertVerifyProc records a histogram correctly when a | 2172 // Tests that CertVerifyProc records a histogram correctly when a | 
| 2010 // certificate chaining to a private root does not contain the TLS feature | 2173 // certificate chaining to a private root does not contain the TLS feature | 
| 2011 // extension. | 2174 // extension. | 
| 2012 TEST_F(CertVerifyProcTest, DoesNotHaveTLSFeatureExtensionUMA) { | 2175 TEST_F(CertVerifyProcBaseClassTest, DoesNotHaveTLSFeatureExtensionUMA) { | 
| 2013 base::HistogramTester histograms; | 2176 base::HistogramTester histograms; | 
| 2014 scoped_refptr<X509Certificate> cert( | 2177 scoped_refptr<X509Certificate> cert( | 
| 2015 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 2178 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 2016 ASSERT_TRUE(cert); | 2179 ASSERT_TRUE(cert); | 
| 2017 CertVerifyResult result; | 2180 CertVerifyResult result; | 
| 2018 result.is_issued_by_known_root = false; | 2181 result.is_issued_by_known_root = false; | 
| 2019 verify_proc_ = new MockCertVerifyProc(result); | 2182 auto verify_proc = make_scoped_refptr(new MockCertVerifyProc(result)); | 
| 2020 | 2183 | 
| 2021 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2184 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 
| 2022 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2185 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 
| 2023 | 2186 | 
| 2024 int flags = 0; | 2187 int flags = 0; | 
| 2025 CertVerifyResult verify_result; | 2188 CertVerifyResult verify_result; | 
| 2026 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 2189 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 
| 2027 &verify_result); | 2190 NULL, EmptyCertList(), &verify_result); | 
| 2028 EXPECT_EQ(OK, error); | 2191 EXPECT_EQ(OK, error); | 
| 2029 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); | 2192 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); | 
| 2030 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, false, 1); | 2193 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, false, 1); | 
| 2031 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2194 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 
| 2032 } | 2195 } | 
| 2033 | 2196 | 
| 2034 // Tests that CertVerifyProc does not record a histogram when a | 2197 // Tests that CertVerifyProc does not record a histogram when a | 
| 2035 // certificate contains the TLS feature extension but chains to a public | 2198 // certificate contains the TLS feature extension but chains to a public | 
| 2036 // root. | 2199 // root. | 
| 2037 TEST_F(CertVerifyProcTest, HasTLSFeatureExtensionWithPublicRootUMA) { | 2200 TEST_F(CertVerifyProcBaseClassTest, HasTLSFeatureExtensionWithPublicRootUMA) { | 
| 2038 base::HistogramTester histograms; | 2201 base::HistogramTester histograms; | 
| 2039 scoped_refptr<X509Certificate> cert( | 2202 scoped_refptr<X509Certificate> cert( | 
| 2040 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); | 2203 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); | 
| 2041 ASSERT_TRUE(cert); | 2204 ASSERT_TRUE(cert); | 
| 2042 CertVerifyResult result; | 2205 CertVerifyResult result; | 
| 2043 result.is_issued_by_known_root = true; | 2206 result.is_issued_by_known_root = true; | 
| 2044 verify_proc_ = new MockCertVerifyProc(result); | 2207 auto verify_proc = make_scoped_refptr(new MockCertVerifyProc(result)); | 
| 2045 | 2208 | 
| 2046 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2209 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 
| 2047 | 2210 | 
| 2048 int flags = 0; | 2211 int flags = 0; | 
| 2049 CertVerifyResult verify_result; | 2212 CertVerifyResult verify_result; | 
| 2050 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 2213 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 
| 2051 &verify_result); | 2214 NULL, EmptyCertList(), &verify_result); | 
| 2052 EXPECT_EQ(OK, error); | 2215 EXPECT_EQ(OK, error); | 
| 2053 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2216 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 
| 2054 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2217 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 
| 2055 } | 2218 } | 
| 2056 | 2219 | 
| 2057 } // namespace net | 2220 } // namespace net | 
| OLD | NEW |