| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/internal/path_builder.h" | 5 #include "net/cert/internal/path_builder.h" |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/cancelable_callback.h" | 8 #include "base/cancelable_callback.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 *out_req = std::move(req); | 93 *out_req = std::move(req); |
| 94 } | 94 } |
| 95 int num_async_gets() const { return num_async_gets_; } | 95 int num_async_gets() const { return num_async_gets_; } |
| 96 | 96 |
| 97 private: | 97 private: |
| 98 CertIssuerSourceStatic static_cert_issuer_source_; | 98 CertIssuerSourceStatic static_cert_issuer_source_; |
| 99 | 99 |
| 100 int num_async_gets_ = 0; | 100 int num_async_gets_ = 0; |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 // Reads a data file from the unit-test data. | |
| 104 std::string ReadTestFileToString(const std::string& file_name) { | |
| 105 // Compute the full path, relative to the src/ directory. | |
| 106 base::FilePath src_root; | |
| 107 PathService::Get(base::DIR_SOURCE_ROOT, &src_root); | |
| 108 base::FilePath filepath = src_root.AppendASCII(file_name); | |
| 109 | |
| 110 // Read the full contents of the file. | |
| 111 std::string file_data; | |
| 112 if (!base::ReadFileToString(filepath, &file_data)) { | |
| 113 ADD_FAILURE() << "Couldn't read file: " << filepath.value(); | |
| 114 return std::string(); | |
| 115 } | |
| 116 | |
| 117 return file_data; | |
| 118 } | |
| 119 | |
| 120 // Reads a verify_certificate_chain_unittest-style test case from |file_name|. | |
| 121 // Test cases are comprised of a certificate chain, trust store, a timestamp to | |
| 122 // validate at, and the expected result of verification (though the expected | |
| 123 // result is ignored here). | |
| 124 void ReadVerifyCertChainTestFromFile(const std::string& file_name, | |
| 125 std::vector<std::string>* chain, | |
| 126 scoped_refptr<ParsedCertificate>* root, | |
| 127 der::GeneralizedTime* time) { | |
| 128 chain->clear(); | |
| 129 | |
| 130 std::string file_data = ReadTestFileToString(file_name); | |
| 131 | |
| 132 std::vector<std::string> pem_headers; | |
| 133 | |
| 134 const char kCertificateHeader[] = "CERTIFICATE"; | |
| 135 const char kTrustedCertificateHeader[] = "TRUSTED_CERTIFICATE"; | |
| 136 const char kTimeHeader[] = "TIME"; | |
| 137 | |
| 138 pem_headers.push_back(kCertificateHeader); | |
| 139 pem_headers.push_back(kTrustedCertificateHeader); | |
| 140 pem_headers.push_back(kTimeHeader); | |
| 141 | |
| 142 bool has_time = false; | |
| 143 | |
| 144 PEMTokenizer pem_tokenizer(file_data, pem_headers); | |
| 145 while (pem_tokenizer.GetNext()) { | |
| 146 const std::string& block_type = pem_tokenizer.block_type(); | |
| 147 const std::string& block_data = pem_tokenizer.data(); | |
| 148 | |
| 149 if (block_type == kCertificateHeader) { | |
| 150 chain->push_back(block_data); | |
| 151 } else if (block_type == kTrustedCertificateHeader) { | |
| 152 *root = ParsedCertificate::CreateFromCertificateCopy(block_data, {}); | |
| 153 ASSERT_TRUE(*root); | |
| 154 } else if (block_type == kTimeHeader) { | |
| 155 ASSERT_FALSE(has_time) << "Duplicate " << kTimeHeader; | |
| 156 has_time = true; | |
| 157 ASSERT_TRUE(der::ParseUTCTime(der::Input(&block_data), time)); | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 ASSERT_TRUE(has_time); | |
| 162 } | |
| 163 | |
| 164 ::testing::AssertionResult ReadTestPem(const std::string& file_name, | 103 ::testing::AssertionResult ReadTestPem(const std::string& file_name, |
| 165 const std::string& block_name, | 104 const std::string& block_name, |
| 166 std::string* result) { | 105 std::string* result) { |
| 167 const PemBlockMapping mappings[] = { | 106 const PemBlockMapping mappings[] = { |
| 168 {block_name.c_str(), result}, | 107 {block_name.c_str(), result}, |
| 169 }; | 108 }; |
| 170 | 109 |
| 171 return ReadTestDataFromPemFile(file_name, mappings); | 110 return ReadTestDataFromPemFile(file_name, mappings); |
| 172 } | 111 } |
| 173 | 112 |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 EXPECT_EQ(c_by_d_, path.certs[2]); | 480 EXPECT_EQ(c_by_d_, path.certs[2]); |
| 542 EXPECT_EQ(d_by_d_, path.trust_anchor->cert()); | 481 EXPECT_EQ(d_by_d_, path.trust_anchor->cert()); |
| 543 } | 482 } |
| 544 } | 483 } |
| 545 | 484 |
| 546 class PathBuilderKeyRolloverTest : public ::testing::Test { | 485 class PathBuilderKeyRolloverTest : public ::testing::Test { |
| 547 public: | 486 public: |
| 548 PathBuilderKeyRolloverTest() : signature_policy_(1024) {} | 487 PathBuilderKeyRolloverTest() : signature_policy_(1024) {} |
| 549 | 488 |
| 550 void SetUp() override { | 489 void SetUp() override { |
| 551 std::vector<std::string> path; | 490 ParsedCertificateList path; |
| 491 bool unused; |
| 552 | 492 |
| 553 ReadVerifyCertChainTestFromFile( | 493 ReadVerifyCertChainTestFromFile("key-rollover-oldchain.pem", &path, |
| 554 "net/data/verify_certificate_chain_unittest/key-rollover-oldchain.pem", | 494 &oldroot_, &time_, &unused); |
| 555 &path, &oldroot_, &time_); | |
| 556 ASSERT_EQ(2U, path.size()); | 495 ASSERT_EQ(2U, path.size()); |
| 557 target_ = ParsedCertificate::CreateFromCertificateCopy(path[0], {}); | 496 target_ = path[0]; |
| 558 oldintermediate_ = | 497 oldintermediate_ = path[1]; |
| 559 ParsedCertificate::CreateFromCertificateCopy(path[1], {}); | |
| 560 ASSERT_TRUE(target_); | 498 ASSERT_TRUE(target_); |
| 561 ASSERT_TRUE(oldintermediate_); | 499 ASSERT_TRUE(oldintermediate_); |
| 562 | 500 |
| 563 ReadVerifyCertChainTestFromFile( | 501 ReadVerifyCertChainTestFromFile("key-rollover-longrolloverchain.pem", &path, |
| 564 "net/data/verify_certificate_chain_unittest/" | 502 &oldroot_, &time_, &unused); |
| 565 "key-rollover-longrolloverchain.pem", | |
| 566 &path, &oldroot_, &time_); | |
| 567 ASSERT_EQ(4U, path.size()); | 503 ASSERT_EQ(4U, path.size()); |
| 568 newintermediate_ = | 504 newintermediate_ = path[1]; |
| 569 ParsedCertificate::CreateFromCertificateCopy(path[1], {}); | 505 newroot_ = path[2]; |
| 570 newroot_ = ParsedCertificate::CreateFromCertificateCopy(path[2], {}); | 506 newrootrollover_ = path[3]; |
| 571 newrootrollover_ = | |
| 572 ParsedCertificate::CreateFromCertificateCopy(path[3], {}); | |
| 573 ASSERT_TRUE(newintermediate_); | 507 ASSERT_TRUE(newintermediate_); |
| 574 ASSERT_TRUE(newroot_); | 508 ASSERT_TRUE(newroot_); |
| 575 ASSERT_TRUE(newrootrollover_); | 509 ASSERT_TRUE(newrootrollover_); |
| 576 } | 510 } |
| 577 | 511 |
| 578 protected: | 512 protected: |
| 579 // oldroot-------->newrootrollover newroot | 513 // oldroot-------->newrootrollover newroot |
| 580 // | | | | 514 // | | | |
| 581 // v v v | 515 // v v v |
| 582 // oldintermediate newintermediate | 516 // oldintermediate newintermediate |
| 583 // | | | 517 // | | |
| 584 // +------------+-------------+ | 518 // +------------+-------------+ |
| 585 // | | 519 // | |
| 586 // v | 520 // v |
| 587 // target | 521 // target |
| 588 scoped_refptr<ParsedCertificate> target_; | 522 scoped_refptr<ParsedCertificate> target_; |
| 589 scoped_refptr<ParsedCertificate> oldintermediate_; | 523 scoped_refptr<ParsedCertificate> oldintermediate_; |
| 590 scoped_refptr<ParsedCertificate> newintermediate_; | 524 scoped_refptr<ParsedCertificate> newintermediate_; |
| 591 scoped_refptr<ParsedCertificate> oldroot_; | 525 scoped_refptr<TrustAnchor> oldroot_; |
| 592 scoped_refptr<ParsedCertificate> newroot_; | 526 scoped_refptr<ParsedCertificate> newroot_; |
| 593 scoped_refptr<ParsedCertificate> newrootrollover_; | 527 scoped_refptr<ParsedCertificate> newrootrollover_; |
| 594 | 528 |
| 595 SimpleSignaturePolicy signature_policy_; | 529 SimpleSignaturePolicy signature_policy_; |
| 596 der::GeneralizedTime time_; | 530 der::GeneralizedTime time_; |
| 597 }; | 531 }; |
| 598 | 532 |
| 599 // Tests that if only the old root cert is trusted, the path builder can build a | 533 // Tests that if only the old root cert is trusted, the path builder can build a |
| 600 // path through the new intermediate and rollover cert to the old root. | 534 // path through the new intermediate and rollover cert to the old root. |
| 601 TEST_F(PathBuilderKeyRolloverTest, TestRolloverOnlyOldRootTrusted) { | 535 TEST_F(PathBuilderKeyRolloverTest, TestRolloverOnlyOldRootTrusted) { |
| 602 // Only oldroot is trusted. | 536 // Only oldroot is trusted. |
| 603 TrustStore trust_store; | 537 TrustStore trust_store; |
| 604 AddTrustedCertificate(oldroot_, &trust_store); | 538 trust_store.AddTrustAnchor(oldroot_); |
| 605 | 539 |
| 606 // Old intermediate cert is not provided, so the pathbuilder will need to go | 540 // Old intermediate cert is not provided, so the pathbuilder will need to go |
| 607 // through the rollover cert. | 541 // through the rollover cert. |
| 608 CertIssuerSourceStatic sync_certs; | 542 CertIssuerSourceStatic sync_certs; |
| 609 sync_certs.AddCert(newintermediate_); | 543 sync_certs.AddCert(newintermediate_); |
| 610 sync_certs.AddCert(newrootrollover_); | 544 sync_certs.AddCert(newrootrollover_); |
| 611 | 545 |
| 612 CertPathBuilder::Result result; | 546 CertPathBuilder::Result result; |
| 613 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, | 547 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, |
| 614 &result); | 548 &result); |
| 615 path_builder.AddCertIssuerSource(&sync_certs); | 549 path_builder.AddCertIssuerSource(&sync_certs); |
| 616 | 550 |
| 617 EXPECT_EQ(CompletionStatus::SYNC, RunPathBuilder(&path_builder)); | 551 EXPECT_EQ(CompletionStatus::SYNC, RunPathBuilder(&path_builder)); |
| 618 | 552 |
| 619 EXPECT_EQ(OK, result.error()); | 553 EXPECT_EQ(OK, result.error()); |
| 620 | 554 |
| 621 // Path builder will first attempt: target <- newintermediate <- oldroot | 555 // Path builder will first attempt: target <- newintermediate <- oldroot |
| 622 // but it will fail since newintermediate is signed by newroot. | 556 // but it will fail since newintermediate is signed by newroot. |
| 623 ASSERT_EQ(2U, result.paths.size()); | 557 ASSERT_EQ(2U, result.paths.size()); |
| 624 const auto& path0 = result.paths[0]->path; | 558 const auto& path0 = result.paths[0]->path; |
| 625 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, result.paths[0]->error); | 559 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, result.paths[0]->error); |
| 626 ASSERT_EQ(2U, path0.certs.size()); | 560 ASSERT_EQ(2U, path0.certs.size()); |
| 627 EXPECT_EQ(target_, path0.certs[0]); | 561 EXPECT_EQ(target_, path0.certs[0]); |
| 628 EXPECT_EQ(newintermediate_, path0.certs[1]); | 562 EXPECT_EQ(newintermediate_, path0.certs[1]); |
| 629 EXPECT_EQ(oldroot_, path0.trust_anchor->cert()); | 563 EXPECT_EQ(oldroot_, path0.trust_anchor); |
| 630 | 564 |
| 631 // Path builder will next attempt: | 565 // Path builder will next attempt: |
| 632 // target <- newintermediate <- newrootrollover <- oldroot | 566 // target <- newintermediate <- newrootrollover <- oldroot |
| 633 // which will succeed. | 567 // which will succeed. |
| 634 const auto& path1 = result.paths[1]->path; | 568 const auto& path1 = result.paths[1]->path; |
| 635 EXPECT_EQ(1U, result.best_result_index); | 569 EXPECT_EQ(1U, result.best_result_index); |
| 636 EXPECT_EQ(OK, result.paths[1]->error); | 570 EXPECT_EQ(OK, result.paths[1]->error); |
| 637 ASSERT_EQ(3U, path1.certs.size()); | 571 ASSERT_EQ(3U, path1.certs.size()); |
| 638 EXPECT_EQ(target_, path1.certs[0]); | 572 EXPECT_EQ(target_, path1.certs[0]); |
| 639 EXPECT_EQ(newintermediate_, path1.certs[1]); | 573 EXPECT_EQ(newintermediate_, path1.certs[1]); |
| 640 EXPECT_EQ(newrootrollover_, path1.certs[2]); | 574 EXPECT_EQ(newrootrollover_, path1.certs[2]); |
| 641 EXPECT_EQ(oldroot_, path1.trust_anchor->cert()); | 575 EXPECT_EQ(oldroot_, path1.trust_anchor); |
| 642 } | 576 } |
| 643 | 577 |
| 644 // Tests that if both old and new roots are trusted it can build a path through | 578 // Tests that if both old and new roots are trusted it can build a path through |
| 645 // either. | 579 // either. |
| 646 // TODO(mattm): Once prioritization is implemented, it should test that it | 580 // TODO(mattm): Once prioritization is implemented, it should test that it |
| 647 // always builds the path through the new intermediate and new root. | 581 // always builds the path through the new intermediate and new root. |
| 648 TEST_F(PathBuilderKeyRolloverTest, TestRolloverBothRootsTrusted) { | 582 TEST_F(PathBuilderKeyRolloverTest, TestRolloverBothRootsTrusted) { |
| 649 // Both oldroot and newroot are trusted. | 583 // Both oldroot and newroot are trusted. |
| 650 TrustStore trust_store; | 584 TrustStore trust_store; |
| 651 AddTrustedCertificate(oldroot_, &trust_store); | 585 trust_store.AddTrustAnchor(oldroot_); |
| 652 AddTrustedCertificate(newroot_, &trust_store); | 586 AddTrustedCertificate(newroot_, &trust_store); |
| 653 | 587 |
| 654 // Both old and new intermediates + rollover cert are provided. | 588 // Both old and new intermediates + rollover cert are provided. |
| 655 CertIssuerSourceStatic sync_certs; | 589 CertIssuerSourceStatic sync_certs; |
| 656 sync_certs.AddCert(oldintermediate_); | 590 sync_certs.AddCert(oldintermediate_); |
| 657 sync_certs.AddCert(newintermediate_); | 591 sync_certs.AddCert(newintermediate_); |
| 658 sync_certs.AddCert(newrootrollover_); | 592 sync_certs.AddCert(newrootrollover_); |
| 659 | 593 |
| 660 CertPathBuilder::Result result; | 594 CertPathBuilder::Result result; |
| 661 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, | 595 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, |
| 662 &result); | 596 &result); |
| 663 path_builder.AddCertIssuerSource(&sync_certs); | 597 path_builder.AddCertIssuerSource(&sync_certs); |
| 664 | 598 |
| 665 EXPECT_EQ(CompletionStatus::SYNC, RunPathBuilder(&path_builder)); | 599 EXPECT_EQ(CompletionStatus::SYNC, RunPathBuilder(&path_builder)); |
| 666 | 600 |
| 667 EXPECT_EQ(OK, result.error()); | 601 EXPECT_EQ(OK, result.error()); |
| 668 | 602 |
| 669 // Path builder willattempt one of: | 603 // Path builder willattempt one of: |
| 670 // target <- oldintermediate <- oldroot | 604 // target <- oldintermediate <- oldroot |
| 671 // target <- newintermediate <- newroot | 605 // target <- newintermediate <- newroot |
| 672 // either will succeed. | 606 // either will succeed. |
| 673 ASSERT_EQ(1U, result.paths.size()); | 607 ASSERT_EQ(1U, result.paths.size()); |
| 674 const auto& path = result.paths[0]->path; | 608 const auto& path = result.paths[0]->path; |
| 675 EXPECT_EQ(OK, result.paths[0]->error); | 609 EXPECT_EQ(OK, result.paths[0]->error); |
| 676 ASSERT_EQ(2U, path.certs.size()); | 610 ASSERT_EQ(2U, path.certs.size()); |
| 677 EXPECT_EQ(target_, path.certs[0]); | 611 EXPECT_EQ(target_, path.certs[0]); |
| 678 if (path.certs[1] != newintermediate_) { | 612 if (path.certs[1] != newintermediate_) { |
| 679 DVLOG(1) << "USED OLD"; | 613 DVLOG(1) << "USED OLD"; |
| 680 EXPECT_EQ(oldintermediate_, path.certs[1]); | 614 EXPECT_EQ(oldintermediate_, path.certs[1]); |
| 681 EXPECT_EQ(oldroot_, path.trust_anchor->cert()); | 615 EXPECT_EQ(oldroot_, path.trust_anchor); |
| 682 } else { | 616 } else { |
| 683 DVLOG(1) << "USED NEW"; | 617 DVLOG(1) << "USED NEW"; |
| 684 EXPECT_EQ(newintermediate_, path.certs[1]); | 618 EXPECT_EQ(newintermediate_, path.certs[1]); |
| 685 EXPECT_EQ(newroot_, path.trust_anchor->cert()); | 619 EXPECT_EQ(newroot_, path.trust_anchor->cert()); |
| 686 } | 620 } |
| 687 } | 621 } |
| 688 | 622 |
| 689 // Tests that multiple trust root matches on a single path will be considered. | 623 // Tests that multiple trust root matches on a single path will be considered. |
| 690 // Both roots have the same subject but different keys. Only one of them will | 624 // Both roots have the same subject but different keys. Only one of them will |
| 691 // verify. | 625 // verify. |
| 692 TEST_F(PathBuilderKeyRolloverTest, TestMultipleRootMatchesOnlyOneWorks) { | 626 TEST_F(PathBuilderKeyRolloverTest, TestMultipleRootMatchesOnlyOneWorks) { |
| 693 // Both newroot and oldroot are trusted. | 627 // Both newroot and oldroot are trusted. |
| 694 TrustStore trust_store; | 628 TrustStore trust_store; |
| 695 AddTrustedCertificate(newroot_, &trust_store); | 629 AddTrustedCertificate(newroot_, &trust_store); |
| 696 AddTrustedCertificate(oldroot_, &trust_store); | 630 trust_store.AddTrustAnchor(oldroot_); |
| 697 | 631 |
| 698 // Only oldintermediate is supplied, so the path with newroot should fail, | 632 // Only oldintermediate is supplied, so the path with newroot should fail, |
| 699 // oldroot should succeed. | 633 // oldroot should succeed. |
| 700 CertIssuerSourceStatic sync_certs; | 634 CertIssuerSourceStatic sync_certs; |
| 701 sync_certs.AddCert(oldintermediate_); | 635 sync_certs.AddCert(oldintermediate_); |
| 702 | 636 |
| 703 CertPathBuilder::Result result; | 637 CertPathBuilder::Result result; |
| 704 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, | 638 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, |
| 705 &result); | 639 &result); |
| 706 path_builder.AddCertIssuerSource(&sync_certs); | 640 path_builder.AddCertIssuerSource(&sync_certs); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 727 } | 661 } |
| 728 | 662 |
| 729 // Path builder will next attempt: | 663 // Path builder will next attempt: |
| 730 // target <- old intermediate <- oldroot | 664 // target <- old intermediate <- oldroot |
| 731 // which should succeed. | 665 // which should succeed. |
| 732 EXPECT_EQ(OK, result.paths[result.best_result_index]->error); | 666 EXPECT_EQ(OK, result.paths[result.best_result_index]->error); |
| 733 const auto& path = result.paths[result.best_result_index]->path; | 667 const auto& path = result.paths[result.best_result_index]->path; |
| 734 ASSERT_EQ(2U, path.certs.size()); | 668 ASSERT_EQ(2U, path.certs.size()); |
| 735 EXPECT_EQ(target_, path.certs[0]); | 669 EXPECT_EQ(target_, path.certs[0]); |
| 736 EXPECT_EQ(oldintermediate_, path.certs[1]); | 670 EXPECT_EQ(oldintermediate_, path.certs[1]); |
| 737 EXPECT_EQ(oldroot_, path.trust_anchor->cert()); | 671 EXPECT_EQ(oldroot_, path.trust_anchor); |
| 738 } | 672 } |
| 739 | 673 |
| 740 // Tests that the path builder doesn't build longer than necessary paths. | 674 // Tests that the path builder doesn't build longer than necessary paths. |
| 741 TEST_F(PathBuilderKeyRolloverTest, TestRolloverLongChain) { | 675 TEST_F(PathBuilderKeyRolloverTest, TestRolloverLongChain) { |
| 742 // Only oldroot is trusted. | 676 // Only oldroot is trusted. |
| 743 TrustStore trust_store; | 677 TrustStore trust_store; |
| 744 AddTrustedCertificate(oldroot_, &trust_store); | 678 trust_store.AddTrustAnchor(oldroot_); |
| 745 | 679 |
| 746 // New intermediate and new root are provided synchronously. | 680 // New intermediate and new root are provided synchronously. |
| 747 CertIssuerSourceStatic sync_certs; | 681 CertIssuerSourceStatic sync_certs; |
| 748 sync_certs.AddCert(newintermediate_); | 682 sync_certs.AddCert(newintermediate_); |
| 749 sync_certs.AddCert(newroot_); | 683 sync_certs.AddCert(newroot_); |
| 750 | 684 |
| 751 // Rollover cert is only provided asynchronously. This will force the | 685 // Rollover cert is only provided asynchronously. This will force the |
| 752 // pathbuilder to first try building a longer than necessary path. | 686 // pathbuilder to first try building a longer than necessary path. |
| 753 AsyncCertIssuerSourceStatic async_certs; | 687 AsyncCertIssuerSourceStatic async_certs; |
| 754 async_certs.AddCert(newrootrollover_); | 688 async_certs.AddCert(newrootrollover_); |
| 755 | 689 |
| 756 CertPathBuilder::Result result; | 690 CertPathBuilder::Result result; |
| 757 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, | 691 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, |
| 758 &result); | 692 &result); |
| 759 path_builder.AddCertIssuerSource(&sync_certs); | 693 path_builder.AddCertIssuerSource(&sync_certs); |
| 760 path_builder.AddCertIssuerSource(&async_certs); | 694 path_builder.AddCertIssuerSource(&async_certs); |
| 761 | 695 |
| 762 EXPECT_EQ(CompletionStatus::ASYNC, RunPathBuilder(&path_builder)); | 696 EXPECT_EQ(CompletionStatus::ASYNC, RunPathBuilder(&path_builder)); |
| 763 | 697 |
| 764 EXPECT_EQ(OK, result.error()); | 698 EXPECT_EQ(OK, result.error()); |
| 765 ASSERT_EQ(3U, result.paths.size()); | 699 ASSERT_EQ(3U, result.paths.size()); |
| 766 | 700 |
| 767 // Path builder will first attempt: target <- newintermediate <- oldroot | 701 // Path builder will first attempt: target <- newintermediate <- oldroot |
| 768 // but it will fail since newintermediate is signed by newroot. | 702 // but it will fail since newintermediate is signed by newroot. |
| 769 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, result.paths[0]->error); | 703 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, result.paths[0]->error); |
| 770 const auto& path0 = result.paths[0]->path; | 704 const auto& path0 = result.paths[0]->path; |
| 771 ASSERT_EQ(2U, path0.certs.size()); | 705 ASSERT_EQ(2U, path0.certs.size()); |
| 772 EXPECT_EQ(target_, path0.certs[0]); | 706 EXPECT_EQ(target_, path0.certs[0]); |
| 773 EXPECT_EQ(newintermediate_, path0.certs[1]); | 707 EXPECT_EQ(newintermediate_, path0.certs[1]); |
| 774 EXPECT_EQ(oldroot_, path0.trust_anchor->cert()); | 708 EXPECT_EQ(oldroot_, path0.trust_anchor); |
| 775 | 709 |
| 776 // Path builder will next attempt: | 710 // Path builder will next attempt: |
| 777 // target <- newintermediate <- newroot <- oldroot | 711 // target <- newintermediate <- newroot <- oldroot |
| 778 // but it will fail since newroot is self-signed. | 712 // but it will fail since newroot is self-signed. |
| 779 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, result.paths[1]->error); | 713 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, result.paths[1]->error); |
| 780 const auto& path1 = result.paths[1]->path; | 714 const auto& path1 = result.paths[1]->path; |
| 781 ASSERT_EQ(3U, path1.certs.size()); | 715 ASSERT_EQ(3U, path1.certs.size()); |
| 782 EXPECT_EQ(target_, path1.certs[0]); | 716 EXPECT_EQ(target_, path1.certs[0]); |
| 783 EXPECT_EQ(newintermediate_, path1.certs[1]); | 717 EXPECT_EQ(newintermediate_, path1.certs[1]); |
| 784 EXPECT_EQ(newroot_, path1.certs[2]); | 718 EXPECT_EQ(newroot_, path1.certs[2]); |
| 785 EXPECT_EQ(oldroot_, path1.trust_anchor->cert()); | 719 EXPECT_EQ(oldroot_, path1.trust_anchor); |
| 786 | 720 |
| 787 // Path builder will skip: | 721 // Path builder will skip: |
| 788 // target <- newintermediate <- newroot <- newrootrollover <- ... | 722 // target <- newintermediate <- newroot <- newrootrollover <- ... |
| 789 // Since newroot and newrootrollover have the same Name+SAN+SPKI. | 723 // Since newroot and newrootrollover have the same Name+SAN+SPKI. |
| 790 | 724 |
| 791 // Finally path builder will use: | 725 // Finally path builder will use: |
| 792 // target <- newintermediate <- newrootrollover <- oldroot | 726 // target <- newintermediate <- newrootrollover <- oldroot |
| 793 EXPECT_EQ(2U, result.best_result_index); | 727 EXPECT_EQ(2U, result.best_result_index); |
| 794 EXPECT_EQ(OK, result.paths[2]->error); | 728 EXPECT_EQ(OK, result.paths[2]->error); |
| 795 const auto& path2 = result.paths[2]->path; | 729 const auto& path2 = result.paths[2]->path; |
| 796 ASSERT_EQ(3U, path2.certs.size()); | 730 ASSERT_EQ(3U, path2.certs.size()); |
| 797 EXPECT_EQ(target_, path2.certs[0]); | 731 EXPECT_EQ(target_, path2.certs[0]); |
| 798 EXPECT_EQ(newintermediate_, path2.certs[1]); | 732 EXPECT_EQ(newintermediate_, path2.certs[1]); |
| 799 EXPECT_EQ(newrootrollover_, path2.certs[2]); | 733 EXPECT_EQ(newrootrollover_, path2.certs[2]); |
| 800 EXPECT_EQ(oldroot_, path2.trust_anchor->cert()); | 734 EXPECT_EQ(oldroot_, path2.trust_anchor); |
| 801 } | 735 } |
| 802 | 736 |
| 803 // If the target cert is a trust anchor, however is not itself *signed* by a | 737 // If the target cert is a trust anchor, however is not itself *signed* by a |
| 804 // trust anchor, then it is not considered valid (the SPKI and name of the | 738 // trust anchor, then it is not considered valid (the SPKI and name of the |
| 805 // trust anchor matches the SPKI and subject of the targe certificate, but the | 739 // trust anchor matches the SPKI and subject of the targe certificate, but the |
| 806 // rest of the certificate cannot be verified). | 740 // rest of the certificate cannot be verified). |
| 807 TEST_F(PathBuilderKeyRolloverTest, TestEndEntityIsTrustRoot) { | 741 TEST_F(PathBuilderKeyRolloverTest, TestEndEntityIsTrustRoot) { |
| 808 // Trust newintermediate. | 742 // Trust newintermediate. |
| 809 TrustStore trust_store; | 743 TrustStore trust_store; |
| 810 AddTrustedCertificate(newintermediate_, &trust_store); | 744 AddTrustedCertificate(newintermediate_, &trust_store); |
| 811 | 745 |
| 812 CertPathBuilder::Result result; | 746 CertPathBuilder::Result result; |
| 813 // Newintermediate is also the target cert. | 747 // Newintermediate is also the target cert. |
| 814 CertPathBuilder path_builder(newintermediate_, &trust_store, | 748 CertPathBuilder path_builder(newintermediate_, &trust_store, |
| 815 &signature_policy_, time_, &result); | 749 &signature_policy_, time_, &result); |
| 816 | 750 |
| 817 EXPECT_EQ(CompletionStatus::SYNC, RunPathBuilder(&path_builder)); | 751 EXPECT_EQ(CompletionStatus::SYNC, RunPathBuilder(&path_builder)); |
| 818 | 752 |
| 819 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, result.error()); | 753 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, result.error()); |
| 820 } | 754 } |
| 821 | 755 |
| 822 // If target has same Name+SAN+SPKI as a necessary intermediate, test if a path | 756 // If target has same Name+SAN+SPKI as a necessary intermediate, test if a path |
| 823 // can still be built. | 757 // can still be built. |
| 824 // Since LoopChecker will prevent the intermediate from being included, this | 758 // Since LoopChecker will prevent the intermediate from being included, this |
| 825 // currently does NOT verify. This case shouldn't occur in the web PKI. | 759 // currently does NOT verify. This case shouldn't occur in the web PKI. |
| 826 TEST_F(PathBuilderKeyRolloverTest, | 760 TEST_F(PathBuilderKeyRolloverTest, |
| 827 TestEndEntityHasSameNameAndSpkiAsIntermediate) { | 761 TestEndEntityHasSameNameAndSpkiAsIntermediate) { |
| 828 // Trust oldroot. | 762 // Trust oldroot. |
| 829 TrustStore trust_store; | 763 TrustStore trust_store; |
| 830 AddTrustedCertificate(oldroot_, &trust_store); | 764 trust_store.AddTrustAnchor(oldroot_); |
| 831 | 765 |
| 832 // New root rollover is provided synchronously. | 766 // New root rollover is provided synchronously. |
| 833 CertIssuerSourceStatic sync_certs; | 767 CertIssuerSourceStatic sync_certs; |
| 834 sync_certs.AddCert(newrootrollover_); | 768 sync_certs.AddCert(newrootrollover_); |
| 835 | 769 |
| 836 CertPathBuilder::Result result; | 770 CertPathBuilder::Result result; |
| 837 // Newroot is the target cert. | 771 // Newroot is the target cert. |
| 838 CertPathBuilder path_builder(newroot_, &trust_store, &signature_policy_, | 772 CertPathBuilder path_builder(newroot_, &trust_store, &signature_policy_, |
| 839 time_, &result); | 773 time_, &result); |
| 840 path_builder.AddCertIssuerSource(&sync_certs); | 774 path_builder.AddCertIssuerSource(&sync_certs); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 const auto& path1 = result.paths[1]->path; | 1157 const auto& path1 = result.paths[1]->path; |
| 1224 ASSERT_EQ(2U, path1.certs.size()); | 1158 ASSERT_EQ(2U, path1.certs.size()); |
| 1225 EXPECT_EQ(target_, path1.certs[0]); | 1159 EXPECT_EQ(target_, path1.certs[0]); |
| 1226 EXPECT_EQ(newintermediate_, path1.certs[1]); | 1160 EXPECT_EQ(newintermediate_, path1.certs[1]); |
| 1227 EXPECT_EQ(newroot_, path1.trust_anchor->cert()); | 1161 EXPECT_EQ(newroot_, path1.trust_anchor->cert()); |
| 1228 } | 1162 } |
| 1229 | 1163 |
| 1230 } // namespace | 1164 } // namespace |
| 1231 | 1165 |
| 1232 } // namespace net | 1166 } // namespace net |
| OLD | NEW |