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/cert/ct_log_verifier.h" | 5 #include "net/cert/ct_log_verifier.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | |
11 | 12 |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "crypto/secure_hash.h" | 15 #include "crypto/secure_hash.h" |
15 #include "net/base/hash_value.h" | 16 #include "net/base/hash_value.h" |
16 #include "net/cert/ct_log_verifier_util.h" | 17 #include "net/cert/ct_log_verifier_util.h" |
17 #include "net/cert/merkle_consistency_proof.h" | 18 #include "net/cert/merkle_consistency_proof.h" |
18 #include "net/cert/signed_certificate_timestamp.h" | 19 #include "net/cert/signed_certificate_timestamp.h" |
19 #include "net/cert/signed_tree_head.h" | 20 #include "net/cert/signed_tree_head.h" |
20 #include "net/test/ct_test_util.h" | 21 #include "net/test/ct_test_util.h" |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 // doesn't contain the root of snapshot1, so set have_root1 = false. | 479 // doesn't contain the root of snapshot1, so set have_root1 = false. |
479 subproof = ReferenceSnapshotConsistency(&inputs[split], snapshot2 - split, | 480 subproof = ReferenceSnapshotConsistency(&inputs[split], snapshot2 - split, |
480 snapshot1 - split, false); | 481 snapshot1 - split, false); |
481 proof.insert(proof.end(), subproof.begin(), subproof.end()); | 482 proof.insert(proof.end(), subproof.begin(), subproof.end()); |
482 // Record the hash of the left subtree (equal in both trees). | 483 // Record the hash of the left subtree (equal in both trees). |
483 proof.push_back(ReferenceMerkleTreeHash(&inputs[0], split)); | 484 proof.push_back(ReferenceMerkleTreeHash(&inputs[0], split)); |
484 } | 485 } |
485 return proof; | 486 return proof; |
486 } | 487 } |
487 | 488 |
488 // Times out on Win7 test bot. http://crbug.com/598406 | 489 class CTLogVerifierTestUsingReferenceGenerator |
489 #if defined(OS_WIN) | 490 : public CTLogVerifierTest, |
490 #define MAYBE_VerifiesValidConsistencyProofsFromReferenceGenerator \ | 491 public ::testing::WithParamInterface<uint64_t> {}; |
491 DISABLED_VerifiesValidConsistencyProofsFromReferenceGenerator | 492 |
492 #else | 493 const uint64_t kReferenceTreeSize = 256; |
493 #define MAYBE_VerifiesValidConsistencyProofsFromReferenceGenerator \ | 494 |
494 VerifiesValidConsistencyProofsFromReferenceGenerator | 495 TEST_P(CTLogVerifierTestUsingReferenceGenerator, |
495 #endif | 496 VerifiesValidConsistencyProof) { |
496 TEST_F(CTLogVerifierTest, | |
497 MAYBE_VerifiesValidConsistencyProofsFromReferenceGenerator) { | |
498 std::vector<std::string> data; | 497 std::vector<std::string> data; |
499 for (int i = 0; i < 256; ++i) | 498 for (uint64_t i = 0; i < kReferenceTreeSize; ++i) |
500 data.push_back(std::string(1, i)); | 499 data.push_back(std::string(1, static_cast<char>(i))); |
501 | 500 |
502 std::vector<std::string> proof; | 501 const uint64_t tree_size = GetParam(); |
503 std::string root1, root2; | 502 const std::string tree_root = ReferenceMerkleTreeHash(data.data(), tree_size); |
504 // More tests with reference proof generator. | 503 |
505 for (size_t tree_size = 1; tree_size <= data.size() / 2; ++tree_size) { | 504 for (uint64_t snapshot = 1; snapshot <= tree_size; ++snapshot) { |
506 root2 = ReferenceMerkleTreeHash(data.data(), tree_size); | 505 SCOPED_TRACE(snapshot); |
507 // Repeat for each snapshot in range. | 506 const std::string snapshot_root = |
508 for (size_t snapshot = 1; snapshot <= tree_size; ++snapshot) { | 507 ReferenceMerkleTreeHash(data.data(), snapshot); |
509 proof = | 508 const std::vector<std::string> proof = |
510 ReferenceSnapshotConsistency(data.data(), tree_size, snapshot, true); | 509 ReferenceSnapshotConsistency(data.data(), tree_size, snapshot, true); |
511 root1 = ReferenceMerkleTreeHash(data.data(), snapshot); | 510 VerifierConsistencyCheck(snapshot, tree_size, snapshot_root, tree_root, |
512 VerifierConsistencyCheck(snapshot, tree_size, root1, root2, proof); | 511 proof); |
513 } | |
514 } | 512 } |
515 } | 513 } |
516 | 514 |
515 // Test verification of consistency proofs between all tree sizes from 1 to 128. | |
516 INSTANTIATE_TEST_CASE_P(RangeOfTreeSizesAndSnapshots, | |
517 CTLogVerifierTestUsingReferenceGenerator, | |
518 testing::Range(1ul, (kReferenceTreeSize / 2) + 1)); | |
Ryan Sleevi
2016/07/28 18:45:41
UINT64_C(1) should resolve the compile issues :)
| |
519 | |
517 } // namespace | 520 } // namespace |
518 | 521 |
519 } // namespace net | 522 } // namespace net |
OLD | NEW |