| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 114 } |
| 115 | 115 |
| 116 ::testing::AssertionResult ReadTestCert( | 116 ::testing::AssertionResult ReadTestCert( |
| 117 const std::string& file_name, | 117 const std::string& file_name, |
| 118 scoped_refptr<ParsedCertificate>* result) { | 118 scoped_refptr<ParsedCertificate>* result) { |
| 119 std::string der; | 119 std::string der; |
| 120 ::testing::AssertionResult r = ReadTestPem( | 120 ::testing::AssertionResult r = ReadTestPem( |
| 121 "net/data/ssl/certificates/" + file_name, "CERTIFICATE", &der); | 121 "net/data/ssl/certificates/" + file_name, "CERTIFICATE", &der); |
| 122 if (!r) | 122 if (!r) |
| 123 return r; | 123 return r; |
| 124 *result = ParsedCertificate::CreateFromCertificateCopy(der, {}); | 124 CertErrors errors; |
| 125 if (!*result) | 125 *result = ParsedCertificate::Create(der, {}, &errors); |
| 126 return ::testing::AssertionFailure() << "CreateFromCertificateCopy failed"; | 126 if (!*result) { |
| 127 return ::testing::AssertionFailure() |
| 128 << "ParseCertificate::Create() failed:\n" |
| 129 << errors.ToDebugString(); |
| 130 } |
| 127 return ::testing::AssertionSuccess(); | 131 return ::testing::AssertionSuccess(); |
| 128 } | 132 } |
| 129 | 133 |
| 130 // Run the path builder, and wait for async completion if necessary. The return | 134 // Run the path builder, and wait for async completion if necessary. The return |
| 131 // value signifies whether the path builder completed synchronously or | 135 // value signifies whether the path builder completed synchronously or |
| 132 // asynchronously, not that RunPathBuilder itself is asynchronous. | 136 // asynchronously, not that RunPathBuilder itself is asynchronous. |
| 133 CompletionStatus RunPathBuilder(CertPathBuilder* path_builder) { | 137 CompletionStatus RunPathBuilder(CertPathBuilder* path_builder) { |
| 134 TestClosure callback; | 138 TestClosure callback; |
| 135 CompletionStatus rv = path_builder->Run(callback.closure()); | 139 CompletionStatus rv = path_builder->Run(callback.closure()); |
| 136 | 140 |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 ASSERT_EQ(1U, best_result->path.certs.size()); | 938 ASSERT_EQ(1U, best_result->path.certs.size()); |
| 935 EXPECT_EQ(newroot_, best_result->path.certs[0]); | 939 EXPECT_EQ(newroot_, best_result->path.certs[0]); |
| 936 EXPECT_EQ(newrootrollover_, best_result->path.trust_anchor->cert()); | 940 EXPECT_EQ(newrootrollover_, best_result->path.trust_anchor->cert()); |
| 937 } | 941 } |
| 938 | 942 |
| 939 // Test that PathBuilder will not try the same path twice if multiple | 943 // Test that PathBuilder will not try the same path twice if multiple |
| 940 // CertIssuerSources provide the same certificate. | 944 // CertIssuerSources provide the same certificate. |
| 941 TEST_F(PathBuilderKeyRolloverTest, TestDuplicateIntermediates) { | 945 TEST_F(PathBuilderKeyRolloverTest, TestDuplicateIntermediates) { |
| 942 // Create a separate copy of oldintermediate. | 946 // Create a separate copy of oldintermediate. |
| 943 scoped_refptr<ParsedCertificate> oldintermediate_dupe( | 947 scoped_refptr<ParsedCertificate> oldintermediate_dupe( |
| 944 ParsedCertificate::CreateFromCertificateCopy( | 948 ParsedCertificate::Create(oldintermediate_->der_cert().AsStringPiece(), |
| 945 oldintermediate_->der_cert().AsStringPiece(), {})); | 949 {}, nullptr)); |
| 946 | 950 |
| 947 // Only newroot is a trusted root. | 951 // Only newroot is a trusted root. |
| 948 TrustStoreInMemory trust_store; | 952 TrustStoreInMemory trust_store; |
| 949 AddTrustedCertificate(newroot_, &trust_store); | 953 AddTrustedCertificate(newroot_, &trust_store); |
| 950 | 954 |
| 951 // The oldintermediate is supplied synchronously by |sync_certs1| and | 955 // The oldintermediate is supplied synchronously by |sync_certs1| and |
| 952 // another copy of oldintermediate is supplied synchronously by |sync_certs2|. | 956 // another copy of oldintermediate is supplied synchronously by |sync_certs2|. |
| 953 // The path target <- oldintermediate <- newroot should be built first, | 957 // The path target <- oldintermediate <- newroot should be built first, |
| 954 // though it won't verify. It should not be attempted again even though | 958 // though it won't verify. It should not be attempted again even though |
| 955 // oldintermediate was supplied twice. | 959 // oldintermediate was supplied twice. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 ASSERT_EQ(2U, path1.certs.size()); | 999 ASSERT_EQ(2U, path1.certs.size()); |
| 996 EXPECT_EQ(target_, path1.certs[0]); | 1000 EXPECT_EQ(target_, path1.certs[0]); |
| 997 EXPECT_EQ(newintermediate_, path1.certs[1]); | 1001 EXPECT_EQ(newintermediate_, path1.certs[1]); |
| 998 EXPECT_EQ(newroot_, path1.trust_anchor->cert()); | 1002 EXPECT_EQ(newroot_, path1.trust_anchor->cert()); |
| 999 } | 1003 } |
| 1000 | 1004 |
| 1001 // Test when PathBuilder is given a cert CertIssuerSources that has the same | 1005 // Test when PathBuilder is given a cert CertIssuerSources that has the same |
| 1002 // SPKI as a TrustAnchor. | 1006 // SPKI as a TrustAnchor. |
| 1003 TEST_F(PathBuilderKeyRolloverTest, TestDuplicateIntermediateAndRoot) { | 1007 TEST_F(PathBuilderKeyRolloverTest, TestDuplicateIntermediateAndRoot) { |
| 1004 // Create a separate copy of newroot. | 1008 // Create a separate copy of newroot. |
| 1005 scoped_refptr<ParsedCertificate> newroot_dupe( | 1009 scoped_refptr<ParsedCertificate> newroot_dupe(ParsedCertificate::Create( |
| 1006 ParsedCertificate::CreateFromCertificateCopy( | 1010 newroot_->der_cert().AsStringPiece(), {}, nullptr)); |
| 1007 newroot_->der_cert().AsStringPiece(), {})); | |
| 1008 | 1011 |
| 1009 // Only newroot is a trusted root. | 1012 // Only newroot is a trusted root. |
| 1010 TrustStoreInMemory trust_store; | 1013 TrustStoreInMemory trust_store; |
| 1011 AddTrustedCertificate(newroot_, &trust_store); | 1014 AddTrustedCertificate(newroot_, &trust_store); |
| 1012 | 1015 |
| 1013 // The oldintermediate and newroot are supplied synchronously by |sync_certs|. | 1016 // The oldintermediate and newroot are supplied synchronously by |sync_certs|. |
| 1014 CertIssuerSourceStatic sync_certs; | 1017 CertIssuerSourceStatic sync_certs; |
| 1015 sync_certs.AddCert(oldintermediate_); | 1018 sync_certs.AddCert(oldintermediate_); |
| 1016 sync_certs.AddCert(newroot_dupe); | 1019 sync_certs.AddCert(newroot_dupe); |
| 1017 | 1020 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 SyncGetIssuersOf(oldintermediate_.get(), _)); | 1229 SyncGetIssuersOf(oldintermediate_.get(), _)); |
| 1227 EXPECT_CALL(cert_issuer_source, | 1230 EXPECT_CALL(cert_issuer_source, |
| 1228 AsyncGetIssuersOf(oldintermediate_.get(), _, _)); | 1231 AsyncGetIssuersOf(oldintermediate_.get(), _, _)); |
| 1229 } | 1232 } |
| 1230 target_issuers_callback.Run(target_issuers_req); | 1233 target_issuers_callback.Run(target_issuers_req); |
| 1231 ::testing::Mock::VerifyAndClearExpectations(target_issuers_req); | 1234 ::testing::Mock::VerifyAndClearExpectations(target_issuers_req); |
| 1232 ::testing::Mock::VerifyAndClearExpectations(&cert_issuer_source); | 1235 ::testing::Mock::VerifyAndClearExpectations(&cert_issuer_source); |
| 1233 | 1236 |
| 1234 // Second async batch: return a different copy of oldintermediate_ again. | 1237 // Second async batch: return a different copy of oldintermediate_ again. |
| 1235 scoped_refptr<ParsedCertificate> oldintermediate_dupe( | 1238 scoped_refptr<ParsedCertificate> oldintermediate_dupe( |
| 1236 ParsedCertificate::CreateFromCertificateCopy( | 1239 ParsedCertificate::Create(oldintermediate_->der_cert().AsStringPiece(), |
| 1237 oldintermediate_->der_cert().AsStringPiece(), {})); | 1240 {}, nullptr)); |
| 1238 EXPECT_CALL(*target_issuers_req, GetNext(_)) | 1241 EXPECT_CALL(*target_issuers_req, GetNext(_)) |
| 1239 .WillOnce(DoAll(SetArgPointee<0>(oldintermediate_dupe), | 1242 .WillOnce(DoAll(SetArgPointee<0>(oldintermediate_dupe), |
| 1240 Return(CompletionStatus::SYNC))) | 1243 Return(CompletionStatus::SYNC))) |
| 1241 .WillOnce( | 1244 .WillOnce( |
| 1242 DoAll(SetArgPointee<0>(nullptr), Return(CompletionStatus::ASYNC))); | 1245 DoAll(SetArgPointee<0>(nullptr), Return(CompletionStatus::ASYNC))); |
| 1243 target_issuers_callback.Run(target_issuers_req); | 1246 target_issuers_callback.Run(target_issuers_req); |
| 1244 // oldintermediate was already processed above, it should not generate any | 1247 // oldintermediate was already processed above, it should not generate any |
| 1245 // more requests. | 1248 // more requests. |
| 1246 ::testing::Mock::VerifyAndClearExpectations(target_issuers_req); | 1249 ::testing::Mock::VerifyAndClearExpectations(target_issuers_req); |
| 1247 ::testing::Mock::VerifyAndClearExpectations(&cert_issuer_source); | 1250 ::testing::Mock::VerifyAndClearExpectations(&cert_issuer_source); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 const auto& path1 = result.paths[1]->path; | 1287 const auto& path1 = result.paths[1]->path; |
| 1285 ASSERT_EQ(2U, path1.certs.size()); | 1288 ASSERT_EQ(2U, path1.certs.size()); |
| 1286 EXPECT_EQ(target_, path1.certs[0]); | 1289 EXPECT_EQ(target_, path1.certs[0]); |
| 1287 EXPECT_EQ(newintermediate_, path1.certs[1]); | 1290 EXPECT_EQ(newintermediate_, path1.certs[1]); |
| 1288 EXPECT_EQ(newroot_, path1.trust_anchor->cert()); | 1291 EXPECT_EQ(newroot_, path1.trust_anchor->cert()); |
| 1289 } | 1292 } |
| 1290 | 1293 |
| 1291 } // namespace | 1294 } // namespace |
| 1292 | 1295 |
| 1293 } // namespace net | 1296 } // namespace net |
| OLD | NEW |