| OLD | NEW |
| 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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->timestamp = base::Time::UnixEpoch() + | 260 sth->timestamp = base::Time::UnixEpoch() + |
| 261 base::TimeDelta::FromMilliseconds(kSampleSTHTimestamp); | 261 base::TimeDelta::FromMilliseconds(kSampleSTHTimestamp); |
| 262 sth->tree_size = kSampleSTHTreeSize; | 262 sth->tree_size = kSampleSTHTreeSize; |
| 263 std::string sha256_root_hash = GetSampleSTHSHA256RootHash(); | 263 std::string sha256_root_hash = GetSampleSTHSHA256RootHash(); |
| 264 memcpy(sth->sha256_root_hash, sha256_root_hash.c_str(), kSthRootHashLength); | 264 memcpy(sth->sha256_root_hash, sha256_root_hash.c_str(), kSthRootHashLength); |
| 265 sth->log_id = GetTestPublicKeyId(); |
| 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) { |
| 270 sth->version = SignedTreeHead::V1; | 271 sth->version = SignedTreeHead::V1; |
| 271 sth->timestamp = base::Time::UnixEpoch() + | 272 sth->timestamp = base::Time::UnixEpoch() + |
| 272 base::TimeDelta::FromMilliseconds(INT64_C(1450443594920)); | 273 base::TimeDelta::FromMilliseconds(INT64_C(1450443594920)); |
| 273 sth->tree_size = 0; | 274 sth->tree_size = 0; |
| 274 std::string empty_root_hash = HexToBytes( | 275 std::string empty_root_hash = HexToBytes( |
| 275 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); | 276 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); |
| 276 memcpy(sth->sha256_root_hash, empty_root_hash.c_str(), kSthRootHashLength); | 277 memcpy(sth->sha256_root_hash, empty_root_hash.c_str(), kSthRootHashLength); |
| 278 sth->log_id = GetTestPublicKeyId(); |
| 277 | 279 |
| 278 std::string tree_head_signature = HexToBytes( | 280 std::string tree_head_signature = HexToBytes( |
| 279 "040300463044022046c26401de9416403da54762dc1f1687c38eafd791b15e484ab4c5f7" | 281 "040300463044022046c26401de9416403da54762dc1f1687c38eafd791b15e484ab4c5f7" |
| 280 "f52721fe02201bf537a3bbea47109fc76c2273fe0f3349f493a07de9335c266330105fb0" | 282 "f52721fe02201bf537a3bbea47109fc76c2273fe0f3349f493a07de9335c266330105fb0" |
| 281 "2a4a"); | 283 "2a4a"); |
| 282 base::StringPiece sp(tree_head_signature); | 284 base::StringPiece sp(tree_head_signature); |
| 283 return DecodeDigitallySigned(&sp, &(sth->signature)) && sp.empty(); | 285 return DecodeDigitallySigned(&sp, &(sth->signature)) && sp.empty(); |
| 284 } | 286 } |
| 285 | 287 |
| 286 bool GetBadEmptySignedTreeHead(SignedTreeHead* sth) { | 288 bool GetBadEmptySignedTreeHead(SignedTreeHead* sth) { |
| 287 sth->version = SignedTreeHead::V1; | 289 sth->version = SignedTreeHead::V1; |
| 288 sth->timestamp = base::Time::UnixEpoch() + | 290 sth->timestamp = base::Time::UnixEpoch() + |
| 289 base::TimeDelta::FromMilliseconds(INT64_C(1450870952897)); | 291 base::TimeDelta::FromMilliseconds(INT64_C(1450870952897)); |
| 290 sth->tree_size = 0; | 292 sth->tree_size = 0; |
| 291 memset(sth->sha256_root_hash, 'f', kSthRootHashLength); | 293 memset(sth->sha256_root_hash, 'f', kSthRootHashLength); |
| 294 sth->log_id = GetTestPublicKeyId(); |
| 292 | 295 |
| 293 std::string tree_head_signature = HexToBytes( | 296 std::string tree_head_signature = HexToBytes( |
| 294 "04030046304402207cab04c62dee5d1cbc95fec30cd8417313f71587b75f133ad2e6f324" | 297 "04030046304402207cab04c62dee5d1cbc95fec30cd8417313f71587b75f133ad2e6f324" |
| 295 "74f164d702205e2f3a9bce46f87d7e20e951a4e955da3cb502f8717a22fabd7c5d7e1bef" | 298 "74f164d702205e2f3a9bce46f87d7e20e951a4e955da3cb502f8717a22fabd7c5d7e1bef" |
| 296 "46ea"); | 299 "46ea"); |
| 297 base::StringPiece sp(tree_head_signature); | 300 base::StringPiece sp(tree_head_signature); |
| 298 return DecodeDigitallySigned(&sp, &(sth->signature)) && sp.empty(); | 301 return DecodeDigitallySigned(&sp, &(sth->signature)) && sp.empty(); |
| 299 } | 302 } |
| 300 | 303 |
| 301 std::string GetSampleSTHSHA256RootHash() { | 304 std::string GetSampleSTHSHA256RootHash() { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 | 391 |
| 389 bool CheckForSCTOrigin(const ct::CTVerifyResult& result, | 392 bool CheckForSCTOrigin(const ct::CTVerifyResult& result, |
| 390 ct::SignedCertificateTimestamp::Origin origin) { | 393 ct::SignedCertificateTimestamp::Origin origin) { |
| 391 return (result.verified_scts.size() > 0) && | 394 return (result.verified_scts.size() > 0) && |
| 392 (result.verified_scts[0]->origin == origin); | 395 (result.verified_scts[0]->origin == origin); |
| 393 } | 396 } |
| 394 | 397 |
| 395 } // namespace ct | 398 } // namespace ct |
| 396 | 399 |
| 397 } // namespace net | 400 } // namespace net |
| OLD | NEW |