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

Side by Side Diff: net/cert/merkle_tree_leaf_unittest.cc

Issue 2107423004: Certificate Transparency: MerkleTreeLeaf, MerkleAuditProof improvements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing botched merge Created 4 years, 5 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
« no previous file with comments | « net/cert/merkle_tree_leaf.cc ('k') | net/test/ct_test_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/merkle_tree_leaf.h" 5 #include "net/cert/merkle_tree_leaf.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 scoped_refptr<SignedCertificateTimestamp> x509_sct_; 68 scoped_refptr<SignedCertificateTimestamp> x509_sct_;
69 scoped_refptr<SignedCertificateTimestamp> precert_sct_; 69 scoped_refptr<SignedCertificateTimestamp> precert_sct_;
70 scoped_refptr<X509Certificate> test_cert_; 70 scoped_refptr<X509Certificate> test_cert_;
71 scoped_refptr<X509Certificate> test_precert_; 71 scoped_refptr<X509Certificate> test_precert_;
72 }; 72 };
73 73
74 TEST_F(MerkleTreeLeafTest, CreatesForX509Cert) { 74 TEST_F(MerkleTreeLeafTest, CreatesForX509Cert) {
75 MerkleTreeLeaf leaf; 75 MerkleTreeLeaf leaf;
76 ASSERT_TRUE(GetMerkleTreeLeaf(test_cert_.get(), x509_sct_.get(), &leaf)); 76 ASSERT_TRUE(GetMerkleTreeLeaf(test_cert_.get(), x509_sct_.get(), &leaf));
77 77
78 EXPECT_EQ(x509_sct_->log_id, leaf.log_id);
79 EXPECT_EQ(LogEntry::LOG_ENTRY_TYPE_X509, leaf.log_entry.type); 78 EXPECT_EQ(LogEntry::LOG_ENTRY_TYPE_X509, leaf.log_entry.type);
80 EXPECT_FALSE(leaf.log_entry.leaf_certificate.empty()); 79 EXPECT_FALSE(leaf.log_entry.leaf_certificate.empty());
81 EXPECT_TRUE(leaf.log_entry.tbs_certificate.empty()); 80 EXPECT_TRUE(leaf.log_entry.tbs_certificate.empty());
82 81
83 EXPECT_EQ(x509_sct_->timestamp, leaf.timestamp); 82 EXPECT_EQ(x509_sct_->timestamp, leaf.timestamp);
84 EXPECT_EQ(x509_sct_->extensions, leaf.extensions); 83 EXPECT_EQ(x509_sct_->extensions, leaf.extensions);
85 } 84 }
86 85
87 TEST_F(MerkleTreeLeafTest, CreatesForPrecert) { 86 TEST_F(MerkleTreeLeafTest, CreatesForPrecert) {
88 MerkleTreeLeaf leaf; 87 MerkleTreeLeaf leaf;
89 ASSERT_TRUE( 88 ASSERT_TRUE(
90 GetMerkleTreeLeaf(test_precert_.get(), precert_sct_.get(), &leaf)); 89 GetMerkleTreeLeaf(test_precert_.get(), precert_sct_.get(), &leaf));
91 90
92 EXPECT_EQ(precert_sct_->log_id, leaf.log_id);
93 EXPECT_EQ(LogEntry::LOG_ENTRY_TYPE_PRECERT, leaf.log_entry.type); 91 EXPECT_EQ(LogEntry::LOG_ENTRY_TYPE_PRECERT, leaf.log_entry.type);
94 EXPECT_FALSE(leaf.log_entry.tbs_certificate.empty()); 92 EXPECT_FALSE(leaf.log_entry.tbs_certificate.empty());
95 EXPECT_TRUE(leaf.log_entry.leaf_certificate.empty()); 93 EXPECT_TRUE(leaf.log_entry.leaf_certificate.empty());
96 94
97 EXPECT_EQ(precert_sct_->timestamp, leaf.timestamp); 95 EXPECT_EQ(precert_sct_->timestamp, leaf.timestamp);
98 EXPECT_EQ(precert_sct_->extensions, leaf.extensions); 96 EXPECT_EQ(precert_sct_->extensions, leaf.extensions);
99 } 97 }
100 98
101 TEST_F(MerkleTreeLeafTest, DoesNotCreateForEmbeddedSCTButNotPrecert) { 99 TEST_F(MerkleTreeLeafTest, DoesNotCreateForEmbeddedSCTButNotPrecert) {
102 MerkleTreeLeaf leaf; 100 MerkleTreeLeaf leaf;
103 ASSERT_FALSE(GetMerkleTreeLeaf(test_cert_.get(), precert_sct_.get(), &leaf)); 101 ASSERT_FALSE(GetMerkleTreeLeaf(test_cert_.get(), precert_sct_.get(), &leaf));
104 } 102 }
105 103
106 // Expected hashes calculated by: 104 // Expected hashes calculated by:
107 // 1. Writing the serialized tree leaves from 105 // 1. Writing the serialized tree leaves from
108 // CtSerialization::EncodesLogEntryFor{X509Cert,Precert} to files. 106 // CtSerialization::EncodesLogEntryFor{X509Cert,Precert} to files.
109 // 2. Prepending a zero byte to both files. 107 // 2. Prepending a zero byte to both files.
110 // 3. Passing each file through the sha256sum tool. 108 // 3. Passing each file through the sha256sum tool.
111 109
112 TEST_F(MerkleTreeLeafTest, HashForX509Cert) { 110 TEST_F(MerkleTreeLeafTest, HashForX509Cert) {
113 MerkleTreeLeaf leaf; 111 MerkleTreeLeaf leaf;
114 ct::GetX509CertTreeLeaf(&leaf); 112 ct::GetX509CertTreeLeaf(&leaf);
115 113
116 std::string hash; 114 std::string hash;
117 ASSERT_TRUE(Hash(leaf, &hash)); 115 ASSERT_TRUE(HashMerkleTreeLeaf(leaf, &hash));
118 EXPECT_THAT(hash, HexEq("452da788b3b8d15872ff0bb0777354b2a7f1c1887b5633201e76" 116 EXPECT_THAT(hash, HexEq("452da788b3b8d15872ff0bb0777354b2a7f1c1887b5633201e76"
119 "2ba5a4b143fc")); 117 "2ba5a4b143fc"));
120 } 118 }
121 119
122 TEST_F(MerkleTreeLeafTest, HashForPrecert) { 120 TEST_F(MerkleTreeLeafTest, HashForPrecert) {
123 MerkleTreeLeaf leaf; 121 MerkleTreeLeaf leaf;
124 ct::GetPrecertTreeLeaf(&leaf); 122 ct::GetPrecertTreeLeaf(&leaf);
125 123
126 std::string hash; 124 std::string hash;
127 ASSERT_TRUE(Hash(leaf, &hash)); 125 ASSERT_TRUE(HashMerkleTreeLeaf(leaf, &hash));
128 EXPECT_THAT(hash, HexEq("257ae85f08810445511e35e33f7aee99ee19407971e35e95822b" 126 EXPECT_THAT(hash, HexEq("257ae85f08810445511e35e33f7aee99ee19407971e35e95822b"
129 "bf42a74be223")); 127 "bf42a74be223"));
130 } 128 }
131 129
132 } // namespace 130 } // namespace
133 131
134 } // namespace ct 132 } // namespace ct
135 133
136 } // namespace net 134 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/merkle_tree_leaf.cc ('k') | net/test/ct_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698