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

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

Issue 27026002: CT: Adding preliminary Certificate Transparency support to Chromium. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Distinguish between SCTs from unknown logs and unverified ones Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « net/cert/ct_objects_extractor_unittest.cc ('k') | net/cert/ct_verifier.h » ('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 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/ct_serialization.h" 5 #include "net/cert/ct_serialization.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 ASSERT_FALSE(ct::DecodeSCTList(&encoded, &decoded)); 131 ASSERT_FALSE(ct::DecodeSCTList(&encoded, &decoded));
132 } 132 }
133 133
134 TEST_F(CtSerializationTest, DecodesSignedCertificateTimestamp) { 134 TEST_F(CtSerializationTest, DecodesSignedCertificateTimestamp) {
135 std::string encoded_test_sct(ct::GetTestSignedCertificateTimestamp()); 135 std::string encoded_test_sct(ct::GetTestSignedCertificateTimestamp());
136 base::StringPiece encoded_sct(encoded_test_sct); 136 base::StringPiece encoded_sct(encoded_test_sct);
137 137
138 ct::SignedCertificateTimestamp sct; 138 ct::SignedCertificateTimestamp sct;
139 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct)); 139 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct));
140 EXPECT_EQ(0, sct.version); 140 EXPECT_EQ(0, sct.version);
141 std::string expected_log_key( 141 EXPECT_EQ(ct::GetTestPublicKeyId(), sct.log_id);
142 "\xdf\x1c\x2e\xc1\x15\x00\x94\x52\x47\xa9\x61\x68\x32\x5d\xdc\x5c\x79\x59"
143 "\xe8\xf7\xc6\xd3\x88\xfc\x00\x2e\x0b\xbd\x3f\x74\xd7\x64",
144 32);
145 EXPECT_EQ(expected_log_key, sct.log_id);
146 base::Time expected_time = base::Time::UnixEpoch() + 142 base::Time expected_time = base::Time::UnixEpoch() +
147 base::TimeDelta::FromMilliseconds(1365181456089); 143 base::TimeDelta::FromMilliseconds(1365181456089);
148 EXPECT_EQ(expected_time, sct.timestamp); 144 EXPECT_EQ(expected_time, sct.timestamp);
149 // Subtracting 4 bytes for signature data (hash & sig algs), 145 // Subtracting 4 bytes for signature data (hash & sig algs),
150 // actual signature data should be 71 bytes. 146 // actual signature data should be 71 bytes.
151 EXPECT_EQ((size_t) 71, sct.signature.signature_data.size()); 147 EXPECT_EQ((size_t) 71, sct.signature.signature_data.size());
152 EXPECT_EQ(std::string(""), sct.extensions); 148 EXPECT_EQ(std::string(""), sct.extensions);
153 } 149 }
154 150
155 TEST_F(CtSerializationTest, FailsDecodingInvalidSignedCertificateTimestamp) { 151 TEST_F(CtSerializationTest, FailsDecodingInvalidSignedCertificateTimestamp) {
156 // Invalid version 152 // Invalid version
157 base::StringPiece invalid_version_sct("\x2\x0", 2); 153 base::StringPiece invalid_version_sct("\x2\x0", 2);
158 ct::SignedCertificateTimestamp sct; 154 ct::SignedCertificateTimestamp sct;
159 155
160 ASSERT_FALSE( 156 ASSERT_FALSE(
161 ct::DecodeSignedCertificateTimestamp(&invalid_version_sct, &sct)); 157 ct::DecodeSignedCertificateTimestamp(&invalid_version_sct, &sct));
162 158
163 // Valid version, invalid length (missing data) 159 // Valid version, invalid length (missing data)
164 base::StringPiece invalid_length_sct("\x0\xa\xb\xc", 4); 160 base::StringPiece invalid_length_sct("\x0\xa\xb\xc", 4);
165 ASSERT_FALSE( 161 ASSERT_FALSE(
166 ct::DecodeSignedCertificateTimestamp(&invalid_length_sct, &sct)); 162 ct::DecodeSignedCertificateTimestamp(&invalid_length_sct, &sct));
167 } 163 }
168 164
169 } // namespace net 165 } // namespace net
170 166
OLDNEW
« no previous file with comments | « net/cert/ct_objects_extractor_unittest.cc ('k') | net/cert/ct_verifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698