| 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 "components/certificate_transparency/single_tree_tracker.h" | 5 #include "components/certificate_transparency/single_tree_tracker.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" |
| 10 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 11 #include "base/test/histogram_tester.h" | 14 #include "base/test/histogram_tester.h" |
| 15 #include "components/certificate_transparency/log_dns_client.h" |
| 16 #include "components/certificate_transparency/mock_log_dns_traffic.h" |
| 17 #include "crypto/sha2.h" |
| 18 #include "net/base/network_change_notifier.h" |
| 12 #include "net/cert/ct_log_verifier.h" | 19 #include "net/cert/ct_log_verifier.h" |
| 13 #include "net/cert/ct_serialization.h" | 20 #include "net/cert/ct_serialization.h" |
| 14 #include "net/cert/signed_certificate_timestamp.h" | 21 #include "net/cert/signed_certificate_timestamp.h" |
| 15 #include "net/cert/signed_tree_head.h" | 22 #include "net/cert/signed_tree_head.h" |
| 16 #include "net/cert/x509_certificate.h" | 23 #include "net/cert/x509_certificate.h" |
| 24 #include "net/dns/dns_client.h" |
| 25 #include "net/log/net_log.h" |
| 17 #include "net/test/ct_test_util.h" | 26 #include "net/test/ct_test_util.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 28 |
| 29 using net::ct::SignedCertificateTimestamp; |
| 30 using net::ct::SignedTreeHead; |
| 31 |
| 20 namespace certificate_transparency { | 32 namespace certificate_transparency { |
| 21 | 33 |
| 22 namespace { | 34 namespace { |
| 23 | 35 |
| 24 const char kCanCheckForInclusionHistogramName[] = | 36 const char kCanCheckForInclusionHistogramName[] = |
| 25 "Net.CertificateTransparency.CanInclusionCheckSCT"; | 37 "Net.CertificateTransparency.CanInclusionCheckSCT"; |
| 26 | 38 |
| 27 bool GetOldSignedTreeHead(net::ct::SignedTreeHead* sth) { | 39 bool GetOldSignedTreeHead(SignedTreeHead* sth) { |
| 28 sth->version = net::ct::SignedTreeHead::V1; | 40 sth->version = SignedTreeHead::V1; |
| 29 sth->timestamp = base::Time::UnixEpoch() + | 41 sth->timestamp = base::Time::UnixEpoch() + |
| 30 base::TimeDelta::FromMilliseconds(INT64_C(1348589665525)); | 42 base::TimeDelta::FromMilliseconds(INT64_C(1348589665525)); |
| 31 sth->tree_size = 12u; | 43 sth->tree_size = 12u; |
| 32 | 44 |
| 33 const uint8_t kOldSTHRootHash[] = { | 45 const uint8_t kOldSTHRootHash[] = { |
| 34 0x18, 0x04, 0x1b, 0xd4, 0x66, 0x50, 0x83, 0x00, 0x1f, 0xba, 0x8c, | 46 0x18, 0x04, 0x1b, 0xd4, 0x66, 0x50, 0x83, 0x00, 0x1f, 0xba, 0x8c, |
| 35 0x54, 0x11, 0xd2, 0xd7, 0x48, 0xe8, 0xab, 0xbf, 0xdc, 0xdf, 0xd9, | 47 0x54, 0x11, 0xd2, 0xd7, 0x48, 0xe8, 0xab, 0xbf, 0xdc, 0xdf, 0xd9, |
| 36 0x21, 0x8c, 0xb0, 0x2b, 0x68, 0xa7, 0x8e, 0x7d, 0x4c, 0x23}; | 48 0x21, 0x8c, 0xb0, 0x2b, 0x68, 0xa7, 0x8e, 0x7d, 0x4c, 0x23}; |
| 37 memcpy(sth->sha256_root_hash, kOldSTHRootHash, net::ct::kSthRootHashLength); | 49 memcpy(sth->sha256_root_hash, kOldSTHRootHash, net::ct::kSthRootHashLength); |
| 38 | 50 |
| 39 sth->log_id = net::ct::GetTestPublicKeyId(); | 51 sth->log_id = net::ct::GetTestPublicKeyId(); |
| 40 | 52 |
| 41 const uint8_t kOldSTHSignatureData[] = { | 53 const uint8_t kOldSTHSignatureData[] = { |
| 42 0x04, 0x03, 0x00, 0x47, 0x30, 0x45, 0x02, 0x20, 0x15, 0x7b, 0x23, | 54 0x04, 0x03, 0x00, 0x47, 0x30, 0x45, 0x02, 0x20, 0x15, 0x7b, 0x23, |
| 43 0x42, 0xa2, 0x5f, 0x88, 0xc9, 0x0b, 0x30, 0xa6, 0xb4, 0x49, 0x50, | 55 0x42, 0xa2, 0x5f, 0x88, 0xc9, 0x0b, 0x30, 0xa6, 0xb4, 0x49, 0x50, |
| 44 0xb3, 0xab, 0xf5, 0x25, 0xfe, 0x27, 0xf0, 0x3f, 0x9a, 0xbf, 0xc1, | 56 0xb3, 0xab, 0xf5, 0x25, 0xfe, 0x27, 0xf0, 0x3f, 0x9a, 0xbf, 0xc1, |
| 45 0x16, 0x5a, 0x7a, 0xc0, 0x62, 0x2b, 0xbb, 0x02, 0x21, 0x00, 0xe6, | 57 0x16, 0x5a, 0x7a, 0xc0, 0x62, 0x2b, 0xbb, 0x02, 0x21, 0x00, 0xe6, |
| 46 0x57, 0xa3, 0xfe, 0xfc, 0x5a, 0x82, 0x9b, 0x29, 0x46, 0x15, 0x1d, | 58 0x57, 0xa3, 0xfe, 0xfc, 0x5a, 0x82, 0x9b, 0x29, 0x46, 0x15, 0x1d, |
| 47 0xbc, 0xfd, 0x9e, 0x87, 0x7f, 0xd0, 0x00, 0x5d, 0x62, 0x4f, 0x9a, | 59 0xbc, 0xfd, 0x9e, 0x87, 0x7f, 0xd0, 0x00, 0x5d, 0x62, 0x4f, 0x9a, |
| 48 0x1a, 0x9f, 0x20, 0x79, 0xd0, 0xc1, 0x34, 0x2e, 0x08}; | 60 0x1a, 0x9f, 0x20, 0x79, 0xd0, 0xc1, 0x34, 0x2e, 0x08}; |
| 49 base::StringPiece sp(reinterpret_cast<const char*>(kOldSTHSignatureData), | 61 base::StringPiece sp(reinterpret_cast<const char*>(kOldSTHSignatureData), |
| 50 sizeof(kOldSTHSignatureData)); | 62 sizeof(kOldSTHSignatureData)); |
| 51 return DecodeDigitallySigned(&sp, &(sth->signature)) && sp.empty(); | 63 return DecodeDigitallySigned(&sp, &(sth->signature)) && sp.empty(); |
| 52 } | 64 } |
| 53 | 65 |
| 66 // TODO(eranm): Extract common method to net/test/ct_test_util.h |
| 67 std::vector<std::string> GetSampleAuditProof(size_t length) { |
| 68 std::vector<std::string> audit_proof(length); |
| 69 // Makes each node of the audit proof different, so that tests are able to |
| 70 // confirm that the audit proof is reconstructed in the correct order. |
| 71 for (size_t i = 0; i < length; ++i) { |
| 72 std::string node(crypto::kSHA256Length, '\0'); |
| 73 // Each node is 32 bytes, with each byte having a different value. |
| 74 for (size_t j = 0; j < crypto::kSHA256Length; ++j) { |
| 75 node[j] = static_cast<char>((-127 + i + j) % 128); |
| 76 } |
| 77 audit_proof[i].assign(std::move(node)); |
| 78 } |
| 79 |
| 80 return audit_proof; |
| 81 } |
| 82 |
| 54 } // namespace | 83 } // namespace |
| 55 | 84 |
| 56 class SingleTreeTrackerTest : public ::testing::Test { | 85 class SingleTreeTrackerTest : public ::testing::Test { |
| 57 void SetUp() override { | 86 void SetUp() override { |
| 58 log_ = | 87 log_ = |
| 59 net::CTLogVerifier::Create(net::ct::GetTestPublicKey(), "testlog", | 88 net::CTLogVerifier::Create(net::ct::GetTestPublicKey(), "testlog", |
| 60 "https://ct.example.com", "dns.example.com"); | 89 "https://ct.example.com", "dns.example.com"); |
| 61 | 90 |
| 62 ASSERT_TRUE(log_); | 91 ASSERT_TRUE(log_); |
| 63 ASSERT_EQ(log_->key_id(), net::ct::GetTestPublicKeyId()); | 92 ASSERT_EQ(log_->key_id(), net::ct::GetTestPublicKeyId()); |
| 64 | 93 |
| 65 tree_tracker_.reset(new SingleTreeTracker(log_)); | 94 net_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
| 95 |
| 96 std::unique_ptr<net::DnsClient> dns_client = |
| 97 net::DnsClient::CreateClient(net_log_.net_log()); |
| 98 |
| 99 log_dns_client_ = |
| 100 base::MakeUnique<LogDnsClient>(std::move(dns_client), net_log_); |
| 101 |
| 102 tree_tracker_.reset(new SingleTreeTracker(log_, log_dns_client_.get())); |
| 103 |
| 66 const std::string der_test_cert(net::ct::GetDerEncodedX509Cert()); | 104 const std::string der_test_cert(net::ct::GetDerEncodedX509Cert()); |
| 67 chain_ = net::X509Certificate::CreateFromBytes(der_test_cert.data(), | 105 chain_ = net::X509Certificate::CreateFromBytes(der_test_cert.data(), |
| 68 der_test_cert.length()); | 106 der_test_cert.length()); |
| 69 ASSERT_TRUE(chain_.get()); | 107 ASSERT_TRUE(chain_.get()); |
| 70 net::ct::GetX509CertSCT(&cert_sct_); | 108 net::ct::GetX509CertSCT(&cert_sct_); |
| 109 cert_sct_->origin = SignedCertificateTimestamp::SCT_FROM_OCSP_RESPONSE; |
| 71 } | 110 } |
| 72 | 111 |
| 73 protected: | 112 protected: |
| 113 base::MessageLoopForIO message_loop_; |
| 74 scoped_refptr<const net::CTLogVerifier> log_; | 114 scoped_refptr<const net::CTLogVerifier> log_; |
| 115 std::unique_ptr<net::NetworkChangeNotifier> net_change_notifier_; |
| 116 std::unique_ptr<LogDnsClient> log_dns_client_; |
| 75 std::unique_ptr<SingleTreeTracker> tree_tracker_; | 117 std::unique_ptr<SingleTreeTracker> tree_tracker_; |
| 76 scoped_refptr<net::X509Certificate> chain_; | 118 scoped_refptr<net::X509Certificate> chain_; |
| 77 scoped_refptr<net::ct::SignedCertificateTimestamp> cert_sct_; | 119 scoped_refptr<SignedCertificateTimestamp> cert_sct_; |
| 120 net::BoundNetLog net_log_; |
| 78 }; | 121 }; |
| 79 | 122 |
| 80 // Test that an SCT is classified as pending for a newer STH if the | 123 // Test that an SCT is classified as pending for a newer STH if the |
| 81 // SingleTreeTracker has not seen any STHs so far. | 124 // SingleTreeTracker has not seen any STHs so far. |
| 82 TEST_F(SingleTreeTrackerTest, CorrectlyClassifiesUnobservedSCTNoSTH) { | 125 TEST_F(SingleTreeTrackerTest, CorrectlyClassifiesUnobservedSCTNoSTH) { |
| 83 base::HistogramTester histograms; | 126 base::HistogramTester histograms; |
| 84 // First make sure the SCT has not been observed at all. | 127 // First make sure the SCT has not been observed at all. |
| 85 EXPECT_EQ( | 128 EXPECT_EQ( |
| 86 SingleTreeTracker::SCT_NOT_OBSERVED, | 129 SingleTreeTracker::SCT_NOT_OBSERVED, |
| 87 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); | 130 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 88 | 131 |
| 89 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); | 132 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); |
| 90 | 133 |
| 91 // Since no STH was provided to the tree_tracker_ the status should be that | 134 // Since no STH was provided to the tree_tracker_ the status should be that |
| 92 // the SCT is pending a newer STH. | 135 // the SCT is pending a newer STH. |
| 93 EXPECT_EQ( | 136 EXPECT_EQ( |
| 94 SingleTreeTracker::SCT_PENDING_NEWER_STH, | 137 SingleTreeTracker::SCT_PENDING_NEWER_STH, |
| 95 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); | 138 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 96 | 139 |
| 97 // Expect logging of a value indicating a valid STH is required. | 140 // Expect logging of a value indicating a valid STH is required. |
| 98 histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 1); | 141 histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 1); |
| 99 histograms.ExpectBucketCount(kCanCheckForInclusionHistogramName, 0, 1); | 142 histograms.ExpectBucketCount(kCanCheckForInclusionHistogramName, 0, 1); |
| 100 } | 143 } |
| 101 | 144 |
| 102 // Test that an SCT is classified as pending an inclusion check if the | 145 // Test that an SCT is classified as pending an inclusion check if the |
| 103 // SingleTreeTracker has a fresh-enough STH to check inclusion against. | 146 // SingleTreeTracker has a fresh-enough STH to check inclusion against. |
| 104 TEST_F(SingleTreeTrackerTest, CorrectlyClassifiesUnobservedSCTWithRecentSTH) { | 147 TEST_F(SingleTreeTrackerTest, CorrectlyClassifiesUnobservedSCTWithRecentSTH) { |
| 105 base::HistogramTester histograms; | 148 base::HistogramTester histograms; |
| 106 // Provide an STH to the tree_tracker_. | 149 // Provide an STH to the tree_tracker_. |
| 107 net::ct::SignedTreeHead sth; | 150 SignedTreeHead sth; |
| 108 net::ct::GetSampleSignedTreeHead(&sth); | 151 net::ct::GetSampleSignedTreeHead(&sth); |
| 109 tree_tracker_->NewSTHObserved(sth); | 152 tree_tracker_->NewSTHObserved(sth); |
| 110 | 153 |
| 111 // Make sure the SCT status is the same as if there's no STH for | 154 // Make sure the SCT status is the same as if there's no STH for |
| 112 // this log. | 155 // this log. |
| 113 EXPECT_EQ( | 156 EXPECT_EQ( |
| 114 SingleTreeTracker::SCT_NOT_OBSERVED, | 157 SingleTreeTracker::SCT_NOT_OBSERVED, |
| 115 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); | 158 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 116 | 159 |
| 117 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); | 160 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 136 base::HistogramTester histograms; | 179 base::HistogramTester histograms; |
| 137 // Report an observed SCT and make sure it's in the pending newer STH | 180 // Report an observed SCT and make sure it's in the pending newer STH |
| 138 // state. | 181 // state. |
| 139 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); | 182 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); |
| 140 EXPECT_EQ( | 183 EXPECT_EQ( |
| 141 SingleTreeTracker::SCT_PENDING_NEWER_STH, | 184 SingleTreeTracker::SCT_PENDING_NEWER_STH, |
| 142 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); | 185 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 143 histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 1); | 186 histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 1); |
| 144 | 187 |
| 145 // Provide with a fresh STH | 188 // Provide with a fresh STH |
| 146 net::ct::SignedTreeHead sth; | 189 SignedTreeHead sth; |
| 147 net::ct::GetSampleSignedTreeHead(&sth); | 190 net::ct::GetSampleSignedTreeHead(&sth); |
| 148 tree_tracker_->NewSTHObserved(sth); | 191 tree_tracker_->NewSTHObserved(sth); |
| 149 | 192 |
| 150 // Test that its status has changed. | 193 // Test that its status has changed. |
| 151 EXPECT_EQ( | 194 EXPECT_EQ( |
| 152 SingleTreeTracker::SCT_PENDING_INCLUSION_CHECK, | 195 SingleTreeTracker::SCT_PENDING_INCLUSION_CHECK, |
| 153 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); | 196 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 154 // Check that no additional UMA was logged for this case as the histogram is | 197 // Check that no additional UMA was logged for this case as the histogram is |
| 155 // only supposed to measure the state of newly-observed SCTs, not pending | 198 // only supposed to measure the state of newly-observed SCTs, not pending |
| 156 // ones. | 199 // ones. |
| 157 histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 1); | 200 histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 1); |
| 158 } | 201 } |
| 159 | 202 |
| 160 // Test that the SingleTreeTracker does not change an SCT's status if an STH | 203 // Test that the SingleTreeTracker does not change an SCT's status if an STH |
| 161 // from the log it was issued by is observed, but that STH is too old to check | 204 // from the log it was issued by is observed, but that STH is too old to check |
| 162 // inclusion against. | 205 // inclusion against. |
| 163 TEST_F(SingleTreeTrackerTest, DoesNotUpdatesSCTStatusOnOldSTH) { | 206 TEST_F(SingleTreeTrackerTest, DoesNotUpdatesSCTStatusOnOldSTH) { |
| 164 // Notify of an SCT and make sure it's in the 'pending newer STH' state. | 207 // Notify of an SCT and make sure it's in the 'pending newer STH' state. |
| 165 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); | 208 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); |
| 166 EXPECT_EQ( | 209 EXPECT_EQ( |
| 167 SingleTreeTracker::SCT_PENDING_NEWER_STH, | 210 SingleTreeTracker::SCT_PENDING_NEWER_STH, |
| 168 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); | 211 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 169 | 212 |
| 170 // Provide an old STH for the same log. | 213 // Provide an old STH for the same log. |
| 171 net::ct::SignedTreeHead sth; | 214 SignedTreeHead sth; |
| 172 GetOldSignedTreeHead(&sth); | 215 GetOldSignedTreeHead(&sth); |
| 173 tree_tracker_->NewSTHObserved(sth); | 216 tree_tracker_->NewSTHObserved(sth); |
| 174 | 217 |
| 175 // Make sure the SCT's state hasn't changed. | 218 // Make sure the SCT's state hasn't changed. |
| 176 EXPECT_EQ( | 219 EXPECT_EQ( |
| 177 SingleTreeTracker::SCT_PENDING_NEWER_STH, | 220 SingleTreeTracker::SCT_PENDING_NEWER_STH, |
| 178 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); | 221 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 179 } | 222 } |
| 180 | 223 |
| 181 // Test that the SingleTreeTracker correctly logs that an SCT is pending a new | 224 // Test that the SingleTreeTracker correctly logs that an SCT is pending a new |
| 182 // STH, when it has a valid STH, but the observed SCT is not covered by the | 225 // STH, when it has a valid STH, but the observed SCT is not covered by the |
| 183 // STH. | 226 // STH. |
| 184 TEST_F(SingleTreeTrackerTest, LogsUMAForNewSCTAndOldSTH) { | 227 TEST_F(SingleTreeTrackerTest, LogsUMAForNewSCTAndOldSTH) { |
| 185 base::HistogramTester histograms; | 228 base::HistogramTester histograms; |
| 186 // Provide an old STH for the same log. | 229 // Provide an old STH for the same log. |
| 187 net::ct::SignedTreeHead sth; | 230 SignedTreeHead sth; |
| 188 GetOldSignedTreeHead(&sth); | 231 GetOldSignedTreeHead(&sth); |
| 189 tree_tracker_->NewSTHObserved(sth); | 232 tree_tracker_->NewSTHObserved(sth); |
| 190 | 233 |
| 191 histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 0); | 234 histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 0); |
| 192 | 235 |
| 193 // Notify of an SCT and make sure it's in the 'pending newer STH' state. | 236 // Notify of an SCT and make sure it's in the 'pending newer STH' state. |
| 194 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); | 237 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); |
| 195 | 238 |
| 196 // Exactly one value should be logged, indicating the SCT cannot be checked | 239 // Exactly one value should be logged, indicating the SCT cannot be checked |
| 197 // for inclusion as the STH is too old. | 240 // for inclusion as the STH is too old. |
| 198 histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 1); | 241 histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 1); |
| 199 histograms.ExpectBucketCount(kCanCheckForInclusionHistogramName, 1, 1); | 242 histograms.ExpectBucketCount(kCanCheckForInclusionHistogramName, 1, 1); |
| 200 } | 243 } |
| 201 | 244 |
| 245 // Test that an entry transitions to the "not found" state if the LogDnsClient |
| 246 // fails to get a leaf index. |
| 247 TEST_F(SingleTreeTrackerTest, TestEntryNotPendingAfterLeafIndexFetchFailure) { |
| 248 MockLogDnsTraffic mock_dns; |
| 249 mock_dns.InitializeDnsConfig(); |
| 250 mock_dns.ExpectRequestAndSocketError( |
| 251 "ASTEWZDDDMBHBVWSAQLIZUSNBMSLMIQMDZNH56TBNXWRMW5XALTA.hash.dns.example." |
| 252 "com", |
| 253 net::Error::ERR_FAILED); |
| 254 |
| 255 log_dns_client_ = |
| 256 base::MakeUnique<LogDnsClient>(mock_dns.CreateDnsClient(), net_log_); |
| 257 tree_tracker_.reset(new SingleTreeTracker(log_, log_dns_client_.get())); |
| 258 |
| 259 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); |
| 260 EXPECT_EQ( |
| 261 SingleTreeTracker::SCT_PENDING_NEWER_STH, |
| 262 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 263 |
| 264 // Provide with a fresh STH |
| 265 SignedTreeHead sth; |
| 266 net::ct::GetSampleSignedTreeHead(&sth); |
| 267 tree_tracker_->NewSTHObserved(sth); |
| 268 base::RunLoop().RunUntilIdle(); |
| 269 |
| 270 EXPECT_EQ( |
| 271 SingleTreeTracker::SCT_NOT_OBSERVED, |
| 272 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 273 } |
| 274 |
| 275 // Test that an entry transitions to the "not found" state if the LogDnsClient |
| 276 // succeeds to get a leaf index but fails to get an inclusion proof. |
| 277 TEST_F(SingleTreeTrackerTest, TestEntryNotPendingAfterInclusionCheckFailure) { |
| 278 MockLogDnsTraffic mock_dns; |
| 279 mock_dns.InitializeDnsConfig(); |
| 280 mock_dns.ExpectLeafIndexRequestAndResponse( |
| 281 "ASTEWZDDDMBHBVWSAQLIZUSNBMSLMIQMDZNH56TBNXWRMW5XALTA.hash.dns.example." |
| 282 "com", |
| 283 "12"); |
| 284 mock_dns.ExpectRequestAndSocketError("0.12.21.tree.dns.example.com", |
| 285 net::Error::ERR_FAILED); |
| 286 |
| 287 log_dns_client_ = |
| 288 base::MakeUnique<LogDnsClient>(mock_dns.CreateDnsClient(), net_log_); |
| 289 tree_tracker_.reset(new SingleTreeTracker(log_, log_dns_client_.get())); |
| 290 |
| 291 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); |
| 292 EXPECT_EQ( |
| 293 SingleTreeTracker::SCT_PENDING_NEWER_STH, |
| 294 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 295 |
| 296 // Provide with a fresh STH |
| 297 SignedTreeHead sth; |
| 298 net::ct::GetSampleSignedTreeHead(&sth); |
| 299 tree_tracker_->NewSTHObserved(sth); |
| 300 base::RunLoop().RunUntilIdle(); |
| 301 |
| 302 EXPECT_EQ( |
| 303 SingleTreeTracker::SCT_NOT_OBSERVED, |
| 304 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 305 } |
| 306 |
| 307 // Test that an entry transitions to the "included" state if the LogDnsClient |
| 308 // succeeds to get a leaf index and an inclusion proof. |
| 309 TEST_F(SingleTreeTrackerTest, TestEntryIncludedAfterInclusionCheckSuccess) { |
| 310 const std::vector<std::string> audit_proof = GetSampleAuditProof(3); |
| 311 |
| 312 MockLogDnsTraffic mock_dns; |
| 313 mock_dns.InitializeDnsConfig(); |
| 314 mock_dns.ExpectLeafIndexRequestAndResponse( |
| 315 "ASTEWZDDDMBHBVWSAQLIZUSNBMSLMIQMDZNH56TBNXWRMW5XALTA.hash.dns.example." |
| 316 "com", |
| 317 "12"); |
| 318 mock_dns.ExpectAuditProofRequestAndResponse("0.12.21.tree.dns.example.com", |
| 319 audit_proof.begin(), |
| 320 audit_proof.begin() + 2); |
| 321 |
| 322 log_dns_client_ = |
| 323 base::MakeUnique<LogDnsClient>(mock_dns.CreateDnsClient(), net_log_); |
| 324 tree_tracker_.reset(new SingleTreeTracker(log_, log_dns_client_.get())); |
| 325 |
| 326 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get()); |
| 327 EXPECT_EQ( |
| 328 SingleTreeTracker::SCT_PENDING_NEWER_STH, |
| 329 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 330 |
| 331 // Provide with a fresh STH |
| 332 SignedTreeHead sth; |
| 333 net::ct::GetSampleSignedTreeHead(&sth); |
| 334 tree_tracker_->NewSTHObserved(sth); |
| 335 base::RunLoop().RunUntilIdle(); |
| 336 |
| 337 EXPECT_EQ( |
| 338 SingleTreeTracker::SCT_INCLUDED_IN_LOG, |
| 339 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get())); |
| 340 } |
| 341 |
| 342 // Test that pending entries transition states correctly according to the |
| 343 // STHs provided: |
| 344 // * Start without an STH. |
| 345 // * Add a collection of entries with mixed timestamps (i.e. SCTs not added |
| 346 // in the order of their timestamps). |
| 347 // * Provide an STH that covers some of the entries, test these are audited. |
| 348 // * Provide another STH that covers more of the entries, test that the entries |
| 349 // already audited are not audited again and that those that need to be |
| 350 // audited are audited, while those that are not covered by that STH are |
| 351 // not audited. |
| 352 |
| 353 // Test that if a request for an entry is throttled, it remains in a |
| 354 // pending state. |
| 355 |
| 356 // Test that if one entry is throttled and the next one audited, the first, |
| 357 // throttled, entry is also audited as a follow-up. |
| 358 |
| 202 } // namespace certificate_transparency | 359 } // namespace certificate_transparency |
| OLD | NEW |