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

Side by Side Diff: net/test/ct_test_util.cc

Issue 1845113003: Certificate Transparency: Start tracking logs' state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/test/ct_test_util.h ('k') | no next file » | 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/test/ct_test_util.h" 5 #include "net/test/ct_test_util.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string.h> 8 #include <string.h>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 198
199 std::string GetTestPublicKeyId() { 199 std::string GetTestPublicKeyId() {
200 return HexToBytes(kTestKeyId); 200 return HexToBytes(kTestKeyId);
201 } 201 }
202 202
203 void GetX509CertSCT(scoped_refptr<SignedCertificateTimestamp>* sct_ref) { 203 void GetX509CertSCT(scoped_refptr<SignedCertificateTimestamp>* sct_ref) {
204 CHECK(sct_ref != NULL); 204 CHECK(sct_ref != NULL);
205 *sct_ref = new SignedCertificateTimestamp(); 205 *sct_ref = new SignedCertificateTimestamp();
206 SignedCertificateTimestamp *const sct(sct_ref->get()); 206 SignedCertificateTimestamp *const sct(sct_ref->get());
207 sct->version = ct::SignedCertificateTimestamp::SCT_VERSION_1; 207 sct->version = ct::SignedCertificateTimestamp::SCT_VERSION_1;
208 sct->log_id = HexToBytes(kTestKeyId); 208 sct->log_id = GetTestPublicKeyId();
209 // Time the log issued a SCT for this certificate, which is 209 // Time the log issued a SCT for this certificate, which is
210 // Fri Apr 5 10:04:16.089 2013 210 // Fri Apr 5 10:04:16.089 2013
211 sct->timestamp = base::Time::UnixEpoch() + 211 sct->timestamp = base::Time::UnixEpoch() +
212 base::TimeDelta::FromMilliseconds(INT64_C(1365181456089)); 212 base::TimeDelta::FromMilliseconds(INT64_C(1365181456089));
213 sct->extensions.clear(); 213 sct->extensions.clear();
214 214
215 sct->signature.hash_algorithm = ct::DigitallySigned::HASH_ALGO_SHA256; 215 sct->signature.hash_algorithm = ct::DigitallySigned::HASH_ALGO_SHA256;
216 sct->signature.signature_algorithm = ct::DigitallySigned::SIG_ALGO_ECDSA; 216 sct->signature.signature_algorithm = ct::DigitallySigned::SIG_ALGO_ECDSA;
217 sct->signature.signature_data = HexToBytes(kTestSCTSignatureData); 217 sct->signature.signature_data = HexToBytes(kTestSCTSignatureData);
218 } 218 }
219 219
220 void GetPrecertSCT(scoped_refptr<SignedCertificateTimestamp>* sct_ref) { 220 void GetPrecertSCT(scoped_refptr<SignedCertificateTimestamp>* sct_ref) {
221 CHECK(sct_ref != NULL); 221 CHECK(sct_ref != NULL);
222 *sct_ref = new SignedCertificateTimestamp(); 222 *sct_ref = new SignedCertificateTimestamp();
223 SignedCertificateTimestamp *const sct(sct_ref->get()); 223 SignedCertificateTimestamp *const sct(sct_ref->get());
224 sct->version = ct::SignedCertificateTimestamp::SCT_VERSION_1; 224 sct->version = ct::SignedCertificateTimestamp::SCT_VERSION_1;
225 sct->log_id = HexToBytes(kTestKeyId); 225 sct->log_id = GetTestPublicKeyId();
226 // Time the log issued a SCT for this Precertificate, which is 226 // Time the log issued a SCT for this Precertificate, which is
227 // Fri Apr 5 10:04:16.275 2013 227 // Fri Apr 5 10:04:16.275 2013
228 sct->timestamp = base::Time::UnixEpoch() + 228 sct->timestamp = base::Time::UnixEpoch() +
229 base::TimeDelta::FromMilliseconds(INT64_C(1365181456275)); 229 base::TimeDelta::FromMilliseconds(INT64_C(1365181456275));
230 sct->extensions.clear(); 230 sct->extensions.clear();
231 231
232 sct->signature.hash_algorithm = ct::DigitallySigned::HASH_ALGO_SHA256; 232 sct->signature.hash_algorithm = ct::DigitallySigned::HASH_ALGO_SHA256;
233 sct->signature.signature_algorithm = ct::DigitallySigned::SIG_ALGO_ECDSA; 233 sct->signature.signature_algorithm = ct::DigitallySigned::SIG_ALGO_ECDSA;
234 sct->signature.signature_data = HexToBytes(kTestSCTPrecertSignatureData); 234 sct->signature.signature_data = HexToBytes(kTestSCTPrecertSignatureData);
235 } 235 }
(...skipping 14 matching lines...) Expand all
250 return HexToBytes(kFakeOCSPResponseCert); 250 return HexToBytes(kFakeOCSPResponseCert);
251 } 251 }
252 252
253 std::string GetDerEncodedFakeOCSPResponseIssuerCert() { 253 std::string GetDerEncodedFakeOCSPResponseIssuerCert() {
254 return HexToBytes(kFakeOCSPResponseIssuerCert); 254 return HexToBytes(kFakeOCSPResponseIssuerCert);
255 } 255 }
256 256
257 // A sample, valid STH 257 // A sample, valid STH
258 bool GetSampleSignedTreeHead(SignedTreeHead* sth) { 258 bool GetSampleSignedTreeHead(SignedTreeHead* sth) {
259 sth->version = SignedTreeHead::V1; 259 sth->version = SignedTreeHead::V1;
260 sth->log_id = GetTestPublicKeyId();
260 sth->timestamp = base::Time::UnixEpoch() + 261 sth->timestamp = base::Time::UnixEpoch() +
261 base::TimeDelta::FromMilliseconds(kSampleSTHTimestamp); 262 base::TimeDelta::FromMilliseconds(kSampleSTHTimestamp);
262 sth->tree_size = kSampleSTHTreeSize; 263 sth->tree_size = kSampleSTHTreeSize;
263 std::string sha256_root_hash = GetSampleSTHSHA256RootHash(); 264 std::string sha256_root_hash = GetSampleSTHSHA256RootHash();
264 memcpy(sth->sha256_root_hash, sha256_root_hash.c_str(), kSthRootHashLength); 265 memcpy(sth->sha256_root_hash, sha256_root_hash.c_str(), kSthRootHashLength);
265 266
266 return GetSampleSTHTreeHeadDecodedSignature(&(sth->signature)); 267 return GetSampleSTHTreeHeadDecodedSignature(&(sth->signature));
267 } 268 }
268 269
269 bool GetSampleEmptySignedTreeHead(SignedTreeHead* sth) { 270 bool GetSampleEmptySignedTreeHead(SignedTreeHead* sth) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 std::string GetSampleSTHTreeHeadSignature() { 306 std::string GetSampleSTHTreeHeadSignature() {
306 return HexToBytes(kSampleSTHTreeHeadSignature); 307 return HexToBytes(kSampleSTHTreeHeadSignature);
307 } 308 }
308 309
309 bool GetSampleSTHTreeHeadDecodedSignature(DigitallySigned* signature) { 310 bool GetSampleSTHTreeHeadDecodedSignature(DigitallySigned* signature) {
310 std::string tree_head_signature = HexToBytes(kSampleSTHTreeHeadSignature); 311 std::string tree_head_signature = HexToBytes(kSampleSTHTreeHeadSignature);
311 base::StringPiece sp(tree_head_signature); 312 base::StringPiece sp(tree_head_signature);
312 return DecodeDigitallySigned(&sp, signature) && sp.empty(); 313 return DecodeDigitallySigned(&sp, signature) && sp.empty();
313 } 314 }
314 315
316 std::string GetSampleSTH() {
317 const std::string log_id = ct::GetTestPublicKeyId();
318 const std::string timestamp("\x0\x0\x1\x45\x3c\x5f\xb8\x35", 8);
319 const std::string tree_size("\x0\x0\x0\x0\x0\x0\x0\x15", 8);
320
321 std::string expected_output;
322 expected_output += log_id;
323 expected_output += timestamp;
324 expected_output += tree_size;
325 expected_output += ct::GetSampleSTHSHA256RootHash();
326 expected_output += ct::GetSampleSTHTreeHeadSignature();
327
328 return expected_output;
329 }
330
315 std::string GetSampleSTHAsJson() { 331 std::string GetSampleSTHAsJson() {
316 return CreateSignedTreeHeadJsonString(kSampleSTHTreeSize, kSampleSTHTimestamp, 332 return CreateSignedTreeHeadJsonString(kSampleSTHTreeSize, kSampleSTHTimestamp,
317 GetSampleSTHSHA256RootHash(), 333 GetSampleSTHSHA256RootHash(),
318 GetSampleSTHTreeHeadSignature()); 334 GetSampleSTHTreeHeadSignature());
319 } 335 }
320 336
321 std::string CreateSignedTreeHeadJsonString(size_t tree_size, 337 std::string CreateSignedTreeHeadJsonString(size_t tree_size,
322 int64_t timestamp, 338 int64_t timestamp,
323 std::string sha256_root_hash, 339 std::string sha256_root_hash,
324 std::string tree_head_signature) { 340 std::string tree_head_signature) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 404
389 bool CheckForSCTOrigin(const ct::CTVerifyResult& result, 405 bool CheckForSCTOrigin(const ct::CTVerifyResult& result,
390 ct::SignedCertificateTimestamp::Origin origin) { 406 ct::SignedCertificateTimestamp::Origin origin) {
391 return (result.verified_scts.size() > 0) && 407 return (result.verified_scts.size() > 0) &&
392 (result.verified_scts[0]->origin == origin); 408 (result.verified_scts[0]->origin == origin);
393 } 409 }
394 410
395 } // namespace ct 411 } // namespace ct
396 412
397 } // namespace net 413 } // namespace net
OLDNEW
« no previous file with comments | « net/test/ct_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698