| Index: net/quic/crypto/proof_verifier_chromium_test.cc
|
| diff --git a/net/quic/crypto/proof_verifier_chromium_test.cc b/net/quic/crypto/proof_verifier_chromium_test.cc
|
| index 9a7f0db86ff96bae69ab8436dc63e32781f70b0f..63ce6cfc5eea90b06404f0b8526fa66e4e0ce888 100644
|
| --- a/net/quic/crypto/proof_verifier_chromium_test.cc
|
| +++ b/net/quic/crypto/proof_verifier_chromium_test.cc
|
| @@ -91,107 +91,108 @@ class DummyProofVerifierCallback : public ProofVerifierCallback {
|
| }
|
| };
|
|
|
| -scoped_refptr<X509Certificate> GetTestServerCertificate() {
|
| - static const char kTestCert[] = "quic_test.example.com.crt";
|
| - return ImportCertFromFile(GetTestCertsDirectory(), kTestCert);
|
| -}
|
| +const char kTestHostname[] = "test.example.com";
|
| +const char kTestConfig[] = "server config bytes";
|
|
|
| -void GetTestCertificates(std::vector<std::string>* certs) {
|
| - scoped_refptr<X509Certificate> cert = GetTestServerCertificate();
|
| - ASSERT_TRUE(cert);
|
| +} // namespace
|
|
|
| - std::string der_bytes;
|
| - ASSERT_TRUE(
|
| - X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_bytes));
|
| +class ProofVerifierChromiumTest : public ::testing::Test {
|
| + public:
|
| + ProofVerifierChromiumTest()
|
| + : verify_context_(new ProofVerifyContextChromium(0 /*cert_verify_flags*/,
|
| + BoundNetLog())) {}
|
|
|
| - certs->clear();
|
| - certs->push_back(der_bytes);
|
| -}
|
| + void SetUp() override {
|
| + ASSERT_NO_FATAL_FAILURE(GetTestCertificates(&certs_));
|
| + }
|
|
|
| -std::string GetTestSignature() {
|
| - // Sample known answer test from ProofTest.VerifyRSAKnownAnswerTest.
|
| - // Generated by dumping the bytes of the |signature| output of
|
| - // ProofSource::GetProof().
|
| - static const unsigned char kTestSignature[] = {
|
| - 0x31, 0xd5, 0xfb, 0x40, 0x30, 0x75, 0xd2, 0x7d, 0x61, 0xf9, 0xd7, 0x54,
|
| - 0x30, 0x06, 0xaf, 0x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 0x01, 0xff, 0xeb, 0x8a,
|
| - 0xb9, 0xe2, 0x34, 0xa5, 0xa0, 0x51, 0xe9, 0xbe, 0x15, 0x12, 0xbf, 0xbe,
|
| - 0x64, 0x3d, 0x3f, 0x98, 0xce, 0xc1, 0xa6, 0x33, 0x32, 0xd3, 0x5c, 0xa8,
|
| - 0x39, 0x93, 0xdc, 0x1c, 0xb9, 0xab, 0x3c, 0x80, 0x62, 0xb3, 0x76, 0x21,
|
| - 0xdf, 0x47, 0x1e, 0xa9, 0x0e, 0x5e, 0x8a, 0xbe, 0x66, 0x5b, 0x7c, 0x21,
|
| - 0xfa, 0x78, 0x2d, 0xd1, 0x1d, 0x5c, 0x35, 0x8a, 0x34, 0xb2, 0x1a, 0xc2,
|
| - 0xc4, 0x4b, 0x53, 0x54,
|
| - };
|
| - return std::string(reinterpret_cast<const char*>(kTestSignature),
|
| - sizeof(kTestSignature));
|
| -}
|
| + scoped_refptr<X509Certificate> GetTestServerCertificate() {
|
| + static const char kTestCert[] = "quic_test.example.com.crt";
|
| + return ImportCertFromFile(GetTestCertsDirectory(), kTestCert);
|
| + }
|
|
|
| -const char kTestHostname[] = "test.example.com";
|
| -const char kTestConfig[] = "server config bytes";
|
| + void GetTestCertificates(std::vector<std::string>* certs) {
|
| + scoped_refptr<X509Certificate> cert = GetTestServerCertificate();
|
| + ASSERT_TRUE(cert);
|
|
|
| -} // namespace
|
| + std::string der_bytes;
|
| + ASSERT_TRUE(
|
| + X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_bytes));
|
| +
|
| + certs->clear();
|
| + certs->push_back(der_bytes);
|
| + }
|
| +
|
| + std::string GetTestSignature() {
|
| + // Sample known answer test from ProofTest.VerifyRSAKnownAnswerTest.
|
| + // Generated by dumping the bytes of the |signature| output of
|
| + // ProofSource::GetProof().
|
| + static const unsigned char kTestSignature[] = {
|
| + 0x31, 0xd5, 0xfb, 0x40, 0x30, 0x75, 0xd2, 0x7d, 0x61, 0xf9, 0xd7, 0x54,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 0xb9, 0x9a, 0xe0, 0xd7, 0x01, 0xff, 0xeb, 0x8a,
|
| + 0xb9, 0xe2, 0x34, 0xa5, 0xa0, 0x51, 0xe9, 0xbe, 0x15, 0x12, 0xbf, 0xbe,
|
| + 0x64, 0x3d, 0x3f, 0x98, 0xce, 0xc1, 0xa6, 0x33, 0x32, 0xd3, 0x5c, 0xa8,
|
| + 0x39, 0x93, 0xdc, 0x1c, 0xb9, 0xab, 0x3c, 0x80, 0x62, 0xb3, 0x76, 0x21,
|
| + 0xdf, 0x47, 0x1e, 0xa9, 0x0e, 0x5e, 0x8a, 0xbe, 0x66, 0x5b, 0x7c, 0x21,
|
| + 0xfa, 0x78, 0x2d, 0xd1, 0x1d, 0x5c, 0x35, 0x8a, 0x34, 0xb2, 0x1a, 0xc2,
|
| + 0xc4, 0x4b, 0x53, 0x54,
|
| + };
|
| + return std::string(reinterpret_cast<const char*>(kTestSignature),
|
| + sizeof(kTestSignature));
|
| + }
|
| +
|
| + protected:
|
| + scoped_ptr<ProofVerifyContext> verify_context_;
|
| + scoped_ptr<ProofVerifyDetails> details_;
|
| + std::string error_details_;
|
| + std::vector<std::string> certs_;
|
| +};
|
|
|
| // Tests that the ProofVerifier fails verification if certificate
|
| // verification fails.
|
| -TEST(ProofVerifierChromiumTest, FailsIfCertFails) {
|
| +TEST_F(ProofVerifierChromiumTest, FailsIfCertFails) {
|
| MockCertVerifier dummy_verifier;
|
| ProofVerifierChromium proof_verifier(&dummy_verifier, nullptr, nullptr);
|
|
|
| - scoped_ptr<ProofVerifyContext> verify_context(
|
| - new ProofVerifyContextChromium(0 /*cert_verify_flags*/, BoundNetLog()));
|
| - scoped_ptr<ProofVerifyDetails> details;
|
| - std::string error_details;
|
| -
|
| - std::vector<std::string> certs;
|
| - ASSERT_NO_FATAL_FAILURE(GetTestCertificates(&certs));
|
| -
|
| DummyProofVerifierCallback* callback = new DummyProofVerifierCallback;
|
| QuicAsyncStatus status = proof_verifier.VerifyProof(
|
| - kTestHostname, kTestConfig, certs, "", GetTestSignature(),
|
| - verify_context.get(), &error_details, &details, callback);
|
| + kTestHostname, kTestConfig, certs_, "", GetTestSignature(),
|
| + verify_context_.get(), &error_details_, &details_, callback);
|
| ASSERT_EQ(QUIC_FAILURE, status);
|
| delete callback;
|
| }
|
|
|
| // Tests that the ProofVerifier doesn't verify certificates if the config
|
| // signature fails.
|
| -TEST(ProofVerifierChromiumTest, FailsIfSignatureFails) {
|
| +TEST_F(ProofVerifierChromiumTest, FailsIfSignatureFails) {
|
| FailsTestCertVerifier cert_verifier;
|
| ProofVerifierChromium proof_verifier(&cert_verifier, nullptr, nullptr);
|
|
|
| - scoped_ptr<ProofVerifyContext> verify_context(
|
| - new ProofVerifyContextChromium(0 /*cert_verify_flags*/, BoundNetLog()));
|
| - scoped_ptr<ProofVerifyDetails> details;
|
| - std::string error_details;
|
| -
|
| - std::vector<std::string> certs;
|
| - ASSERT_NO_FATAL_FAILURE(GetTestCertificates(&certs));
|
| -
|
| DummyProofVerifierCallback* callback = new DummyProofVerifierCallback;
|
| QuicAsyncStatus status = proof_verifier.VerifyProof(
|
| - kTestHostname, kTestConfig, certs, "", kTestConfig, verify_context.get(),
|
| - &error_details, &details, callback);
|
| + kTestHostname, kTestConfig, certs_, "", kTestConfig,
|
| + verify_context_.get(), &error_details_, &details_, callback);
|
| ASSERT_EQ(QUIC_FAILURE, status);
|
| delete callback;
|
| }
|
|
|
| // Tests that EV certificates are left as EV if there is no certificate
|
| // policy enforcement.
|
| -TEST(ProofVerifierChromiumTest, PreservesEVIfNoPolicy) {
|
| +TEST_F(ProofVerifierChromiumTest, PreservesEVIfNoPolicy) {
|
| scoped_refptr<X509Certificate> test_cert = GetTestServerCertificate();
|
| ASSERT_TRUE(test_cert);
|
|
|
| @@ -204,31 +205,23 @@ TEST(ProofVerifierChromiumTest, PreservesEVIfNoPolicy) {
|
|
|
| ProofVerifierChromium proof_verifier(&dummy_verifier, nullptr, nullptr);
|
|
|
| - scoped_ptr<ProofVerifyContext> verify_context(
|
| - new ProofVerifyContextChromium(0 /*cert_verify_flags*/, BoundNetLog()));
|
| - scoped_ptr<ProofVerifyDetails> details;
|
| - std::string error_details;
|
| -
|
| - std::vector<std::string> certs;
|
| - ASSERT_NO_FATAL_FAILURE(GetTestCertificates(&certs));
|
| -
|
| DummyProofVerifierCallback* callback = new DummyProofVerifierCallback;
|
| QuicAsyncStatus status = proof_verifier.VerifyProof(
|
| - kTestHostname, kTestConfig, certs, "", GetTestSignature(),
|
| - verify_context.get(), &error_details, &details, callback);
|
| + kTestHostname, kTestConfig, certs_, "", GetTestSignature(),
|
| + verify_context_.get(), &error_details_, &details_, callback);
|
| ASSERT_EQ(QUIC_SUCCESS, status);
|
| delete callback;
|
|
|
| - ASSERT_TRUE(details.get());
|
| + ASSERT_TRUE(details_.get());
|
| ProofVerifyDetailsChromium* verify_details =
|
| - static_cast<ProofVerifyDetailsChromium*>(details.get());
|
| + static_cast<ProofVerifyDetailsChromium*>(details_.get());
|
| EXPECT_EQ(dummy_result.cert_status,
|
| verify_details->cert_verify_result.cert_status);
|
| }
|
|
|
| // Tests that the certificate policy enforcer is consulted for EV
|
| // and the certificate is allowed to be EV.
|
| -TEST(ProofVerifierChromiumTest, PreservesEVIfAllowed) {
|
| +TEST_F(ProofVerifierChromiumTest, PreservesEVIfAllowed) {
|
| scoped_refptr<X509Certificate> test_cert = GetTestServerCertificate();
|
| ASSERT_TRUE(test_cert);
|
|
|
| @@ -244,31 +237,23 @@ TEST(ProofVerifierChromiumTest, PreservesEVIfAllowed) {
|
| ProofVerifierChromium proof_verifier(&dummy_verifier, &policy_enforcer,
|
| nullptr);
|
|
|
| - scoped_ptr<ProofVerifyContext> verify_context(
|
| - new ProofVerifyContextChromium(0 /*cert_verify_flags*/, BoundNetLog()));
|
| - scoped_ptr<ProofVerifyDetails> details;
|
| - std::string error_details;
|
| -
|
| - std::vector<std::string> certs;
|
| - ASSERT_NO_FATAL_FAILURE(GetTestCertificates(&certs));
|
| -
|
| DummyProofVerifierCallback* callback = new DummyProofVerifierCallback;
|
| QuicAsyncStatus status = proof_verifier.VerifyProof(
|
| - kTestHostname, kTestConfig, certs, "", GetTestSignature(),
|
| - verify_context.get(), &error_details, &details, callback);
|
| + kTestHostname, kTestConfig, certs_, "", GetTestSignature(),
|
| + verify_context_.get(), &error_details_, &details_, callback);
|
| ASSERT_EQ(QUIC_SUCCESS, status);
|
| delete callback;
|
|
|
| - ASSERT_TRUE(details.get());
|
| + ASSERT_TRUE(details_.get());
|
| ProofVerifyDetailsChromium* verify_details =
|
| - static_cast<ProofVerifyDetailsChromium*>(details.get());
|
| + static_cast<ProofVerifyDetailsChromium*>(details_.get());
|
| EXPECT_EQ(dummy_result.cert_status,
|
| verify_details->cert_verify_result.cert_status);
|
| }
|
|
|
| // Tests that the certificate policy enforcer is consulted for EV
|
| // and the certificate is not allowed to be EV.
|
| -TEST(ProofVerifierChromiumTest, StripsEVIfNotAllowed) {
|
| +TEST_F(ProofVerifierChromiumTest, StripsEVIfNotAllowed) {
|
| scoped_refptr<X509Certificate> test_cert = GetTestServerCertificate();
|
| ASSERT_TRUE(test_cert);
|
|
|
| @@ -284,24 +269,16 @@ TEST(ProofVerifierChromiumTest, StripsEVIfNotAllowed) {
|
| ProofVerifierChromium proof_verifier(&dummy_verifier, &policy_enforcer,
|
| nullptr);
|
|
|
| - scoped_ptr<ProofVerifyContext> verify_context(
|
| - new ProofVerifyContextChromium(0 /*cert_verify_flags*/, BoundNetLog()));
|
| - scoped_ptr<ProofVerifyDetails> details;
|
| - std::string error_details;
|
| -
|
| - std::vector<std::string> certs;
|
| - ASSERT_NO_FATAL_FAILURE(GetTestCertificates(&certs));
|
| -
|
| DummyProofVerifierCallback* callback = new DummyProofVerifierCallback;
|
| QuicAsyncStatus status = proof_verifier.VerifyProof(
|
| - kTestHostname, kTestConfig, certs, "", GetTestSignature(),
|
| - verify_context.get(), &error_details, &details, callback);
|
| + kTestHostname, kTestConfig, certs_, "", GetTestSignature(),
|
| + verify_context_.get(), &error_details_, &details_, callback);
|
| ASSERT_EQ(QUIC_SUCCESS, status);
|
| delete callback;
|
|
|
| - ASSERT_TRUE(details.get());
|
| + ASSERT_TRUE(details_.get());
|
| ProofVerifyDetailsChromium* verify_details =
|
| - static_cast<ProofVerifyDetailsChromium*>(details.get());
|
| + static_cast<ProofVerifyDetailsChromium*>(details_.get());
|
| EXPECT_EQ(CERT_STATUS_CT_COMPLIANCE_FAILED,
|
| verify_details->cert_verify_result.cert_status &
|
| (CERT_STATUS_CT_COMPLIANCE_FAILED | CERT_STATUS_IS_EV));
|
| @@ -309,7 +286,7 @@ TEST(ProofVerifierChromiumTest, StripsEVIfNotAllowed) {
|
|
|
| // Tests that the certificate policy enforcer is not consulted if
|
| // the certificate is not EV.
|
| -TEST(ProofVerifierChromiumTest, IgnoresPolicyEnforcerIfNotEV) {
|
| +TEST_F(ProofVerifierChromiumTest, IgnoresPolicyEnforcerIfNotEV) {
|
| scoped_refptr<X509Certificate> test_cert = GetTestServerCertificate();
|
| ASSERT_TRUE(test_cert);
|
|
|
| @@ -325,24 +302,16 @@ TEST(ProofVerifierChromiumTest, IgnoresPolicyEnforcerIfNotEV) {
|
| ProofVerifierChromium proof_verifier(&dummy_verifier, &policy_enforcer,
|
| nullptr);
|
|
|
| - scoped_ptr<ProofVerifyContext> verify_context(
|
| - new ProofVerifyContextChromium(0 /*cert_verify_flags*/, BoundNetLog()));
|
| - scoped_ptr<ProofVerifyDetails> details;
|
| - std::string error_details;
|
| -
|
| - std::vector<std::string> certs;
|
| - ASSERT_NO_FATAL_FAILURE(GetTestCertificates(&certs));
|
| -
|
| DummyProofVerifierCallback* callback = new DummyProofVerifierCallback;
|
| QuicAsyncStatus status = proof_verifier.VerifyProof(
|
| - kTestHostname, kTestConfig, certs, "", GetTestSignature(),
|
| - verify_context.get(), &error_details, &details, callback);
|
| + kTestHostname, kTestConfig, certs_, "", GetTestSignature(),
|
| + verify_context_.get(), &error_details_, &details_, callback);
|
| ASSERT_EQ(QUIC_SUCCESS, status);
|
| delete callback;
|
|
|
| - ASSERT_TRUE(details.get());
|
| + ASSERT_TRUE(details_.get());
|
| ProofVerifyDetailsChromium* verify_details =
|
| - static_cast<ProofVerifyDetailsChromium*>(details.get());
|
| + static_cast<ProofVerifyDetailsChromium*>(details_.get());
|
| EXPECT_EQ(0u, verify_details->cert_verify_result.cert_status);
|
| }
|
|
|
|
|