Chromium Code Reviews| 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 <tuple> | |
| 12 #include <utility> | |
| 13 #include <vector> | |
| 11 | 14 |
| 12 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 14 #include "crypto/secure_hash.h" | 17 #include "crypto/secure_hash.h" |
| 15 #include "net/base/hash_value.h" | 18 #include "net/base/hash_value.h" |
| 16 #include "net/cert/ct_log_verifier_util.h" | 19 #include "net/cert/ct_log_verifier_util.h" |
| 17 #include "net/cert/merkle_consistency_proof.h" | 20 #include "net/cert/merkle_consistency_proof.h" |
| 18 #include "net/cert/signed_certificate_timestamp.h" | 21 #include "net/cert/signed_certificate_timestamp.h" |
| 19 #include "net/cert/signed_tree_head.h" | 22 #include "net/cert/signed_tree_head.h" |
| 20 #include "net/test/ct_test_util.h" | 23 #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. | 481 // doesn't contain the root of snapshot1, so set have_root1 = false. |
| 479 subproof = ReferenceSnapshotConsistency(&inputs[split], snapshot2 - split, | 482 subproof = ReferenceSnapshotConsistency(&inputs[split], snapshot2 - split, |
| 480 snapshot1 - split, false); | 483 snapshot1 - split, false); |
| 481 proof.insert(proof.end(), subproof.begin(), subproof.end()); | 484 proof.insert(proof.end(), subproof.begin(), subproof.end()); |
| 482 // Record the hash of the left subtree (equal in both trees). | 485 // Record the hash of the left subtree (equal in both trees). |
| 483 proof.push_back(ReferenceMerkleTreeHash(&inputs[0], split)); | 486 proof.push_back(ReferenceMerkleTreeHash(&inputs[0], split)); |
| 484 } | 487 } |
| 485 return proof; | 488 return proof; |
| 486 } | 489 } |
| 487 | 490 |
| 488 // Times out on Win7 test bot. http://crbug.com/598406 | 491 // Generates all valid combinations of tree size and snapshot size / leaf index |
| 489 #if defined(OS_WIN) | 492 // (assuming the leaf index is 1-based). Combinations will be generated for all |
| 490 #define MAYBE_VerifiesValidConsistencyProofsFromReferenceGenerator \ | 493 // tree sizes from 1 to |max_tree_size|. |
| 491 DISABLED_VerifiesValidConsistencyProofsFromReferenceGenerator | 494 // This is useful for exhaustive testing of consistency proof and audit proof |
| 492 #else | 495 // verification. |
| 493 #define MAYBE_VerifiesValidConsistencyProofsFromReferenceGenerator \ | 496 std::vector<std::pair<uint64_t, uint64_t>> GenerateTestParams( |
| 494 VerifiesValidConsistencyProofsFromReferenceGenerator | 497 size_t max_tree_size) { |
| 495 #endif | 498 std::vector<std::pair<uint64_t, uint64_t>> params; |
| 496 TEST_F(CTLogVerifierTest, | 499 params.reserve(max_tree_size * (max_tree_size + 1) / 2); |
| 497 MAYBE_VerifiesValidConsistencyProofsFromReferenceGenerator) { | 500 for (uint64_t tree_size = 1; tree_size <= max_tree_size; ++tree_size) { |
| 501 for (uint64_t x = 1; x <= tree_size; ++x) { | |
| 502 // |x| could be a tree snapshot size (for consistency proof tests) or a | |
| 503 // leaf index (for inclusion proofs tests). | |
| 504 params.emplace_back(tree_size, x); | |
| 505 } | |
| 506 } | |
| 507 return params; | |
| 508 } | |
| 509 | |
| 510 class CTLogVerifierTestUsingReferenceGenerator | |
| 511 : public CTLogVerifierTest, | |
| 512 public ::testing::WithParamInterface<std::pair<uint64_t, uint64_t>> {}; | |
| 513 | |
| 514 TEST_P(CTLogVerifierTestUsingReferenceGenerator, | |
| 515 VerifiesValidConsistencyProof) { | |
| 498 std::vector<std::string> data; | 516 std::vector<std::string> data; |
| 499 for (int i = 0; i < 256; ++i) | 517 for (int i = 0; i < 256; ++i) |
| 500 data.push_back(std::string(1, i)); | 518 data.push_back(std::string(1, i)); |
| 501 | 519 |
| 502 std::vector<std::string> proof; | 520 uint64_t tree_size, snapshot; |
| 503 std::string root1, root2; | 521 std::tie(tree_size, snapshot) = GetParam(); |
| 504 // More tests with reference proof generator. | 522 std::string root1 = ReferenceMerkleTreeHash(data.data(), snapshot); |
| 505 for (size_t tree_size = 1; tree_size <= data.size() / 2; ++tree_size) { | 523 std::string root2 = ReferenceMerkleTreeHash(data.data(), tree_size); |
| 506 root2 = ReferenceMerkleTreeHash(data.data(), tree_size); | 524 std::vector<std::string> proof = |
| 507 // Repeat for each snapshot in range. | 525 ReferenceSnapshotConsistency(data.data(), tree_size, snapshot, true); |
| 508 for (size_t snapshot = 1; snapshot <= tree_size; ++snapshot) { | 526 VerifierConsistencyCheck(snapshot, tree_size, root1, root2, proof); |
| 509 proof = | |
| 510 ReferenceSnapshotConsistency(data.data(), tree_size, snapshot, true); | |
| 511 root1 = ReferenceMerkleTreeHash(data.data(), snapshot); | |
| 512 VerifierConsistencyCheck(snapshot, tree_size, root1, root2, proof); | |
| 513 } | |
| 514 } | |
| 515 } | 527 } |
| 516 | 528 |
| 529 // Test verification of consistency proofs between all tree sizes from 1 to 128. | |
| 530 INSTANTIATE_TEST_CASE_P(RangeOfTreeSizesAndSnapshots, | |
| 531 CTLogVerifierTestUsingReferenceGenerator, | |
| 532 testing::ValuesIn(GenerateTestParams(128))); | |
|
Ryan Sleevi
2016/07/28 16:46:50
Doesn't this 128 magic value tightly couple with t
Rob Percival
2016/07/28 17:39:24
Indeed it does - I've created a constant to link t
| |
| 533 | |
| 517 } // namespace | 534 } // namespace |
| 518 | 535 |
| 519 } // namespace net | 536 } // namespace net |
| OLD | NEW |