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 11 matching lines...) Expand all Loading... |
22 #include "net/cert/test_root_certs.h" | 22 #include "net/cert/test_root_certs.h" |
23 #include "net/cert/x509_certificate.h" | 23 #include "net/cert/x509_certificate.h" |
24 #include "net/test/cert_test_util.h" | 24 #include "net/test/cert_test_util.h" |
25 #include "net/test/test_certificate_data.h" | 25 #include "net/test/test_certificate_data.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
27 | 27 |
28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
29 #include "base/win/windows_version.h" | 29 #include "base/win/windows_version.h" |
30 #elif defined(OS_MACOSX) && !defined(OS_IOS) | 30 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
31 #include "base/mac/mac_util.h" | 31 #include "base/mac/mac_util.h" |
| 32 #elif defined(OS_ANDROID) |
| 33 #include "base/android/build_info.h" |
32 #endif | 34 #endif |
33 | 35 |
34 using base::HexEncode; | 36 using base::HexEncode; |
35 | 37 |
36 namespace net { | 38 namespace net { |
37 | 39 |
38 namespace { | 40 namespace { |
39 | 41 |
40 // A certificate for www.paypal.com with a NULL byte in the common name. | 42 // A certificate for www.paypal.com with a NULL byte in the common name. |
41 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363 | 43 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 X509Certificate* cert, | 78 X509Certificate* cert, |
77 const std::string& hostname, | 79 const std::string& hostname, |
78 int flags, | 80 int flags, |
79 CRLSet* crl_set, | 81 CRLSet* crl_set, |
80 const CertificateList& additional_trust_anchors, | 82 const CertificateList& additional_trust_anchors, |
81 CertVerifyResult* verify_result) { | 83 CertVerifyResult* verify_result) { |
82 verify_result->is_issued_by_known_root = is_well_known_; | 84 verify_result->is_issued_by_known_root = is_well_known_; |
83 return OK; | 85 return OK; |
84 } | 86 } |
85 | 87 |
| 88 bool SupportsReturningVerifiedChain() { |
| 89 #if defined(OS_ANDROID) |
| 90 // Before API level 17, Android does not expose the APIs necessary to get at |
| 91 // the verified certificate chain. |
| 92 if (base::android::BuildInfo::GetInstance()->sdk_int() < 17) |
| 93 return false; |
| 94 #endif |
| 95 return true; |
| 96 } |
| 97 |
| 98 bool SupportsDetectingKnownRoots() { |
| 99 #if defined(OS_ANDROID) |
| 100 // Before API level 17, Android does not expose the APIs necessary to get at |
| 101 // the verified certificate chain and detect known roots. |
| 102 if (base::android::BuildInfo::GetInstance()->sdk_int() < 17) |
| 103 return false; |
| 104 #endif |
| 105 return true; |
| 106 } |
| 107 |
86 } // namespace | 108 } // namespace |
87 | 109 |
88 class CertVerifyProcTest : public testing::Test { | 110 class CertVerifyProcTest : public testing::Test { |
89 public: | 111 public: |
90 CertVerifyProcTest() | 112 CertVerifyProcTest() |
91 : verify_proc_(CertVerifyProc::CreateDefault()) { | 113 : verify_proc_(CertVerifyProc::CreateDefault()) { |
92 } | 114 } |
93 virtual ~CertVerifyProcTest() {} | 115 virtual ~CertVerifyProcTest() {} |
94 | 116 |
95 protected: | 117 protected: |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 } | 413 } |
392 } | 414 } |
393 } | 415 } |
394 | 416 |
395 // Regression test for http://crbug.com/108514. | 417 // Regression test for http://crbug.com/108514. |
396 #if defined(OS_MACOSX) && !defined(OS_IOS) | 418 #if defined(OS_MACOSX) && !defined(OS_IOS) |
397 // Disabled on OS X - Security.framework doesn't ignore superflous certificates | 419 // Disabled on OS X - Security.framework doesn't ignore superflous certificates |
398 // provided by servers. See CertVerifyProcTest.CybertrustGTERoot for further | 420 // provided by servers. See CertVerifyProcTest.CybertrustGTERoot for further |
399 // details. | 421 // details. |
400 #define MAYBE_ExtraneousMD5RootCert DISABLED_ExtraneousMD5RootCert | 422 #define MAYBE_ExtraneousMD5RootCert DISABLED_ExtraneousMD5RootCert |
401 #elif defined(USE_OPENSSL) || defined(OS_ANDROID) | |
402 // Disabled for OpenSSL / Android - Android and OpenSSL do not attempt to find | |
403 // a minimal certificate chain, thus prefer the MD5 root over the SHA-1 root. | |
404 #define MAYBE_ExtraneousMD5RootCert DISABLED_ExtraneousMD5RootCert | |
405 #else | 423 #else |
406 #define MAYBE_ExtraneousMD5RootCert ExtraneousMD5RootCert | 424 #define MAYBE_ExtraneousMD5RootCert ExtraneousMD5RootCert |
407 #endif | 425 #endif |
408 TEST_F(CertVerifyProcTest, MAYBE_ExtraneousMD5RootCert) { | 426 TEST_F(CertVerifyProcTest, MAYBE_ExtraneousMD5RootCert) { |
| 427 if (!SupportsReturningVerifiedChain()) { |
| 428 LOG(INFO) << "Skipping this test in this platform."; |
| 429 return; |
| 430 } |
| 431 |
409 base::FilePath certs_dir = GetTestCertsDirectory(); | 432 base::FilePath certs_dir = GetTestCertsDirectory(); |
410 | 433 |
411 scoped_refptr<X509Certificate> server_cert = | 434 scoped_refptr<X509Certificate> server_cert = |
412 ImportCertFromFile(certs_dir, "cross-signed-leaf.pem"); | 435 ImportCertFromFile(certs_dir, "cross-signed-leaf.pem"); |
413 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 436 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); |
414 | 437 |
415 scoped_refptr<X509Certificate> extra_cert = | 438 scoped_refptr<X509Certificate> extra_cert = |
416 ImportCertFromFile(certs_dir, "cross-signed-root-md5.pem"); | 439 ImportCertFromFile(certs_dir, "cross-signed-root-md5.pem"); |
417 ASSERT_NE(static_cast<X509Certificate*>(NULL), extra_cert.get()); | 440 ASSERT_NE(static_cast<X509Certificate*>(NULL), extra_cert.get()); |
418 | 441 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 int error = Verify(leaf.get(), | 570 int error = Verify(leaf.get(), |
548 "test.example.com", | 571 "test.example.com", |
549 flags, | 572 flags, |
550 NULL, | 573 NULL, |
551 empty_cert_list_, | 574 empty_cert_list_, |
552 &verify_result); | 575 &verify_result); |
553 EXPECT_EQ(OK, error); | 576 EXPECT_EQ(OK, error); |
554 EXPECT_EQ(0U, verify_result.cert_status); | 577 EXPECT_EQ(0U, verify_result.cert_status); |
555 } | 578 } |
556 | 579 |
557 #if defined(OS_ANDROID) | 580 TEST_F(CertVerifyProcTest, NameConstraintsFailure) { |
558 // Disabled because Android isn't filling in SPKI hashes: crbug.com/116838. | 581 if (!SupportsReturningVerifiedChain()) { |
559 #define MAYBE_NameConstraintsFailure DISABLED_NameConstraintsFailure | 582 LOG(INFO) << "Skipping this test in this platform."; |
560 #else | 583 return; |
561 #define MAYBE_NameConstraintsFailure NameConstraintsFailure | 584 } |
562 #endif | 585 |
563 TEST_F(CertVerifyProcTest, MAYBE_NameConstraintsFailure) { | |
564 CertificateList ca_cert_list = | 586 CertificateList ca_cert_list = |
565 CreateCertificateListFromFile(GetTestCertsDirectory(), | 587 CreateCertificateListFromFile(GetTestCertsDirectory(), |
566 "root_ca_cert.pem", | 588 "root_ca_cert.pem", |
567 X509Certificate::FORMAT_AUTO); | 589 X509Certificate::FORMAT_AUTO); |
568 ASSERT_EQ(1U, ca_cert_list.size()); | 590 ASSERT_EQ(1U, ca_cert_list.size()); |
569 ScopedTestRoot test_root(ca_cert_list[0]); | 591 ScopedTestRoot test_root(ca_cert_list[0]); |
570 | 592 |
571 CertificateList cert_list = CreateCertificateListFromFile( | 593 CertificateList cert_list = CreateCertificateListFromFile( |
572 GetTestCertsDirectory(), "name_constraint_bad.crt", | 594 GetTestCertsDirectory(), "name_constraint_bad.crt", |
573 X509Certificate::FORMAT_AUTO); | 595 X509Certificate::FORMAT_AUTO); |
(...skipping 10 matching lines...) Expand all Loading... |
584 "test.example.com", | 606 "test.example.com", |
585 flags, | 607 flags, |
586 NULL, | 608 NULL, |
587 empty_cert_list_, | 609 empty_cert_list_, |
588 &verify_result); | 610 &verify_result); |
589 EXPECT_EQ(ERR_CERT_NAME_CONSTRAINT_VIOLATION, error); | 611 EXPECT_EQ(ERR_CERT_NAME_CONSTRAINT_VIOLATION, error); |
590 EXPECT_EQ(CERT_STATUS_NAME_CONSTRAINT_VIOLATION, | 612 EXPECT_EQ(CERT_STATUS_NAME_CONSTRAINT_VIOLATION, |
591 verify_result.cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION); | 613 verify_result.cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION); |
592 } | 614 } |
593 | 615 |
594 // The certse.pem certificate has been revoked. crbug.com/259723. | |
595 TEST_F(CertVerifyProcTest, TestKnownRoot) { | 616 TEST_F(CertVerifyProcTest, TestKnownRoot) { |
| 617 if (!SupportsDetectingKnownRoots()) { |
| 618 LOG(INFO) << "Skipping this test in this platform."; |
| 619 return; |
| 620 } |
| 621 |
596 base::FilePath certs_dir = GetTestCertsDirectory(); | 622 base::FilePath certs_dir = GetTestCertsDirectory(); |
597 CertificateList certs = CreateCertificateListFromFile( | 623 CertificateList certs = CreateCertificateListFromFile( |
598 certs_dir, "satveda.pem", X509Certificate::FORMAT_AUTO); | 624 certs_dir, "satveda.pem", X509Certificate::FORMAT_AUTO); |
599 ASSERT_EQ(2U, certs.size()); | 625 ASSERT_EQ(2U, certs.size()); |
600 | 626 |
601 X509Certificate::OSCertHandles intermediates; | 627 X509Certificate::OSCertHandles intermediates; |
602 intermediates.push_back(certs[1]->os_cert_handle()); | 628 intermediates.push_back(certs[1]->os_cert_handle()); |
603 | 629 |
604 scoped_refptr<X509Certificate> cert_chain = | 630 scoped_refptr<X509Certificate> cert_chain = |
605 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 631 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
606 intermediates); | 632 intermediates); |
607 | 633 |
608 int flags = 0; | 634 int flags = 0; |
609 CertVerifyResult verify_result; | 635 CertVerifyResult verify_result; |
610 // This will blow up, May 24th, 2019. Sorry! Please disable and file a bug | 636 // This will blow up, May 24th, 2019. Sorry! Please disable and file a bug |
611 // against agl. See also PublicKeyHashes. | 637 // against agl. See also PublicKeyHashes. |
612 int error = Verify(cert_chain.get(), | 638 int error = Verify(cert_chain.get(), |
613 "satveda.com", | 639 "satveda.com", |
614 flags, | 640 flags, |
615 NULL, | 641 NULL, |
616 empty_cert_list_, | 642 empty_cert_list_, |
617 &verify_result); | 643 &verify_result); |
618 EXPECT_EQ(OK, error); | 644 EXPECT_EQ(OK, error); |
619 EXPECT_EQ(0U, verify_result.cert_status); | 645 EXPECT_EQ(0U, verify_result.cert_status); |
620 EXPECT_TRUE(verify_result.is_issued_by_known_root); | 646 EXPECT_TRUE(verify_result.is_issued_by_known_root); |
621 } | 647 } |
622 | 648 |
623 // The certse.pem certificate has been revoked. crbug.com/259723. | 649 // The certse.pem certificate has been revoked. crbug.com/259723. |
624 TEST_F(CertVerifyProcTest, PublicKeyHashes) { | 650 TEST_F(CertVerifyProcTest, PublicKeyHashes) { |
| 651 if (!SupportsReturningVerifiedChain()) { |
| 652 LOG(INFO) << "Skipping this test in this platform."; |
| 653 return; |
| 654 } |
| 655 |
625 base::FilePath certs_dir = GetTestCertsDirectory(); | 656 base::FilePath certs_dir = GetTestCertsDirectory(); |
626 CertificateList certs = CreateCertificateListFromFile( | 657 CertificateList certs = CreateCertificateListFromFile( |
627 certs_dir, "satveda.pem", X509Certificate::FORMAT_AUTO); | 658 certs_dir, "satveda.pem", X509Certificate::FORMAT_AUTO); |
628 ASSERT_EQ(2U, certs.size()); | 659 ASSERT_EQ(2U, certs.size()); |
629 | 660 |
630 X509Certificate::OSCertHandles intermediates; | 661 X509Certificate::OSCertHandles intermediates; |
631 intermediates.push_back(certs[1]->os_cert_handle()); | 662 intermediates.push_back(certs[1]->os_cert_handle()); |
632 | 663 |
633 scoped_refptr<X509Certificate> cert_chain = | 664 scoped_refptr<X509Certificate> cert_chain = |
634 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 665 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 #endif | 741 #endif |
711 } | 742 } |
712 | 743 |
713 // Basic test for returning the chain in CertVerifyResult. Note that the | 744 // Basic test for returning the chain in CertVerifyResult. Note that the |
714 // returned chain may just be a reflection of the originally supplied chain; | 745 // returned chain may just be a reflection of the originally supplied chain; |
715 // that is, if any errors occur, the default chain returned is an exact copy | 746 // that is, if any errors occur, the default chain returned is an exact copy |
716 // of the certificate to be verified. The remaining VerifyReturn* tests are | 747 // of the certificate to be verified. The remaining VerifyReturn* tests are |
717 // used to ensure that the actual, verified chain is being returned by | 748 // used to ensure that the actual, verified chain is being returned by |
718 // Verify(). | 749 // Verify(). |
719 TEST_F(CertVerifyProcTest, VerifyReturnChainBasic) { | 750 TEST_F(CertVerifyProcTest, VerifyReturnChainBasic) { |
| 751 if (!SupportsReturningVerifiedChain()) { |
| 752 LOG(INFO) << "Skipping this test in this platform."; |
| 753 return; |
| 754 } |
| 755 |
720 base::FilePath certs_dir = GetTestCertsDirectory(); | 756 base::FilePath certs_dir = GetTestCertsDirectory(); |
721 CertificateList certs = CreateCertificateListFromFile( | 757 CertificateList certs = CreateCertificateListFromFile( |
722 certs_dir, "x509_verify_results.chain.pem", | 758 certs_dir, "x509_verify_results.chain.pem", |
723 X509Certificate::FORMAT_AUTO); | 759 X509Certificate::FORMAT_AUTO); |
724 ASSERT_EQ(3U, certs.size()); | 760 ASSERT_EQ(3U, certs.size()); |
725 | 761 |
726 X509Certificate::OSCertHandles intermediates; | 762 X509Certificate::OSCertHandles intermediates; |
727 intermediates.push_back(certs[1]->os_cert_handle()); | 763 intermediates.push_back(certs[1]->os_cert_handle()); |
728 intermediates.push_back(certs[2]->os_cert_handle()); | 764 intermediates.push_back(certs[2]->os_cert_handle()); |
729 | 765 |
(...skipping 22 matching lines...) Expand all Loading... |
752 verify_result.verified_cert->os_cert_handle())); | 788 verify_result.verified_cert->os_cert_handle())); |
753 const X509Certificate::OSCertHandles& return_intermediates = | 789 const X509Certificate::OSCertHandles& return_intermediates = |
754 verify_result.verified_cert->GetIntermediateCertificates(); | 790 verify_result.verified_cert->GetIntermediateCertificates(); |
755 ASSERT_EQ(2U, return_intermediates.size()); | 791 ASSERT_EQ(2U, return_intermediates.size()); |
756 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 792 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], |
757 certs[1]->os_cert_handle())); | 793 certs[1]->os_cert_handle())); |
758 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 794 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], |
759 certs[2]->os_cert_handle())); | 795 certs[2]->os_cert_handle())); |
760 } | 796 } |
761 | 797 |
762 #if defined(OS_ANDROID) | |
763 // TODO(ppi): Disabled because is_issued_by_known_root is incorrect on Android. | |
764 // Once this is fixed, re-enable this check for android. crbug.com/116838 | |
765 #define MAYBE_IntranetHostsRejected DISABLED_IntranetHostsRejected | |
766 #else | |
767 #define MAYBE_IntranetHostsRejected IntranetHostsRejected | |
768 #endif | |
769 | |
770 // Test that certificates issued for 'intranet' names (that is, containing no | 798 // Test that certificates issued for 'intranet' names (that is, containing no |
771 // known public registry controlled domain information) issued by well-known | 799 // known public registry controlled domain information) issued by well-known |
772 // CAs are flagged appropriately, while certificates that are issued by | 800 // CAs are flagged appropriately, while certificates that are issued by |
773 // internal CAs are not flagged. | 801 // internal CAs are not flagged. |
774 TEST_F(CertVerifyProcTest, MAYBE_IntranetHostsRejected) { | 802 TEST_F(CertVerifyProcTest, IntranetHostsRejected) { |
| 803 if (!SupportsDetectingKnownRoots()) { |
| 804 LOG(INFO) << "Skipping this test in this platform."; |
| 805 return; |
| 806 } |
| 807 |
775 CertificateList cert_list = CreateCertificateListFromFile( | 808 CertificateList cert_list = CreateCertificateListFromFile( |
776 GetTestCertsDirectory(), "ok_cert.pem", | 809 GetTestCertsDirectory(), "ok_cert.pem", |
777 X509Certificate::FORMAT_AUTO); | 810 X509Certificate::FORMAT_AUTO); |
778 ASSERT_EQ(1U, cert_list.size()); | 811 ASSERT_EQ(1U, cert_list.size()); |
779 scoped_refptr<X509Certificate> cert(cert_list[0]); | 812 scoped_refptr<X509Certificate> cert(cert_list[0]); |
780 | 813 |
781 CertVerifyResult verify_result; | 814 CertVerifyResult verify_result; |
782 int error = 0; | 815 int error = 0; |
783 | 816 |
784 // Intranet names for public CAs should be flagged: | 817 // Intranet names for public CAs should be flagged: |
(...skipping 10 matching lines...) Expand all Loading... |
795 EXPECT_EQ(OK, error); | 828 EXPECT_EQ(OK, error); |
796 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); | 829 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); |
797 } | 830 } |
798 | 831 |
799 // Test that the certificate returned in CertVerifyResult is able to reorder | 832 // Test that the certificate returned in CertVerifyResult is able to reorder |
800 // certificates that are not ordered from end-entity to root. While this is | 833 // certificates that are not ordered from end-entity to root. While this is |
801 // a protocol violation if sent during a TLS handshake, if multiple sources | 834 // a protocol violation if sent during a TLS handshake, if multiple sources |
802 // of intermediate certificates are combined, it's possible that order may | 835 // of intermediate certificates are combined, it's possible that order may |
803 // not be maintained. | 836 // not be maintained. |
804 TEST_F(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) { | 837 TEST_F(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) { |
| 838 if (!SupportsReturningVerifiedChain()) { |
| 839 LOG(INFO) << "Skipping this test in this platform."; |
| 840 return; |
| 841 } |
| 842 |
805 base::FilePath certs_dir = GetTestCertsDirectory(); | 843 base::FilePath certs_dir = GetTestCertsDirectory(); |
806 CertificateList certs = CreateCertificateListFromFile( | 844 CertificateList certs = CreateCertificateListFromFile( |
807 certs_dir, "x509_verify_results.chain.pem", | 845 certs_dir, "x509_verify_results.chain.pem", |
808 X509Certificate::FORMAT_AUTO); | 846 X509Certificate::FORMAT_AUTO); |
809 ASSERT_EQ(3U, certs.size()); | 847 ASSERT_EQ(3U, certs.size()); |
810 | 848 |
811 // Construct the chain out of order. | 849 // Construct the chain out of order. |
812 X509Certificate::OSCertHandles intermediates; | 850 X509Certificate::OSCertHandles intermediates; |
813 intermediates.push_back(certs[2]->os_cert_handle()); | 851 intermediates.push_back(certs[2]->os_cert_handle()); |
814 intermediates.push_back(certs[1]->os_cert_handle()); | 852 intermediates.push_back(certs[1]->os_cert_handle()); |
(...skipping 26 matching lines...) Expand all Loading... |
841 ASSERT_EQ(2U, return_intermediates.size()); | 879 ASSERT_EQ(2U, return_intermediates.size()); |
842 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 880 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], |
843 certs[1]->os_cert_handle())); | 881 certs[1]->os_cert_handle())); |
844 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 882 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], |
845 certs[2]->os_cert_handle())); | 883 certs[2]->os_cert_handle())); |
846 } | 884 } |
847 | 885 |
848 // Test that Verify() filters out certificates which are not related to | 886 // Test that Verify() filters out certificates which are not related to |
849 // or part of the certificate chain being verified. | 887 // or part of the certificate chain being verified. |
850 TEST_F(CertVerifyProcTest, VerifyReturnChainFiltersUnrelatedCerts) { | 888 TEST_F(CertVerifyProcTest, VerifyReturnChainFiltersUnrelatedCerts) { |
| 889 if (!SupportsReturningVerifiedChain()) { |
| 890 LOG(INFO) << "Skipping this test in this platform."; |
| 891 return; |
| 892 } |
| 893 |
851 base::FilePath certs_dir = GetTestCertsDirectory(); | 894 base::FilePath certs_dir = GetTestCertsDirectory(); |
852 CertificateList certs = CreateCertificateListFromFile( | 895 CertificateList certs = CreateCertificateListFromFile( |
853 certs_dir, "x509_verify_results.chain.pem", | 896 certs_dir, "x509_verify_results.chain.pem", |
854 X509Certificate::FORMAT_AUTO); | 897 X509Certificate::FORMAT_AUTO); |
855 ASSERT_EQ(3U, certs.size()); | 898 ASSERT_EQ(3U, certs.size()); |
856 ScopedTestRoot scoped_root(certs[2].get()); | 899 ScopedTestRoot scoped_root(certs[2].get()); |
857 | 900 |
858 scoped_refptr<X509Certificate> unrelated_certificate = | 901 scoped_refptr<X509Certificate> unrelated_certificate = |
859 ImportCertFromFile(certs_dir, "duplicate_cn_1.pem"); | 902 ImportCertFromFile(certs_dir, "duplicate_cn_1.pem"); |
860 scoped_refptr<X509Certificate> unrelated_certificate2 = | 903 scoped_refptr<X509Certificate> unrelated_certificate2 = |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 | 982 |
940 // Clearing the |trust_anchors| makes verification fail again (the cache | 983 // Clearing the |trust_anchors| makes verification fail again (the cache |
941 // should be skipped). | 984 // should be skipped). |
942 error = Verify( | 985 error = Verify( |
943 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 986 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); |
944 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); | 987 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); |
945 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); | 988 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); |
946 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); | 989 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); |
947 } | 990 } |
948 | 991 |
| 992 // Tests that certificates issued by user-supplied roots are not flagged as |
| 993 // issued by a known root. This should pass whether or not the platform supports |
| 994 // detecting known roots. |
| 995 TEST_F(CertVerifyProcTest, IsIssuedByKnownRootIgnoresTestRoots) { |
| 996 // Load root_ca_cert.pem into the test root store. |
| 997 TestRootCerts* root_certs = TestRootCerts::GetInstance(); |
| 998 root_certs->AddFromFile( |
| 999 GetTestCertsDirectory().AppendASCII("root_ca_cert.pem")); |
| 1000 |
| 1001 CertificateList cert_list = CreateCertificateListFromFile( |
| 1002 GetTestCertsDirectory(), "ok_cert.pem", |
| 1003 X509Certificate::FORMAT_AUTO); |
| 1004 ASSERT_EQ(1U, cert_list.size()); |
| 1005 scoped_refptr<X509Certificate> cert(cert_list[0]); |
| 1006 |
| 1007 // Verification should pass. |
| 1008 int flags = 0; |
| 1009 CertVerifyResult verify_result; |
| 1010 int error = Verify( |
| 1011 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); |
| 1012 EXPECT_EQ(OK, error); |
| 1013 EXPECT_EQ(0U, verify_result.cert_status); |
| 1014 // But should not be marked as a known root. |
| 1015 EXPECT_FALSE(verify_result.is_issued_by_known_root); |
| 1016 } |
| 1017 |
949 #if defined(OS_MACOSX) && !defined(OS_IOS) | 1018 #if defined(OS_MACOSX) && !defined(OS_IOS) |
950 // Tests that, on OS X, issues with a cross-certified Baltimore CyberTrust | 1019 // Tests that, on OS X, issues with a cross-certified Baltimore CyberTrust |
951 // Root can be successfully worked around once Apple completes removing the | 1020 // Root can be successfully worked around once Apple completes removing the |
952 // older GTE CyberTrust Root from its trusted root store. | 1021 // older GTE CyberTrust Root from its trusted root store. |
953 // | 1022 // |
954 // The issue is caused by servers supplying the cross-certified intermediate | 1023 // The issue is caused by servers supplying the cross-certified intermediate |
955 // (necessary for certain mobile platforms), which OS X does not recognize | 1024 // (necessary for certain mobile platforms), which OS X does not recognize |
956 // as already existing within its trust store. | 1025 // as already existing within its trust store. |
957 TEST_F(CertVerifyProcTest, CybertrustGTERoot) { | 1026 TEST_F(CertVerifyProcTest, CybertrustGTERoot) { |
958 CertificateList certs = CreateCertificateListFromFile( | 1027 CertificateList certs = CreateCertificateListFromFile( |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1524 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); | 1593 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); |
1525 } | 1594 } |
1526 } | 1595 } |
1527 | 1596 |
1528 WRAPPED_INSTANTIATE_TEST_CASE_P( | 1597 WRAPPED_INSTANTIATE_TEST_CASE_P( |
1529 VerifyName, | 1598 VerifyName, |
1530 CertVerifyProcNameTest, | 1599 CertVerifyProcNameTest, |
1531 testing::ValuesIn(kVerifyNameData)); | 1600 testing::ValuesIn(kVerifyNameData)); |
1532 | 1601 |
1533 } // namespace net | 1602 } // namespace net |
OLD | NEW |