Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: components/certificate_transparency/single_tree_tracker_unittest.cc

Issue 1845113003: Certificate Transparency: Start tracking logs' state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments, test improvement Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/certificate_transparency/single_tree_tracker.h"
6
7 #include <string>
8 #include <utility>
9
10 #include "base/strings/string_piece.h"
11 #include "net/cert/ct_log_verifier.h"
12 #include "net/cert/ct_serialization.h"
13 #include "net/cert/signed_certificate_timestamp.h"
14 #include "net/cert/signed_tree_head.h"
15 #include "net/cert/x509_certificate.h"
16 #include "net/test/ct_test_util.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace certificate_transparency {
20
21 namespace {
22
23 bool GetOldSignedTreeHead(net::ct::SignedTreeHead* sth) {
24 sth->version = net::ct::SignedTreeHead::V1;
25 sth->timestamp = base::Time::UnixEpoch() +
26 base::TimeDelta::FromMilliseconds(INT64_C(1348589665525));
27 sth->tree_size = 12u;
28
29 const uint8_t kOldSTHRootHash[] = {
30 0x18, 0x04, 0x1b, 0xd4, 0x66, 0x50, 0x83, 0x00, 0x1f, 0xba, 0x8c,
31 0x54, 0x11, 0xd2, 0xd7, 0x48, 0xe8, 0xab, 0xbf, 0xdc, 0xdf, 0xd9,
32 0x21, 0x8c, 0xb0, 0x2b, 0x68, 0xa7, 0x8e, 0x7d, 0x4c, 0x23};
33 memcpy(sth->sha256_root_hash, kOldSTHRootHash, net::ct::kSthRootHashLength);
34
35 sth->log_id = net::ct::GetTestPublicKeyId();
36
37 const uint8_t kOldSTHSignatureData[] = {
38 0x04, 0x03, 0x00, 0x47, 0x30, 0x45, 0x02, 0x20, 0x15, 0x7b, 0x23,
39 0x42, 0xa2, 0x5f, 0x88, 0xc9, 0x0b, 0x30, 0xa6, 0xb4, 0x49, 0x50,
40 0xb3, 0xab, 0xf5, 0x25, 0xfe, 0x27, 0xf0, 0x3f, 0x9a, 0xbf, 0xc1,
41 0x16, 0x5a, 0x7a, 0xc0, 0x62, 0x2b, 0xbb, 0x02, 0x21, 0x00, 0xe6,
42 0x57, 0xa3, 0xfe, 0xfc, 0x5a, 0x82, 0x9b, 0x29, 0x46, 0x15, 0x1d,
43 0xbc, 0xfd, 0x9e, 0x87, 0x7f, 0xd0, 0x00, 0x5d, 0x62, 0x4f, 0x9a,
44 0x1a, 0x9f, 0x20, 0x79, 0xd0, 0xc1, 0x34, 0x2e, 0x08};
45 base::StringPiece sp(reinterpret_cast<const char*>(kOldSTHSignatureData),
46 sizeof(kOldSTHSignatureData));
47 return DecodeDigitallySigned(&sp, &(sth->signature)) && sp.empty();
48 }
49
50 } // namespace
51
52 class SingleTreeTrackerTest : public ::testing::Test {
53 void SetUp() override {
54 log_ = net::CTLogVerifier::Create(net::ct::GetTestPublicKey(), "testlog",
55 "https://ct.example.com");
56
57 ASSERT_TRUE(log_);
58 ASSERT_EQ(log_->key_id(), net::ct::GetTestPublicKeyId());
59
60 tree_tracker_.reset(new SingleTreeTracker(log_));
61 const std::string der_test_cert(net::ct::GetDerEncodedX509Cert());
62 chain_ = net::X509Certificate::CreateFromBytes(der_test_cert.data(),
63 der_test_cert.length());
64 ASSERT_TRUE(chain_.get());
65 net::ct::GetX509CertSCT(&cert_sct_);
66 }
67
68 protected:
69 scoped_refptr<const net::CTLogVerifier> log_;
70 std::unique_ptr<SingleTreeTracker> tree_tracker_;
71 scoped_refptr<net::X509Certificate> chain_;
72 scoped_refptr<net::ct::SignedCertificateTimestamp> cert_sct_;
73 };
74
75 TEST_F(SingleTreeTrackerTest, TestCorrectlyClassifiesUnobservedSCTNoSTH) {
Ryan Sleevi 2016/05/18 16:58:19 Same remarks as the previous CL regarding being cl
Eran Messeri 2016/05/19 12:35:00 Done, added documentation to all test cases. (as a
Ryan Sleevi 2016/05/19 17:20:56 I think I'd disagree pretty heavily with that phil
76 EXPECT_EQ(
77 SingleTreeTracker::SCT_NOT_OBSERVED,
78 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
79 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get());
Ryan Sleevi 2016/05/18 16:58:19 Newline here between 78 & 79 - That is, it seems
Eran Messeri 2016/05/19 12:35:00 Done (added comments too).
80
81 EXPECT_EQ(
82 SingleTreeTracker::SCT_PENDING_NEWER_STH,
83 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
84 }
85
86 TEST_F(SingleTreeTrackerTest,
87 TestCorrectlyClassifiesUnobservedSCTWithRecentSTH) {
88 net::ct::SignedTreeHead sth;
89 net::ct::GetSampleSignedTreeHead(&sth);
90 tree_tracker_->NewSTHObserved(sth);
91
92 EXPECT_EQ(
93 SingleTreeTracker::SCT_NOT_OBSERVED,
94 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
95
96 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get());
97
98 EXPECT_EQ(
99 SingleTreeTracker::SCT_PENDING_INCLUSION_CHECK,
100 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
101 }
102
103 TEST_F(SingleTreeTrackerTest, TestCorrectlyUpdatesSCTStatusOnNewSTH) {
Ryan Sleevi 2016/05/18 16:58:19 the "Test" in all of these tests is redundant Sin
Eran Messeri 2016/05/19 12:35:00 Done.
104 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get());
105 EXPECT_EQ(
106 SingleTreeTracker::SCT_PENDING_NEWER_STH,
107 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
108
109 net::ct::SignedTreeHead sth;
110 net::ct::GetSampleSignedTreeHead(&sth);
111 tree_tracker_->NewSTHObserved(sth);
112 EXPECT_EQ(
113 SingleTreeTracker::SCT_PENDING_INCLUSION_CHECK,
114 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
115 }
116
117 TEST_F(SingleTreeTrackerTest, TestDoesNotUpdatesSCTStatusOnOldSTH) {
118 tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get());
119 EXPECT_EQ(
120 SingleTreeTracker::SCT_PENDING_NEWER_STH,
121 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
122
123 net::ct::SignedTreeHead sth;
124 GetOldSignedTreeHead(&sth);
125 tree_tracker_->NewSTHObserved(sth);
126 EXPECT_EQ(
127 SingleTreeTracker::SCT_PENDING_NEWER_STH,
128 tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
129 }
130
131 } // namespace certificate_transparency
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698