#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/cert/ct_log_verifier.h"
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "crypto/secure_hash.h"
#include "net/base/hash_value.h"
#include "net/cert/ct_log_verifier_util.h"
#include "net/cert/merkle_audit_proof.h"
#include "net/cert/merkle_consistency_proof.h"
#include "net/cert/signed_certificate_timestamp.h"
#include "net/cert/signed_tree_head.h"
#include "net/test/ct_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
namespace {
size_t CalculateNearestPowerOfTwo(size_t n) { … }
const uint8_t kEmptyTreeHash[32] = …;
std::string GetEmptyTreeHash() { … }
const char* const kLeafHashes[8] = …;
const char* const kRootHashes[8] = …;
struct ConsistencyProofTestVector { … };
const ConsistencyProofTestVector kConsistencyProofs[] = …;
struct AuditProofTestVector { … };
const AuditProofTestVector kAuditProofs[] = …;
std::string HexToBytes(const std::string& hex_data) { … }
template <typename TestVectorType>
std::vector<std::string> GetProof(const TestVectorType& test_vector) { … }
bool VerifyConsistencyProof(const CTLogVerifier& log,
size_t old_tree_size,
const std::string& old_tree_root,
size_t new_tree_size,
const std::string& new_tree_root,
const std::vector<std::string>& proof) { … }
bool VerifyAuditProof(const CTLogVerifier& log,
size_t leaf,
size_t tree_size,
const std::vector<std::string>& proof,
const std::string& tree_root,
const std::string& leaf_hash) { … }
class CTLogVerifierTest : public ::testing::Test { … };
void CheckVerifyAuditProof(const CTLogVerifier& log,
size_t leaf,
size_t tree_size,
const std::vector<std::string>& proof,
const std::string& root_hash,
const std::string& leaf_hash) { … }
void CheckVerifyConsistencyProof(const CTLogVerifier& log,
int old_tree_size,
int new_tree_size,
const std::string& old_root,
const std::string& new_root,
const std::vector<std::string>& proof) { … }
TEST_F(CTLogVerifierTest, VerifiesCertSCT) { … }
TEST_F(CTLogVerifierTest, VerifiesPrecertSCT) { … }
TEST_F(CTLogVerifierTest, FailsInvalidTimestamp) { … }
TEST_F(CTLogVerifierTest, FailsInvalidLogID) { … }
TEST_F(CTLogVerifierTest, VerifiesValidSTH) { … }
TEST_F(CTLogVerifierTest, DoesNotVerifyInvalidSTH) { … }
TEST_F(CTLogVerifierTest, VerifiesValidEmptySTH) { … }
TEST_F(CTLogVerifierTest, DoesNotVerifyInvalidEmptySTH) { … }
TEST_F(CTLogVerifierTest, ExcessDataInPublicKey) { … }
TEST_F(CTLogVerifierTest, VerifiesConsistencyProofEdgeCases_EmptyProof) { … }
TEST_F(CTLogVerifierTest, VerifiesConsistencyProofEdgeCases_MismatchingRoots) { … }
TEST_F(CTLogVerifierTest,
VerifiesConsistencyProofEdgeCases_MatchingRootsNonEmptyProof) { … }
class CTLogVerifierConsistencyProofTest
: public CTLogVerifierTest,
public ::testing::WithParamInterface<size_t > { … };
TEST_P(CTLogVerifierConsistencyProofTest, VerifiesValidConsistencyProof) { … }
INSTANTIATE_TEST_SUITE_P(…);
class CTLogVerifierAuditProofTest
: public CTLogVerifierTest,
public ::testing::WithParamInterface<size_t > { … };
TEST_P(CTLogVerifierAuditProofTest, VerifiesValidAuditProofs) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(CTLogVerifierTest, VerifiesAuditProofEdgeCases_InvalidLeafIndex) { … }
namespace rfc6962 {
std::string HashLeaf(const std::string& leaf) { … }
std::string HashTree(std::string leaves[], size_t tree_size) { … }
std::vector<std::string> CreateAuditProof(std::string leaves[],
size_t tree_size,
size_t leaf_index) { … }
std::vector<std::string> CreateConsistencyProof(std::string leaves[],
size_t new_tree_size,
size_t old_tree_size,
bool contains_old_tree = true) { … }
}
class CTLogVerifierTestUsingGenerator
: public CTLogVerifierTest,
public ::testing::WithParamInterface<size_t > { … };
TEST_P(CTLogVerifierTestUsingGenerator, VerifiesValidConsistencyProof) { … }
TEST_P(CTLogVerifierTestUsingGenerator, VerifiesValidAuditProofs) { … }
INSTANTIATE_TEST_SUITE_P(…);
}
}