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" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/sha1.h" | 14 #include "base/sha1.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "crypto/sha2.h" | 17 #include "crypto/sha2.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/cert/asn1_util.h" | 19 #include "net/cert/asn1_util.h" |
20 #include "net/cert/cert_status_flags.h" | 20 #include "net/cert/cert_status_flags.h" |
21 #include "net/cert/cert_verifier.h" | 21 #include "net/cert/cert_verifier.h" |
22 #include "net/cert/cert_verify_result.h" | 22 #include "net/cert/cert_verify_result.h" |
23 #include "net/cert/crl_set.h" | 23 #include "net/cert/crl_set.h" |
24 #include "net/cert/crl_set_storage.h" | 24 #include "net/cert/crl_set_storage.h" |
25 #include "net/cert/test_root_certs.h" | 25 #include "net/cert/test_root_certs.h" |
26 #include "net/cert/x509_certificate.h" | 26 #include "net/cert/x509_certificate.h" |
27 #include "net/test/cert_test_util.h" | 27 #include "net/test/cert_test_util.h" |
| 28 #include "net/test/gtest_util.h" |
28 #include "net/test/test_certificate_data.h" | 29 #include "net/test/test_certificate_data.h" |
29 #include "net/test/test_data_directory.h" | 30 #include "net/test/test_data_directory.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
31 | 33 |
32 #if defined(OS_ANDROID) | 34 #if defined(OS_ANDROID) |
33 #include "base/android/build_info.h" | 35 #include "base/android/build_info.h" |
34 #endif | 36 #endif |
35 | 37 |
| 38 using net::test::IsError; |
| 39 using net::test::IsOk; |
| 40 |
36 using base::HexEncode; | 41 using base::HexEncode; |
37 | 42 |
38 namespace net { | 43 namespace net { |
39 | 44 |
40 namespace { | 45 namespace { |
41 | 46 |
42 // Mock CertVerifyProc that sets the CertVerifyResult to a given value for | 47 // Mock CertVerifyProc that sets the CertVerifyResult to a given value for |
43 // all certificates that are Verify()'d | 48 // all certificates that are Verify()'d |
44 class MockCertVerifyProc : public CertVerifyProc { | 49 class MockCertVerifyProc : public CertVerifyProc { |
45 public: | 50 public: |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 189 |
185 scoped_refptr<CRLSet> crl_set(CRLSet::ForTesting(false, NULL, "")); | 190 scoped_refptr<CRLSet> crl_set(CRLSet::ForTesting(false, NULL, "")); |
186 CertVerifyResult verify_result; | 191 CertVerifyResult verify_result; |
187 int flags = CertVerifier::VERIFY_EV_CERT; | 192 int flags = CertVerifier::VERIFY_EV_CERT; |
188 int error = Verify(comodo_chain.get(), | 193 int error = Verify(comodo_chain.get(), |
189 "comodo.com", | 194 "comodo.com", |
190 flags, | 195 flags, |
191 crl_set.get(), | 196 crl_set.get(), |
192 empty_cert_list_, | 197 empty_cert_list_, |
193 &verify_result); | 198 &verify_result); |
194 EXPECT_EQ(OK, error); | 199 EXPECT_THAT(error, IsOk()); |
195 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); | 200 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); |
196 } | 201 } |
197 | 202 |
198 // TODO(crbug.com/605457): the test expectation was incorrect on some | 203 // TODO(crbug.com/605457): the test expectation was incorrect on some |
199 // configurations, so disable the test until it is fixed (better to have | 204 // configurations, so disable the test until it is fixed (better to have |
200 // a bug to track a failing test than a false sense of security due to | 205 // a bug to track a failing test than a false sense of security due to |
201 // false positive). | 206 // false positive). |
202 TEST_F(CertVerifyProcTest, DISABLED_PaypalNullCertParsing) { | 207 TEST_F(CertVerifyProcTest, DISABLED_PaypalNullCertParsing) { |
203 // A certificate for www.paypal.com with a NULL byte in the common name. | 208 // A certificate for www.paypal.com with a NULL byte in the common name. |
204 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363 | 209 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363 |
(...skipping 11 matching lines...) Expand all Loading... |
216 | 221 |
217 int flags = 0; | 222 int flags = 0; |
218 CertVerifyResult verify_result; | 223 CertVerifyResult verify_result; |
219 int error = Verify(paypal_null_cert.get(), | 224 int error = Verify(paypal_null_cert.get(), |
220 "www.paypal.com", | 225 "www.paypal.com", |
221 flags, | 226 flags, |
222 NULL, | 227 NULL, |
223 empty_cert_list_, | 228 empty_cert_list_, |
224 &verify_result); | 229 &verify_result); |
225 #if defined(USE_NSS_CERTS) || defined(OS_ANDROID) | 230 #if defined(USE_NSS_CERTS) || defined(OS_ANDROID) |
226 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error); | 231 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); |
227 #elif defined(OS_IOS) && TARGET_IPHONE_SIMULATOR | 232 #elif defined(OS_IOS) && TARGET_IPHONE_SIMULATOR |
228 // iOS returns a ERR_CERT_INVALID error on the simulator, while returning | 233 // iOS returns a ERR_CERT_INVALID error on the simulator, while returning |
229 // ERR_CERT_AUTHORITY_INVALID on the real device. | 234 // ERR_CERT_AUTHORITY_INVALID on the real device. |
230 EXPECT_EQ(ERR_CERT_INVALID, error); | 235 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); |
231 #else | 236 #else |
232 // TOOD(bulach): investigate why macosx and win aren't returning | 237 // TOOD(bulach): investigate why macosx and win aren't returning |
233 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. | 238 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. |
234 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); | 239 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); |
235 #endif | 240 #endif |
236 // Either the system crypto library should correctly report a certificate | 241 // Either the system crypto library should correctly report a certificate |
237 // name mismatch, or our certificate blacklist should cause us to report an | 242 // name mismatch, or our certificate blacklist should cause us to report an |
238 // invalid certificate. | 243 // invalid certificate. |
239 #if defined(USE_NSS_CERTS) || defined(OS_WIN) | 244 #if defined(USE_NSS_CERTS) || defined(OS_WIN) |
240 EXPECT_TRUE(verify_result.cert_status & | 245 EXPECT_TRUE(verify_result.cert_status & |
241 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); | 246 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); |
242 #endif | 247 #endif |
243 } | 248 } |
244 | 249 |
(...skipping 26 matching lines...) Expand all Loading... |
271 ScopedTestRoot scoped_root(certs[2].get()); | 276 ScopedTestRoot scoped_root(certs[2].get()); |
272 | 277 |
273 int flags = 0; | 278 int flags = 0; |
274 CertVerifyResult verify_result; | 279 CertVerifyResult verify_result; |
275 int error = Verify(cert.get(), | 280 int error = Verify(cert.get(), |
276 "policy_test.example", | 281 "policy_test.example", |
277 flags, | 282 flags, |
278 NULL, | 283 NULL, |
279 empty_cert_list_, | 284 empty_cert_list_, |
280 &verify_result); | 285 &verify_result); |
281 EXPECT_EQ(OK, error); | 286 EXPECT_THAT(error, IsOk()); |
282 EXPECT_EQ(0u, verify_result.cert_status); | 287 EXPECT_EQ(0u, verify_result.cert_status); |
283 } | 288 } |
284 | 289 |
285 TEST_F(CertVerifyProcTest, RejectExpiredCert) { | 290 TEST_F(CertVerifyProcTest, RejectExpiredCert) { |
286 base::FilePath certs_dir = GetTestCertsDirectory(); | 291 base::FilePath certs_dir = GetTestCertsDirectory(); |
287 | 292 |
288 // Load root_ca_cert.pem into the test root store. | 293 // Load root_ca_cert.pem into the test root store. |
289 ScopedTestRoot test_root( | 294 ScopedTestRoot test_root( |
290 ImportCertFromFile(certs_dir, "root_ca_cert.pem").get()); | 295 ImportCertFromFile(certs_dir, "root_ca_cert.pem").get()); |
291 | 296 |
292 CertificateList certs = CreateCertificateListFromFile( | 297 CertificateList certs = CreateCertificateListFromFile( |
293 certs_dir, "expired_cert.pem", X509Certificate::FORMAT_AUTO); | 298 certs_dir, "expired_cert.pem", X509Certificate::FORMAT_AUTO); |
294 ASSERT_EQ(1U, certs.size()); | 299 ASSERT_EQ(1U, certs.size()); |
295 | 300 |
296 X509Certificate::OSCertHandles intermediates; | 301 X509Certificate::OSCertHandles intermediates; |
297 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( | 302 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( |
298 certs[0]->os_cert_handle(), intermediates); | 303 certs[0]->os_cert_handle(), intermediates); |
299 | 304 |
300 int flags = 0; | 305 int flags = 0; |
301 CertVerifyResult verify_result; | 306 CertVerifyResult verify_result; |
302 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 307 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, |
303 &verify_result); | 308 &verify_result); |
304 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); | 309 EXPECT_THAT(error, IsError(ERR_CERT_DATE_INVALID)); |
305 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_DATE_INVALID); | 310 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_DATE_INVALID); |
306 } | 311 } |
307 | 312 |
308 // Currently, only RSA and DSA keys are checked for weakness, and our example | 313 // Currently, only RSA and DSA keys are checked for weakness, and our example |
309 // weak size is 768. These could change in the future. | 314 // weak size is 768. These could change in the future. |
310 // | 315 // |
311 // Note that this means there may be false negatives: keys for other | 316 // Note that this means there may be false negatives: keys for other |
312 // algorithms and which are weak will pass this test. | 317 // algorithms and which are weak will pass this test. |
313 static bool IsWeakKeyType(const std::string& key_type) { | 318 static bool IsWeakKeyType(const std::string& key_type) { |
314 size_t pos = key_type.find("-"); | 319 size_t pos = key_type.find("-"); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 empty_cert_list_, | 377 empty_cert_list_, |
373 &verify_result); | 378 &verify_result); |
374 | 379 |
375 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { | 380 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { |
376 EXPECT_NE(OK, error); | 381 EXPECT_NE(OK, error); |
377 EXPECT_EQ(CERT_STATUS_WEAK_KEY, | 382 EXPECT_EQ(CERT_STATUS_WEAK_KEY, |
378 verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 383 verify_result.cert_status & CERT_STATUS_WEAK_KEY); |
379 EXPECT_NE(CERT_STATUS_INVALID, | 384 EXPECT_NE(CERT_STATUS_INVALID, |
380 verify_result.cert_status & CERT_STATUS_INVALID); | 385 verify_result.cert_status & CERT_STATUS_INVALID); |
381 } else { | 386 } else { |
382 EXPECT_EQ(OK, error); | 387 EXPECT_THAT(error, IsOk()); |
383 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 388 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); |
384 } | 389 } |
385 } | 390 } |
386 } | 391 } |
387 } | 392 } |
388 | 393 |
389 // Regression test for http://crbug.com/108514. | 394 // Regression test for http://crbug.com/108514. |
390 #if defined(OS_MACOSX) && !defined(OS_IOS) | 395 #if defined(OS_MACOSX) && !defined(OS_IOS) |
391 // Disabled on OS X - Security.framework doesn't ignore superflous certificates | 396 // Disabled on OS X - Security.framework doesn't ignore superflous certificates |
392 // provided by servers. See CertVerifyProcTest.CybertrustGTERoot for further | 397 // provided by servers. See CertVerifyProcTest.CybertrustGTERoot for further |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 intermediates); | 429 intermediates); |
425 | 430 |
426 CertVerifyResult verify_result; | 431 CertVerifyResult verify_result; |
427 int flags = 0; | 432 int flags = 0; |
428 int error = Verify(cert_chain.get(), | 433 int error = Verify(cert_chain.get(), |
429 "127.0.0.1", | 434 "127.0.0.1", |
430 flags, | 435 flags, |
431 NULL, | 436 NULL, |
432 empty_cert_list_, | 437 empty_cert_list_, |
433 &verify_result); | 438 &verify_result); |
434 EXPECT_EQ(OK, error); | 439 EXPECT_THAT(error, IsOk()); |
435 | 440 |
436 // The extra MD5 root should be discarded | 441 // The extra MD5 root should be discarded |
437 ASSERT_TRUE(verify_result.verified_cert.get()); | 442 ASSERT_TRUE(verify_result.verified_cert.get()); |
438 ASSERT_EQ(1u, | 443 ASSERT_EQ(1u, |
439 verify_result.verified_cert->GetIntermediateCertificates().size()); | 444 verify_result.verified_cert->GetIntermediateCertificates().size()); |
440 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 445 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
441 verify_result.verified_cert->GetIntermediateCertificates().front(), | 446 verify_result.verified_cert->GetIntermediateCertificates().front(), |
442 root_cert->os_cert_handle())); | 447 root_cert->os_cert_handle())); |
443 | 448 |
444 EXPECT_FALSE(verify_result.has_md5); | 449 EXPECT_FALSE(verify_result.has_md5); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 intermediates); | 555 intermediates); |
551 | 556 |
552 int flags = 0; | 557 int flags = 0; |
553 CertVerifyResult verify_result; | 558 CertVerifyResult verify_result; |
554 int error = Verify(leaf.get(), | 559 int error = Verify(leaf.get(), |
555 "test.example.com", | 560 "test.example.com", |
556 flags, | 561 flags, |
557 NULL, | 562 NULL, |
558 empty_cert_list_, | 563 empty_cert_list_, |
559 &verify_result); | 564 &verify_result); |
560 EXPECT_EQ(OK, error); | 565 EXPECT_THAT(error, IsOk()); |
561 EXPECT_EQ(0U, verify_result.cert_status); | 566 EXPECT_EQ(0U, verify_result.cert_status); |
562 | 567 |
563 error = Verify(leaf.get(), "foo.test2.example.com", flags, NULL, | 568 error = Verify(leaf.get(), "foo.test2.example.com", flags, NULL, |
564 empty_cert_list_, &verify_result); | 569 empty_cert_list_, &verify_result); |
565 EXPECT_EQ(OK, error); | 570 EXPECT_THAT(error, IsOk()); |
566 EXPECT_EQ(0U, verify_result.cert_status); | 571 EXPECT_EQ(0U, verify_result.cert_status); |
567 } | 572 } |
568 | 573 |
569 TEST_F(CertVerifyProcTest, NameConstraintsFailure) { | 574 TEST_F(CertVerifyProcTest, NameConstraintsFailure) { |
570 if (!SupportsReturningVerifiedChain()) { | 575 if (!SupportsReturningVerifiedChain()) { |
571 LOG(INFO) << "Skipping this test in this platform."; | 576 LOG(INFO) << "Skipping this test in this platform."; |
572 return; | 577 return; |
573 } | 578 } |
574 | 579 |
575 CertificateList ca_cert_list = | 580 CertificateList ca_cert_list = |
(...skipping 14 matching lines...) Expand all Loading... |
590 intermediates); | 595 intermediates); |
591 | 596 |
592 int flags = 0; | 597 int flags = 0; |
593 CertVerifyResult verify_result; | 598 CertVerifyResult verify_result; |
594 int error = Verify(leaf.get(), | 599 int error = Verify(leaf.get(), |
595 "test.example.com", | 600 "test.example.com", |
596 flags, | 601 flags, |
597 NULL, | 602 NULL, |
598 empty_cert_list_, | 603 empty_cert_list_, |
599 &verify_result); | 604 &verify_result); |
600 EXPECT_EQ(ERR_CERT_NAME_CONSTRAINT_VIOLATION, error); | 605 EXPECT_THAT(error, IsError(ERR_CERT_NAME_CONSTRAINT_VIOLATION)); |
601 EXPECT_EQ(CERT_STATUS_NAME_CONSTRAINT_VIOLATION, | 606 EXPECT_EQ(CERT_STATUS_NAME_CONSTRAINT_VIOLATION, |
602 verify_result.cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION); | 607 verify_result.cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION); |
603 } | 608 } |
604 | 609 |
605 TEST_F(CertVerifyProcTest, TestHasTooLongValidity) { | 610 TEST_F(CertVerifyProcTest, TestHasTooLongValidity) { |
606 struct { | 611 struct { |
607 const char* const file; | 612 const char* const file; |
608 bool is_valid_too_long; | 613 bool is_valid_too_long; |
609 } tests[] = { | 614 } tests[] = { |
610 {"twitter-chain.pem", false}, | 615 {"twitter-chain.pem", false}, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 scoped_refptr<X509Certificate> cert_chain = | 655 scoped_refptr<X509Certificate> cert_chain = |
651 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 656 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
652 intermediates); | 657 intermediates); |
653 | 658 |
654 int flags = 0; | 659 int flags = 0; |
655 CertVerifyResult verify_result; | 660 CertVerifyResult verify_result; |
656 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug | 661 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug |
657 // against agl. See also PublicKeyHashes. | 662 // against agl. See also PublicKeyHashes. |
658 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, | 663 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, |
659 empty_cert_list_, &verify_result); | 664 empty_cert_list_, &verify_result); |
660 EXPECT_EQ(OK, error); | 665 EXPECT_THAT(error, IsOk()); |
661 EXPECT_TRUE(verify_result.is_issued_by_known_root); | 666 EXPECT_TRUE(verify_result.is_issued_by_known_root); |
662 } | 667 } |
663 | 668 |
664 // TODO(crbug.com/610546): Fix and re-enable this test. | 669 // TODO(crbug.com/610546): Fix and re-enable this test. |
665 TEST_F(CertVerifyProcTest, DISABLED_PublicKeyHashes) { | 670 TEST_F(CertVerifyProcTest, DISABLED_PublicKeyHashes) { |
666 if (!SupportsReturningVerifiedChain()) { | 671 if (!SupportsReturningVerifiedChain()) { |
667 LOG(INFO) << "Skipping this test in this platform."; | 672 LOG(INFO) << "Skipping this test in this platform."; |
668 return; | 673 return; |
669 } | 674 } |
670 | 675 |
671 base::FilePath certs_dir = GetTestCertsDirectory(); | 676 base::FilePath certs_dir = GetTestCertsDirectory(); |
672 CertificateList certs = CreateCertificateListFromFile( | 677 CertificateList certs = CreateCertificateListFromFile( |
673 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); | 678 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); |
674 ASSERT_EQ(3U, certs.size()); | 679 ASSERT_EQ(3U, certs.size()); |
675 | 680 |
676 X509Certificate::OSCertHandles intermediates; | 681 X509Certificate::OSCertHandles intermediates; |
677 intermediates.push_back(certs[1]->os_cert_handle()); | 682 intermediates.push_back(certs[1]->os_cert_handle()); |
678 | 683 |
679 scoped_refptr<X509Certificate> cert_chain = | 684 scoped_refptr<X509Certificate> cert_chain = |
680 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 685 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
681 intermediates); | 686 intermediates); |
682 int flags = 0; | 687 int flags = 0; |
683 CertVerifyResult verify_result; | 688 CertVerifyResult verify_result; |
684 | 689 |
685 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug | 690 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug |
686 // against agl. See also TestKnownRoot. | 691 // against agl. See also TestKnownRoot. |
687 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, | 692 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, |
688 empty_cert_list_, &verify_result); | 693 empty_cert_list_, &verify_result); |
689 EXPECT_EQ(OK, error); | 694 EXPECT_THAT(error, IsOk()); |
690 ASSERT_LE(3U, verify_result.public_key_hashes.size()); | 695 ASSERT_LE(3U, verify_result.public_key_hashes.size()); |
691 | 696 |
692 HashValueVector sha1_hashes; | 697 HashValueVector sha1_hashes; |
693 for (size_t i = 0; i < verify_result.public_key_hashes.size(); ++i) { | 698 for (size_t i = 0; i < verify_result.public_key_hashes.size(); ++i) { |
694 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA1) | 699 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA1) |
695 continue; | 700 continue; |
696 sha1_hashes.push_back(verify_result.public_key_hashes[i]); | 701 sha1_hashes.push_back(verify_result.public_key_hashes[i]); |
697 } | 702 } |
698 ASSERT_LE(3u, sha1_hashes.size()); | 703 ASSERT_LE(3u, sha1_hashes.size()); |
699 | 704 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 int error = Verify(server_cert.get(), | 736 int error = Verify(server_cert.get(), |
732 "jira.aquameta.com", | 737 "jira.aquameta.com", |
733 flags, | 738 flags, |
734 NULL, | 739 NULL, |
735 empty_cert_list_, | 740 empty_cert_list_, |
736 &verify_result); | 741 &verify_result); |
737 #if defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | 742 #if defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) |
738 // This certificate has two errors: "invalid key usage" and "untrusted CA". | 743 // This certificate has two errors: "invalid key usage" and "untrusted CA". |
739 // However, OpenSSL returns only one (the latter), and we can't detect | 744 // However, OpenSSL returns only one (the latter), and we can't detect |
740 // the other errors. | 745 // the other errors. |
741 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); | 746 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); |
742 #else | 747 #else |
743 EXPECT_EQ(ERR_CERT_INVALID, error); | 748 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); |
744 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 749 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); |
745 #endif | 750 #endif |
746 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors | 751 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors |
747 // from NSS. | 752 // from NSS. |
748 #if !defined(USE_NSS_CERTS) && !defined(OS_IOS) && !defined(OS_ANDROID) | 753 #if !defined(USE_NSS_CERTS) && !defined(OS_IOS) && !defined(OS_ANDROID) |
749 // The certificate is issued by an unknown CA. | 754 // The certificate is issued by an unknown CA. |
750 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); | 755 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); |
751 #endif | 756 #endif |
752 } | 757 } |
753 | 758 |
(...skipping 29 matching lines...) Expand all Loading... |
783 | 788 |
784 CertVerifyResult verify_result; | 789 CertVerifyResult verify_result; |
785 EXPECT_EQ(static_cast<X509Certificate*>(NULL), | 790 EXPECT_EQ(static_cast<X509Certificate*>(NULL), |
786 verify_result.verified_cert.get()); | 791 verify_result.verified_cert.get()); |
787 int error = Verify(google_full_chain.get(), | 792 int error = Verify(google_full_chain.get(), |
788 "127.0.0.1", | 793 "127.0.0.1", |
789 0, | 794 0, |
790 NULL, | 795 NULL, |
791 empty_cert_list_, | 796 empty_cert_list_, |
792 &verify_result); | 797 &verify_result); |
793 EXPECT_EQ(OK, error); | 798 EXPECT_THAT(error, IsOk()); |
794 ASSERT_NE(static_cast<X509Certificate*>(NULL), | 799 ASSERT_NE(static_cast<X509Certificate*>(NULL), |
795 verify_result.verified_cert.get()); | 800 verify_result.verified_cert.get()); |
796 | 801 |
797 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 802 EXPECT_NE(google_full_chain, verify_result.verified_cert); |
798 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 803 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
799 google_full_chain->os_cert_handle(), | 804 google_full_chain->os_cert_handle(), |
800 verify_result.verified_cert->os_cert_handle())); | 805 verify_result.verified_cert->os_cert_handle())); |
801 const X509Certificate::OSCertHandles& return_intermediates = | 806 const X509Certificate::OSCertHandles& return_intermediates = |
802 verify_result.verified_cert->GetIntermediateCertificates(); | 807 verify_result.verified_cert->GetIntermediateCertificates(); |
803 ASSERT_EQ(2U, return_intermediates.size()); | 808 ASSERT_EQ(2U, return_intermediates.size()); |
(...skipping 21 matching lines...) Expand all Loading... |
825 | 830 |
826 CertVerifyResult verify_result; | 831 CertVerifyResult verify_result; |
827 int error = 0; | 832 int error = 0; |
828 | 833 |
829 // Intranet names for public CAs should be flagged: | 834 // Intranet names for public CAs should be flagged: |
830 CertVerifyResult dummy_result; | 835 CertVerifyResult dummy_result; |
831 dummy_result.is_issued_by_known_root = true; | 836 dummy_result.is_issued_by_known_root = true; |
832 verify_proc_ = new MockCertVerifyProc(dummy_result); | 837 verify_proc_ = new MockCertVerifyProc(dummy_result); |
833 error = | 838 error = |
834 Verify(cert.get(), "intranet", 0, NULL, empty_cert_list_, &verify_result); | 839 Verify(cert.get(), "intranet", 0, NULL, empty_cert_list_, &verify_result); |
835 EXPECT_EQ(OK, error); | 840 EXPECT_THAT(error, IsOk()); |
836 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); | 841 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); |
837 | 842 |
838 // However, if the CA is not well known, these should not be flagged: | 843 // However, if the CA is not well known, these should not be flagged: |
839 dummy_result.Reset(); | 844 dummy_result.Reset(); |
840 dummy_result.is_issued_by_known_root = false; | 845 dummy_result.is_issued_by_known_root = false; |
841 verify_proc_ = new MockCertVerifyProc(dummy_result); | 846 verify_proc_ = new MockCertVerifyProc(dummy_result); |
842 error = | 847 error = |
843 Verify(cert.get(), "intranet", 0, NULL, empty_cert_list_, &verify_result); | 848 Verify(cert.get(), "intranet", 0, NULL, empty_cert_list_, &verify_result); |
844 EXPECT_EQ(OK, error); | 849 EXPECT_THAT(error, IsOk()); |
845 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); | 850 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); |
846 } | 851 } |
847 | 852 |
848 // Test that a SHA-1 certificate from a publicly trusted CA issued after | 853 // Test that a SHA-1 certificate from a publicly trusted CA issued after |
849 // 1 January 2016 is rejected, but those issued before that date, or with | 854 // 1 January 2016 is rejected, but those issued before that date, or with |
850 // SHA-1 in the intermediate, is not rejected. | 855 // SHA-1 in the intermediate, is not rejected. |
851 TEST_F(CertVerifyProcTest, VerifyRejectsSHA1AfterDeprecation) { | 856 TEST_F(CertVerifyProcTest, VerifyRejectsSHA1AfterDeprecation) { |
852 CertVerifyResult dummy_result; | 857 CertVerifyResult dummy_result; |
853 CertVerifyResult verify_result; | 858 CertVerifyResult verify_result; |
854 int error = 0; | 859 int error = 0; |
855 scoped_refptr<X509Certificate> cert; | 860 scoped_refptr<X509Certificate> cert; |
856 | 861 |
857 // Publicly trusted SHA-1 leaf certificates issued before 1 January 2016 | 862 // Publicly trusted SHA-1 leaf certificates issued before 1 January 2016 |
858 // are accepted. | 863 // are accepted. |
859 verify_result.Reset(); | 864 verify_result.Reset(); |
860 dummy_result.Reset(); | 865 dummy_result.Reset(); |
861 dummy_result.is_issued_by_known_root = true; | 866 dummy_result.is_issued_by_known_root = true; |
862 dummy_result.has_sha1 = true; | 867 dummy_result.has_sha1 = true; |
863 dummy_result.has_sha1_leaf = true; | 868 dummy_result.has_sha1_leaf = true; |
864 verify_proc_ = new MockCertVerifyProc(dummy_result); | 869 verify_proc_ = new MockCertVerifyProc(dummy_result); |
865 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), | 870 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), |
866 "sha1_dec_2015.pem", | 871 "sha1_dec_2015.pem", |
867 X509Certificate::FORMAT_AUTO); | 872 X509Certificate::FORMAT_AUTO); |
868 ASSERT_TRUE(cert); | 873 ASSERT_TRUE(cert); |
869 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, | 874 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, |
870 &verify_result); | 875 &verify_result); |
871 EXPECT_EQ(OK, error); | 876 EXPECT_THAT(error, IsOk()); |
872 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 877 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); |
873 | 878 |
874 // Publicly trusted SHA-1 leaf certificates issued on/after 1 January 2016 | 879 // Publicly trusted SHA-1 leaf certificates issued on/after 1 January 2016 |
875 // are rejected. | 880 // are rejected. |
876 verify_result.Reset(); | 881 verify_result.Reset(); |
877 dummy_result.Reset(); | 882 dummy_result.Reset(); |
878 dummy_result.is_issued_by_known_root = true; | 883 dummy_result.is_issued_by_known_root = true; |
879 dummy_result.has_sha1 = true; | 884 dummy_result.has_sha1 = true; |
880 dummy_result.has_sha1_leaf = true; | 885 dummy_result.has_sha1_leaf = true; |
881 verify_proc_ = new MockCertVerifyProc(dummy_result); | 886 verify_proc_ = new MockCertVerifyProc(dummy_result); |
882 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), | 887 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), |
883 "sha1_jan_2016.pem", | 888 "sha1_jan_2016.pem", |
884 X509Certificate::FORMAT_AUTO); | 889 X509Certificate::FORMAT_AUTO); |
885 ASSERT_TRUE(cert); | 890 ASSERT_TRUE(cert); |
886 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, | 891 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, |
887 &verify_result); | 892 &verify_result); |
888 EXPECT_EQ(ERR_CERT_WEAK_SIGNATURE_ALGORITHM, error); | 893 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); |
889 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 894 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); |
890 | 895 |
891 // Enterprise issued SHA-1 leaf certificates issued on/after 1 January 2016 | 896 // Enterprise issued SHA-1 leaf certificates issued on/after 1 January 2016 |
892 // remain accepted until SHA-1 is disabled. | 897 // remain accepted until SHA-1 is disabled. |
893 verify_result.Reset(); | 898 verify_result.Reset(); |
894 dummy_result.Reset(); | 899 dummy_result.Reset(); |
895 dummy_result.is_issued_by_known_root = false; | 900 dummy_result.is_issued_by_known_root = false; |
896 dummy_result.has_sha1 = true; | 901 dummy_result.has_sha1 = true; |
897 dummy_result.has_sha1_leaf = true; | 902 dummy_result.has_sha1_leaf = true; |
898 verify_proc_ = new MockCertVerifyProc(dummy_result); | 903 verify_proc_ = new MockCertVerifyProc(dummy_result); |
899 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), | 904 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), |
900 "sha1_jan_2016.pem", | 905 "sha1_jan_2016.pem", |
901 X509Certificate::FORMAT_AUTO); | 906 X509Certificate::FORMAT_AUTO); |
902 ASSERT_TRUE(cert); | 907 ASSERT_TRUE(cert); |
903 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, | 908 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, |
904 &verify_result); | 909 &verify_result); |
905 EXPECT_EQ(OK, error); | 910 EXPECT_THAT(error, IsOk()); |
906 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 911 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); |
907 | 912 |
908 // Publicly trusted SHA-1 intermediates issued on/after 1 January 2016 are, | 913 // Publicly trusted SHA-1 intermediates issued on/after 1 January 2016 are, |
909 // unfortunately, accepted. This can arise due to OS path building quirks. | 914 // unfortunately, accepted. This can arise due to OS path building quirks. |
910 verify_result.Reset(); | 915 verify_result.Reset(); |
911 dummy_result.Reset(); | 916 dummy_result.Reset(); |
912 dummy_result.is_issued_by_known_root = true; | 917 dummy_result.is_issued_by_known_root = true; |
913 dummy_result.has_sha1 = true; | 918 dummy_result.has_sha1 = true; |
914 dummy_result.has_sha1_leaf = false; | 919 dummy_result.has_sha1_leaf = false; |
915 verify_proc_ = new MockCertVerifyProc(dummy_result); | 920 verify_proc_ = new MockCertVerifyProc(dummy_result); |
916 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), | 921 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), |
917 "sha1_jan_2016.pem", | 922 "sha1_jan_2016.pem", |
918 X509Certificate::FORMAT_AUTO); | 923 X509Certificate::FORMAT_AUTO); |
919 ASSERT_TRUE(cert); | 924 ASSERT_TRUE(cert); |
920 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, | 925 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, |
921 &verify_result); | 926 &verify_result); |
922 EXPECT_EQ(OK, error); | 927 EXPECT_THAT(error, IsOk()); |
923 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 928 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); |
924 } | 929 } |
925 | 930 |
926 // Test that the certificate returned in CertVerifyResult is able to reorder | 931 // Test that the certificate returned in CertVerifyResult is able to reorder |
927 // certificates that are not ordered from end-entity to root. While this is | 932 // certificates that are not ordered from end-entity to root. While this is |
928 // a protocol violation if sent during a TLS handshake, if multiple sources | 933 // a protocol violation if sent during a TLS handshake, if multiple sources |
929 // of intermediate certificates are combined, it's possible that order may | 934 // of intermediate certificates are combined, it's possible that order may |
930 // not be maintained. | 935 // not be maintained. |
931 TEST_F(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) { | 936 TEST_F(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) { |
932 if (!SupportsReturningVerifiedChain()) { | 937 if (!SupportsReturningVerifiedChain()) { |
(...skipping 22 matching lines...) Expand all Loading... |
955 | 960 |
956 CertVerifyResult verify_result; | 961 CertVerifyResult verify_result; |
957 EXPECT_EQ(static_cast<X509Certificate*>(NULL), | 962 EXPECT_EQ(static_cast<X509Certificate*>(NULL), |
958 verify_result.verified_cert.get()); | 963 verify_result.verified_cert.get()); |
959 int error = Verify(google_full_chain.get(), | 964 int error = Verify(google_full_chain.get(), |
960 "127.0.0.1", | 965 "127.0.0.1", |
961 0, | 966 0, |
962 NULL, | 967 NULL, |
963 empty_cert_list_, | 968 empty_cert_list_, |
964 &verify_result); | 969 &verify_result); |
965 EXPECT_EQ(OK, error); | 970 EXPECT_THAT(error, IsOk()); |
966 ASSERT_NE(static_cast<X509Certificate*>(NULL), | 971 ASSERT_NE(static_cast<X509Certificate*>(NULL), |
967 verify_result.verified_cert.get()); | 972 verify_result.verified_cert.get()); |
968 | 973 |
969 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 974 EXPECT_NE(google_full_chain, verify_result.verified_cert); |
970 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 975 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
971 google_full_chain->os_cert_handle(), | 976 google_full_chain->os_cert_handle(), |
972 verify_result.verified_cert->os_cert_handle())); | 977 verify_result.verified_cert->os_cert_handle())); |
973 const X509Certificate::OSCertHandles& return_intermediates = | 978 const X509Certificate::OSCertHandles& return_intermediates = |
974 verify_result.verified_cert->GetIntermediateCertificates(); | 979 verify_result.verified_cert->GetIntermediateCertificates(); |
975 ASSERT_EQ(2U, return_intermediates.size()); | 980 ASSERT_EQ(2U, return_intermediates.size()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 | 1021 |
1017 CertVerifyResult verify_result; | 1022 CertVerifyResult verify_result; |
1018 EXPECT_EQ(static_cast<X509Certificate*>(NULL), | 1023 EXPECT_EQ(static_cast<X509Certificate*>(NULL), |
1019 verify_result.verified_cert.get()); | 1024 verify_result.verified_cert.get()); |
1020 int error = Verify(google_full_chain.get(), | 1025 int error = Verify(google_full_chain.get(), |
1021 "127.0.0.1", | 1026 "127.0.0.1", |
1022 0, | 1027 0, |
1023 NULL, | 1028 NULL, |
1024 empty_cert_list_, | 1029 empty_cert_list_, |
1025 &verify_result); | 1030 &verify_result); |
1026 EXPECT_EQ(OK, error); | 1031 EXPECT_THAT(error, IsOk()); |
1027 ASSERT_NE(static_cast<X509Certificate*>(NULL), | 1032 ASSERT_NE(static_cast<X509Certificate*>(NULL), |
1028 verify_result.verified_cert.get()); | 1033 verify_result.verified_cert.get()); |
1029 | 1034 |
1030 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 1035 EXPECT_NE(google_full_chain, verify_result.verified_cert); |
1031 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 1036 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
1032 google_full_chain->os_cert_handle(), | 1037 google_full_chain->os_cert_handle(), |
1033 verify_result.verified_cert->os_cert_handle())); | 1038 verify_result.verified_cert->os_cert_handle())); |
1034 const X509Certificate::OSCertHandles& return_intermediates = | 1039 const X509Certificate::OSCertHandles& return_intermediates = |
1035 verify_result.verified_cert->GetIntermediateCertificates(); | 1040 verify_result.verified_cert->GetIntermediateCertificates(); |
1036 ASSERT_EQ(2U, return_intermediates.size()); | 1041 ASSERT_EQ(2U, return_intermediates.size()); |
(...skipping 21 matching lines...) Expand all Loading... |
1058 X509Certificate::FORMAT_AUTO); | 1063 X509Certificate::FORMAT_AUTO); |
1059 ASSERT_EQ(1U, cert_list.size()); | 1064 ASSERT_EQ(1U, cert_list.size()); |
1060 scoped_refptr<X509Certificate> cert(cert_list[0]); | 1065 scoped_refptr<X509Certificate> cert(cert_list[0]); |
1061 | 1066 |
1062 // Verification of |cert| fails when |ca_cert| is not in the trust anchors | 1067 // Verification of |cert| fails when |ca_cert| is not in the trust anchors |
1063 // list. | 1068 // list. |
1064 int flags = 0; | 1069 int flags = 0; |
1065 CertVerifyResult verify_result; | 1070 CertVerifyResult verify_result; |
1066 int error = Verify( | 1071 int error = Verify( |
1067 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 1072 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); |
1068 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); | 1073 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); |
1069 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); | 1074 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); |
1070 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); | 1075 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); |
1071 | 1076 |
1072 // Now add the |ca_cert| to the |trust_anchors|, and verification should pass. | 1077 // Now add the |ca_cert| to the |trust_anchors|, and verification should pass. |
1073 CertificateList trust_anchors; | 1078 CertificateList trust_anchors; |
1074 trust_anchors.push_back(ca_cert); | 1079 trust_anchors.push_back(ca_cert); |
1075 error = Verify( | 1080 error = Verify( |
1076 cert.get(), "127.0.0.1", flags, NULL, trust_anchors, &verify_result); | 1081 cert.get(), "127.0.0.1", flags, NULL, trust_anchors, &verify_result); |
1077 EXPECT_EQ(OK, error); | 1082 EXPECT_THAT(error, IsOk()); |
1078 EXPECT_EQ(0U, verify_result.cert_status); | 1083 EXPECT_EQ(0U, verify_result.cert_status); |
1079 EXPECT_TRUE(verify_result.is_issued_by_additional_trust_anchor); | 1084 EXPECT_TRUE(verify_result.is_issued_by_additional_trust_anchor); |
1080 | 1085 |
1081 // Clearing the |trust_anchors| makes verification fail again (the cache | 1086 // Clearing the |trust_anchors| makes verification fail again (the cache |
1082 // should be skipped). | 1087 // should be skipped). |
1083 error = Verify( | 1088 error = Verify( |
1084 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 1089 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); |
1085 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); | 1090 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); |
1086 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); | 1091 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); |
1087 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); | 1092 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); |
1088 } | 1093 } |
1089 | 1094 |
1090 // Tests that certificates issued by user-supplied roots are not flagged as | 1095 // Tests that certificates issued by user-supplied roots are not flagged as |
1091 // issued by a known root. This should pass whether or not the platform supports | 1096 // issued by a known root. This should pass whether or not the platform supports |
1092 // detecting known roots. | 1097 // detecting known roots. |
1093 TEST_F(CertVerifyProcTest, IsIssuedByKnownRootIgnoresTestRoots) { | 1098 TEST_F(CertVerifyProcTest, IsIssuedByKnownRootIgnoresTestRoots) { |
1094 // Load root_ca_cert.pem into the test root store. | 1099 // Load root_ca_cert.pem into the test root store. |
1095 ScopedTestRoot test_root( | 1100 ScopedTestRoot test_root( |
1096 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); | 1101 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); |
1097 | 1102 |
1098 scoped_refptr<X509Certificate> cert( | 1103 scoped_refptr<X509Certificate> cert( |
1099 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1104 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); |
1100 | 1105 |
1101 // Verification should pass. | 1106 // Verification should pass. |
1102 int flags = 0; | 1107 int flags = 0; |
1103 CertVerifyResult verify_result; | 1108 CertVerifyResult verify_result; |
1104 int error = Verify( | 1109 int error = Verify( |
1105 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 1110 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); |
1106 EXPECT_EQ(OK, error); | 1111 EXPECT_THAT(error, IsOk()); |
1107 EXPECT_EQ(0U, verify_result.cert_status); | 1112 EXPECT_EQ(0U, verify_result.cert_status); |
1108 // But should not be marked as a known root. | 1113 // But should not be marked as a known root. |
1109 EXPECT_FALSE(verify_result.is_issued_by_known_root); | 1114 EXPECT_FALSE(verify_result.is_issued_by_known_root); |
1110 } | 1115 } |
1111 | 1116 |
1112 #if defined(USE_NSS_CERTS) || defined(OS_WIN) || \ | 1117 #if defined(USE_NSS_CERTS) || defined(OS_WIN) || \ |
1113 (defined(OS_MACOSX) && !defined(OS_IOS)) | 1118 (defined(OS_MACOSX) && !defined(OS_IOS)) |
1114 // Test that CRLSets are effective in making a certificate appear to be | 1119 // Test that CRLSets are effective in making a certificate appear to be |
1115 // revoked. | 1120 // revoked. |
1116 TEST_F(CertVerifyProcTest, CRLSet) { | 1121 TEST_F(CertVerifyProcTest, CRLSet) { |
1117 CertificateList ca_cert_list = | 1122 CertificateList ca_cert_list = |
1118 CreateCertificateListFromFile(GetTestCertsDirectory(), | 1123 CreateCertificateListFromFile(GetTestCertsDirectory(), |
1119 "root_ca_cert.pem", | 1124 "root_ca_cert.pem", |
1120 X509Certificate::FORMAT_AUTO); | 1125 X509Certificate::FORMAT_AUTO); |
1121 ASSERT_EQ(1U, ca_cert_list.size()); | 1126 ASSERT_EQ(1U, ca_cert_list.size()); |
1122 ScopedTestRoot test_root(ca_cert_list[0].get()); | 1127 ScopedTestRoot test_root(ca_cert_list[0].get()); |
1123 | 1128 |
1124 CertificateList cert_list = CreateCertificateListFromFile( | 1129 CertificateList cert_list = CreateCertificateListFromFile( |
1125 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO); | 1130 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO); |
1126 ASSERT_EQ(1U, cert_list.size()); | 1131 ASSERT_EQ(1U, cert_list.size()); |
1127 scoped_refptr<X509Certificate> cert(cert_list[0]); | 1132 scoped_refptr<X509Certificate> cert(cert_list[0]); |
1128 | 1133 |
1129 int flags = 0; | 1134 int flags = 0; |
1130 CertVerifyResult verify_result; | 1135 CertVerifyResult verify_result; |
1131 int error = Verify( | 1136 int error = Verify( |
1132 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 1137 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); |
1133 EXPECT_EQ(OK, error); | 1138 EXPECT_THAT(error, IsOk()); |
1134 EXPECT_EQ(0U, verify_result.cert_status); | 1139 EXPECT_EQ(0U, verify_result.cert_status); |
1135 | 1140 |
1136 scoped_refptr<CRLSet> crl_set; | 1141 scoped_refptr<CRLSet> crl_set; |
1137 std::string crl_set_bytes; | 1142 std::string crl_set_bytes; |
1138 | 1143 |
1139 // First test blocking by SPKI. | 1144 // First test blocking by SPKI. |
1140 EXPECT_TRUE(base::ReadFileToString( | 1145 EXPECT_TRUE(base::ReadFileToString( |
1141 GetTestCertsDirectory().AppendASCII("crlset_by_leaf_spki.raw"), | 1146 GetTestCertsDirectory().AppendASCII("crlset_by_leaf_spki.raw"), |
1142 &crl_set_bytes)); | 1147 &crl_set_bytes)); |
1143 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 1148 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); |
1144 | 1149 |
1145 error = Verify(cert.get(), | 1150 error = Verify(cert.get(), |
1146 "127.0.0.1", | 1151 "127.0.0.1", |
1147 flags, | 1152 flags, |
1148 crl_set.get(), | 1153 crl_set.get(), |
1149 empty_cert_list_, | 1154 empty_cert_list_, |
1150 &verify_result); | 1155 &verify_result); |
1151 EXPECT_EQ(ERR_CERT_REVOKED, error); | 1156 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); |
1152 | 1157 |
1153 // Second, test revocation by serial number of a cert directly under the | 1158 // Second, test revocation by serial number of a cert directly under the |
1154 // root. | 1159 // root. |
1155 crl_set_bytes.clear(); | 1160 crl_set_bytes.clear(); |
1156 EXPECT_TRUE(base::ReadFileToString( | 1161 EXPECT_TRUE(base::ReadFileToString( |
1157 GetTestCertsDirectory().AppendASCII("crlset_by_root_serial.raw"), | 1162 GetTestCertsDirectory().AppendASCII("crlset_by_root_serial.raw"), |
1158 &crl_set_bytes)); | 1163 &crl_set_bytes)); |
1159 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 1164 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); |
1160 | 1165 |
1161 error = Verify(cert.get(), | 1166 error = Verify(cert.get(), |
1162 "127.0.0.1", | 1167 "127.0.0.1", |
1163 flags, | 1168 flags, |
1164 crl_set.get(), | 1169 crl_set.get(), |
1165 empty_cert_list_, | 1170 empty_cert_list_, |
1166 &verify_result); | 1171 &verify_result); |
1167 EXPECT_EQ(ERR_CERT_REVOKED, error); | 1172 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); |
1168 } | 1173 } |
1169 | 1174 |
1170 TEST_F(CertVerifyProcTest, CRLSetLeafSerial) { | 1175 TEST_F(CertVerifyProcTest, CRLSetLeafSerial) { |
1171 CertificateList ca_cert_list = | 1176 CertificateList ca_cert_list = |
1172 CreateCertificateListFromFile(GetTestCertsDirectory(), | 1177 CreateCertificateListFromFile(GetTestCertsDirectory(), |
1173 "quic_root.crt", | 1178 "quic_root.crt", |
1174 X509Certificate::FORMAT_AUTO); | 1179 X509Certificate::FORMAT_AUTO); |
1175 ASSERT_EQ(1U, ca_cert_list.size()); | 1180 ASSERT_EQ(1U, ca_cert_list.size()); |
1176 ScopedTestRoot test_root(ca_cert_list[0].get()); | 1181 ScopedTestRoot test_root(ca_cert_list[0].get()); |
1177 | 1182 |
(...skipping 15 matching lines...) Expand all Loading... |
1193 intermediates); | 1198 intermediates); |
1194 | 1199 |
1195 int flags = 0; | 1200 int flags = 0; |
1196 CertVerifyResult verify_result; | 1201 CertVerifyResult verify_result; |
1197 int error = Verify(leaf.get(), | 1202 int error = Verify(leaf.get(), |
1198 "test.example.com", | 1203 "test.example.com", |
1199 flags, | 1204 flags, |
1200 NULL, | 1205 NULL, |
1201 empty_cert_list_, | 1206 empty_cert_list_, |
1202 &verify_result); | 1207 &verify_result); |
1203 EXPECT_EQ(OK, error); | 1208 EXPECT_THAT(error, IsOk()); |
1204 EXPECT_EQ(CERT_STATUS_SHA1_SIGNATURE_PRESENT, verify_result.cert_status); | 1209 EXPECT_EQ(CERT_STATUS_SHA1_SIGNATURE_PRESENT, verify_result.cert_status); |
1205 | 1210 |
1206 // Test revocation by serial number of a certificate not under the root. | 1211 // Test revocation by serial number of a certificate not under the root. |
1207 scoped_refptr<CRLSet> crl_set; | 1212 scoped_refptr<CRLSet> crl_set; |
1208 std::string crl_set_bytes; | 1213 std::string crl_set_bytes; |
1209 ASSERT_TRUE(base::ReadFileToString( | 1214 ASSERT_TRUE(base::ReadFileToString( |
1210 GetTestCertsDirectory().AppendASCII("crlset_by_intermediate_serial.raw"), | 1215 GetTestCertsDirectory().AppendASCII("crlset_by_intermediate_serial.raw"), |
1211 &crl_set_bytes)); | 1216 &crl_set_bytes)); |
1212 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); | 1217 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); |
1213 | 1218 |
1214 error = Verify(leaf.get(), | 1219 error = Verify(leaf.get(), |
1215 "test.example.com", | 1220 "test.example.com", |
1216 flags, | 1221 flags, |
1217 crl_set.get(), | 1222 crl_set.get(), |
1218 empty_cert_list_, | 1223 empty_cert_list_, |
1219 &verify_result); | 1224 &verify_result); |
1220 EXPECT_EQ(ERR_CERT_REVOKED, error); | 1225 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); |
1221 } | 1226 } |
1222 | 1227 |
1223 // Tests that CRLSets participate in path building functions, and that as | 1228 // Tests that CRLSets participate in path building functions, and that as |
1224 // long as a valid path exists within the verification graph, verification | 1229 // long as a valid path exists within the verification graph, verification |
1225 // succeeds. | 1230 // succeeds. |
1226 // | 1231 // |
1227 // In this test, there are two roots (D and E), and three possible paths | 1232 // In this test, there are two roots (D and E), and three possible paths |
1228 // to validate a leaf (A): | 1233 // to validate a leaf (A): |
1229 // 1. A(B) -> B(C) -> C(D) -> D(D) | 1234 // 1. A(B) -> B(C) -> C(D) -> D(D) |
1230 // 2. A(B) -> B(C) -> C(E) -> E(E) | 1235 // 2. A(B) -> B(C) -> C(E) -> E(E) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 CertVerifyResult verify_result; | 1307 CertVerifyResult verify_result; |
1303 int error = Verify(cert.get(), "127.0.0.1", flags, crl_set.get(), | 1308 int error = Verify(cert.get(), "127.0.0.1", flags, crl_set.get(), |
1304 empty_cert_list_, &verify_result); | 1309 empty_cert_list_, &verify_result); |
1305 | 1310 |
1306 if (!testcase.expect_valid) { | 1311 if (!testcase.expect_valid) { |
1307 EXPECT_NE(OK, error); | 1312 EXPECT_NE(OK, error); |
1308 EXPECT_NE(0U, verify_result.cert_status); | 1313 EXPECT_NE(0U, verify_result.cert_status); |
1309 continue; | 1314 continue; |
1310 } | 1315 } |
1311 | 1316 |
1312 ASSERT_EQ(OK, error); | 1317 ASSERT_THAT(error, IsOk()); |
1313 ASSERT_EQ(0U, verify_result.cert_status); | 1318 ASSERT_EQ(0U, verify_result.cert_status); |
1314 ASSERT_TRUE(verify_result.verified_cert.get()); | 1319 ASSERT_TRUE(verify_result.verified_cert.get()); |
1315 | 1320 |
1316 if (!testcase.expected_intermediate) | 1321 if (!testcase.expected_intermediate) |
1317 continue; | 1322 continue; |
1318 | 1323 |
1319 const X509Certificate::OSCertHandles& verified_intermediates = | 1324 const X509Certificate::OSCertHandles& verified_intermediates = |
1320 verify_result.verified_cert->GetIntermediateCertificates(); | 1325 verify_result.verified_cert->GetIntermediateCertificates(); |
1321 ASSERT_EQ(3U, verified_intermediates.size()); | 1326 ASSERT_EQ(3U, verified_intermediates.size()); |
1322 | 1327 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 } | 1432 } |
1428 | 1433 |
1429 // If a root cert is present, then check that the chain was rejected if any | 1434 // If a root cert is present, then check that the chain was rejected if any |
1430 // weak algorithms are present. This is only checked when a root cert is | 1435 // weak algorithms are present. This is only checked when a root cert is |
1431 // present because the error reported for incomplete chains with weak | 1436 // present because the error reported for incomplete chains with weak |
1432 // algorithms depends on which implementation was used to validate (NSS, | 1437 // algorithms depends on which implementation was used to validate (NSS, |
1433 // OpenSSL, CryptoAPI, Security.framework) and upon which weak algorithm | 1438 // OpenSSL, CryptoAPI, Security.framework) and upon which weak algorithm |
1434 // present (MD2, MD4, MD5). | 1439 // present (MD2, MD4, MD5). |
1435 if (data.root_cert_filename) { | 1440 if (data.root_cert_filename) { |
1436 if (data.expected_algorithms & (EXPECT_MD2 | EXPECT_MD4)) { | 1441 if (data.expected_algorithms & (EXPECT_MD2 | EXPECT_MD4)) { |
1437 EXPECT_EQ(ERR_CERT_INVALID, rv); | 1442 EXPECT_THAT(rv, IsError(ERR_CERT_INVALID)); |
1438 } else if (data.expected_algorithms & EXPECT_MD5) { | 1443 } else if (data.expected_algorithms & EXPECT_MD5) { |
1439 EXPECT_EQ(ERR_CERT_WEAK_SIGNATURE_ALGORITHM, rv); | 1444 EXPECT_THAT(rv, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); |
1440 } else { | 1445 } else { |
1441 EXPECT_EQ(OK, rv); | 1446 EXPECT_THAT(rv, IsOk()); |
1442 } | 1447 } |
1443 } | 1448 } |
1444 } | 1449 } |
1445 | 1450 |
1446 // Unlike TEST/TEST_F, which are macros that expand to further macros, | 1451 // Unlike TEST/TEST_F, which are macros that expand to further macros, |
1447 // INSTANTIATE_TEST_CASE_P is a macro that expands directly to code that | 1452 // INSTANTIATE_TEST_CASE_P is a macro that expands directly to code that |
1448 // stringizes the arguments. As a result, macros passed as parameters (such as | 1453 // stringizes the arguments. As a result, macros passed as parameters (such as |
1449 // prefix or test_case_name) will not be expanded by the preprocessor. To work | 1454 // prefix or test_case_name) will not be expanded by the preprocessor. To work |
1450 // around this, indirect the macro for INSTANTIATE_TEST_CASE_P, so that the | 1455 // around this, indirect the macro for INSTANTIATE_TEST_CASE_P, so that the |
1451 // pre-processor will expand macros such as MAYBE_test_name before | 1456 // pre-processor will expand macros such as MAYBE_test_name before |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1640 X509Certificate::FORMAT_AUTO); | 1645 X509Certificate::FORMAT_AUTO); |
1641 ASSERT_EQ(1U, cert_list.size()); | 1646 ASSERT_EQ(1U, cert_list.size()); |
1642 scoped_refptr<X509Certificate> cert(cert_list[0]); | 1647 scoped_refptr<X509Certificate> cert(cert_list[0]); |
1643 | 1648 |
1644 ScopedTestRoot scoped_root(cert.get()); | 1649 ScopedTestRoot scoped_root(cert.get()); |
1645 | 1650 |
1646 CertVerifyResult verify_result; | 1651 CertVerifyResult verify_result; |
1647 int error = Verify(cert.get(), data.hostname, 0, NULL, empty_cert_list_, | 1652 int error = Verify(cert.get(), data.hostname, 0, NULL, empty_cert_list_, |
1648 &verify_result); | 1653 &verify_result); |
1649 if (data.valid) { | 1654 if (data.valid) { |
1650 EXPECT_EQ(OK, error); | 1655 EXPECT_THAT(error, IsOk()); |
1651 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); | 1656 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); |
1652 } else { | 1657 } else { |
1653 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error); | 1658 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); |
1654 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); | 1659 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); |
1655 } | 1660 } |
1656 } | 1661 } |
1657 | 1662 |
1658 WRAPPED_INSTANTIATE_TEST_CASE_P( | 1663 WRAPPED_INSTANTIATE_TEST_CASE_P( |
1659 VerifyName, | 1664 VerifyName, |
1660 CertVerifyProcNameTest, | 1665 CertVerifyProcNameTest, |
1661 testing::ValuesIn(kVerifyNameData)); | 1666 testing::ValuesIn(kVerifyNameData)); |
1662 | 1667 |
1663 #if defined(OS_MACOSX) && !defined(OS_IOS) | 1668 #if defined(OS_MACOSX) && !defined(OS_IOS) |
1664 // Test that CertVerifyProcMac reacts appropriately when Apple's certificate | 1669 // Test that CertVerifyProcMac reacts appropriately when Apple's certificate |
1665 // verifier rejects a certificate with a fatal error. This is a regression | 1670 // verifier rejects a certificate with a fatal error. This is a regression |
1666 // test for https://crbug.com/472291. | 1671 // test for https://crbug.com/472291. |
1667 TEST_F(CertVerifyProcTest, LargeKey) { | 1672 TEST_F(CertVerifyProcTest, LargeKey) { |
1668 // Load root_ca_cert.pem into the test root store. | 1673 // Load root_ca_cert.pem into the test root store. |
1669 ScopedTestRoot test_root( | 1674 ScopedTestRoot test_root( |
1670 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); | 1675 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); |
1671 | 1676 |
1672 scoped_refptr<X509Certificate> cert( | 1677 scoped_refptr<X509Certificate> cert( |
1673 ImportCertFromFile(GetTestCertsDirectory(), "large_key.pem")); | 1678 ImportCertFromFile(GetTestCertsDirectory(), "large_key.pem")); |
1674 | 1679 |
1675 // Apple's verifier rejects this certificate as invalid because the | 1680 // Apple's verifier rejects this certificate as invalid because the |
1676 // RSA key is too large. If a future version of OS X changes this, | 1681 // RSA key is too large. If a future version of OS X changes this, |
1677 // large_key.pem may need to be regenerated with a larger key. | 1682 // large_key.pem may need to be regenerated with a larger key. |
1678 int flags = 0; | 1683 int flags = 0; |
1679 CertVerifyResult verify_result; | 1684 CertVerifyResult verify_result; |
1680 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 1685 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, |
1681 &verify_result); | 1686 &verify_result); |
1682 EXPECT_EQ(ERR_CERT_INVALID, error); | 1687 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); |
1683 EXPECT_EQ(CERT_STATUS_INVALID, verify_result.cert_status); | 1688 EXPECT_EQ(CERT_STATUS_INVALID, verify_result.cert_status); |
1684 } | 1689 } |
1685 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 1690 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
1686 | 1691 |
1687 } // namespace net | 1692 } // namespace net |
OLD | NEW |