| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/multi_log_ct_verifier.h" | 5 #include "net/cert/multi_log_ct_verifier.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 return false; | 78 return false; |
| 79 | 79 |
| 80 const TestNetLogEntry& received = entries[0]; | 80 const TestNetLogEntry& received = entries[0]; |
| 81 std::string embedded_scts; | 81 std::string embedded_scts; |
| 82 if (!received.GetStringValue("embedded_scts", &embedded_scts)) | 82 if (!received.GetStringValue("embedded_scts", &embedded_scts)) |
| 83 return false; | 83 return false; |
| 84 if (embedded_scts.empty()) | 84 if (embedded_scts.empty()) |
| 85 return false; | 85 return false; |
| 86 | 86 |
| 87 const TestNetLogEntry& parsed = entries[1]; | 87 const TestNetLogEntry& parsed = entries[1]; |
| 88 base::ListValue* verified_scts; | 88 base::ListValue* scts; |
| 89 if (!parsed.GetListValue("verified_scts", &verified_scts) || | 89 if (!parsed.GetListValue("scts", &scts) || scts->GetSize() != 1) { |
| 90 verified_scts->GetSize() != 1) { | |
| 91 return false; | 90 return false; |
| 92 } | 91 } |
| 93 | 92 |
| 94 base::DictionaryValue* the_sct; | 93 base::DictionaryValue* the_sct; |
| 95 if (!verified_scts->GetDictionary(0, &the_sct)) | 94 if (!scts->GetDictionary(0, &the_sct)) |
| 96 return false; | 95 return false; |
| 97 | 96 |
| 98 std::string origin; | 97 std::string origin; |
| 99 if (!the_sct->GetString("origin", &origin)) | 98 if (!the_sct->GetString("origin", &origin)) |
| 100 return false; | 99 return false; |
| 101 if (origin != "Embedded in certificate") | 100 if (origin != "Embedded in certificate") |
| 102 return false; | 101 return false; |
| 103 | 102 |
| 104 base::ListValue* other_scts; | 103 std::string verification_status; |
| 105 if (!parsed.GetListValue("invalid_scts", &other_scts) || | 104 if (!the_sct->GetString("verification_status", &verification_status)) |
| 106 !other_scts->empty()) { | |
| 107 return false; | 105 return false; |
| 108 } | 106 if (verification_status != "Verified") |
| 109 | |
| 110 if (!parsed.GetListValue("unknown_logs_scts", &other_scts) || | |
| 111 !other_scts->empty()) { | |
| 112 return false; | 107 return false; |
| 113 } | |
| 114 | 108 |
| 115 return true; | 109 return true; |
| 116 } | 110 } |
| 117 | 111 |
| 118 bool VerifySinglePrecertificateChain(scoped_refptr<X509Certificate> chain, | 112 bool VerifySinglePrecertificateChain(scoped_refptr<X509Certificate> chain, |
| 119 const BoundNetLog& bound_net_log, | 113 const BoundNetLog& bound_net_log, |
| 120 ct::CTVerifyResult* result) { | 114 ct::CTVerifyResult* result) { |
| 121 return verifier_->Verify(chain.get(), | 115 return verifier_->Verify(chain.get(), |
| 122 std::string(), | 116 std::string(), |
| 123 std::string(), | 117 std::string(), |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 result, ct::SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION)); | 223 result, ct::SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION)); |
| 230 } | 224 } |
| 231 | 225 |
| 232 TEST_F(MultiLogCTVerifierTest, IdentifiesSCTFromUnknownLog) { | 226 TEST_F(MultiLogCTVerifierTest, IdentifiesSCTFromUnknownLog) { |
| 233 std::string sct_list = ct::GetSCTListWithInvalidSCT(); | 227 std::string sct_list = ct::GetSCTListWithInvalidSCT(); |
| 234 ct::CTVerifyResult result; | 228 ct::CTVerifyResult result; |
| 235 | 229 |
| 236 EXPECT_NE(OK, | 230 EXPECT_NE(OK, |
| 237 verifier_->Verify( | 231 verifier_->Verify( |
| 238 chain_.get(), std::string(), sct_list, &result, BoundNetLog())); | 232 chain_.get(), std::string(), sct_list, &result, BoundNetLog())); |
| 239 EXPECT_EQ(1U, result.unknown_logs_scts.size()); | 233 EXPECT_EQ(1U, result.scts.size()); |
| 240 EXPECT_EQ("", result.unknown_logs_scts[0]->log_description); | 234 EXPECT_EQ("", result.scts[0].sct->log_description); |
| 235 EXPECT_EQ(ct::SCT_STATUS_LOG_UNKNOWN, result.scts[0].status); |
| 241 } | 236 } |
| 242 | 237 |
| 243 TEST_F(MultiLogCTVerifierTest, CountsValidSCTsInStatusHistogram) { | 238 TEST_F(MultiLogCTVerifierTest, CountsValidSCTsInStatusHistogram) { |
| 244 int num_valid_scts = NumValidSCTsInStatusHistogram(); | 239 int num_valid_scts = NumValidSCTsInStatusHistogram(); |
| 245 | 240 |
| 246 ASSERT_TRUE(VerifySinglePrecertificateChain(embedded_sct_chain_)); | 241 ASSERT_TRUE(VerifySinglePrecertificateChain(embedded_sct_chain_)); |
| 247 | 242 |
| 248 EXPECT_EQ(num_valid_scts + 1, NumValidSCTsInStatusHistogram()); | 243 EXPECT_EQ(num_valid_scts + 1, NumValidSCTsInStatusHistogram()); |
| 249 } | 244 } |
| 250 | 245 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 Mock::VerifyAndClearExpectations(&observer); | 296 Mock::VerifyAndClearExpectations(&observer); |
| 302 | 297 |
| 303 EXPECT_CALL(observer, OnSCTVerified(embedded_sct_chain_.get(), _)).Times(0); | 298 EXPECT_CALL(observer, OnSCTVerified(embedded_sct_chain_.get(), _)).Times(0); |
| 304 verifier_->SetObserver(nullptr); | 299 verifier_->SetObserver(nullptr); |
| 305 ASSERT_TRUE(VerifySinglePrecertificateChain(embedded_sct_chain_)); | 300 ASSERT_TRUE(VerifySinglePrecertificateChain(embedded_sct_chain_)); |
| 306 } | 301 } |
| 307 | 302 |
| 308 } // namespace | 303 } // namespace |
| 309 | 304 |
| 310 } // namespace net | 305 } // namespace net |
| OLD | NEW |