| 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/quic/test_tools/crypto_test_utils.h" | 5 #include "net/quic/test_tools/crypto_test_utils.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "net/base/net_errors.h" |
| 9 #include "net/base/test_data_directory.h" | 10 #include "net/base/test_data_directory.h" |
| 10 #include "net/cert/cert_verifier.h" | 11 #include "net/cert/cert_verifier.h" |
| 12 #include "net/cert/mock_cert_verifier.h" |
| 11 #include "net/cert/test_root_certs.h" | 13 #include "net/cert/test_root_certs.h" |
| 12 #include "net/cert/x509_certificate.h" | 14 #include "net/cert/x509_certificate.h" |
| 13 #include "net/http/transport_security_state.h" | 15 #include "net/http/transport_security_state.h" |
| 14 #include "net/quic/crypto/proof_source_chromium.h" | 16 #include "net/quic/crypto/proof_source_chromium.h" |
| 15 #include "net/quic/crypto/proof_verifier_chromium.h" | 17 #include "net/quic/crypto/proof_verifier_chromium.h" |
| 16 #include "net/test/cert_test_util.h" | 18 #include "net/test/cert_test_util.h" |
| 17 | 19 |
| 18 namespace net { | 20 namespace net { |
| 19 | 21 |
| 20 namespace test { | 22 namespace test { |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 class TestProofVerifierChromium : public ProofVerifierChromium { | 26 class TestProofVerifierChromium : public ProofVerifierChromium { |
| 25 public: | 27 public: |
| 28 // TODO(rch): |transport_security_state| should be a scoped_ptr. |
| 26 TestProofVerifierChromium(CertVerifier* cert_verifier, | 29 TestProofVerifierChromium(CertVerifier* cert_verifier, |
| 27 TransportSecurityState* transport_security_state, | 30 TransportSecurityState* transport_security_state, |
| 28 const std::string& cert_file) | 31 const std::string& cert_file) |
| 29 : ProofVerifierChromium(cert_verifier, nullptr, transport_security_state), | 32 : ProofVerifierChromium(cert_verifier, nullptr, transport_security_state), |
| 30 cert_verifier_(cert_verifier), | 33 cert_verifier_(cert_verifier), |
| 31 transport_security_state_(transport_security_state) { | 34 transport_security_state_(transport_security_state) { |
| 32 // Load and install the root for the validated chain. | 35 // Load and install the root for the validated chain. |
| 33 scoped_refptr<X509Certificate> root_cert = | 36 scoped_refptr<X509Certificate> root_cert = |
| 34 ImportCertFromFile(GetTestCertsDirectory(), cert_file); | 37 ImportCertFromFile(GetTestCertsDirectory(), cert_file); |
| 35 scoped_root_.Reset(root_cert.get()); | 38 scoped_root_.Reset(root_cert.get()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 104 } |
| 102 | 105 |
| 103 private: | 106 private: |
| 104 DISALLOW_COPY_AND_ASSIGN(FakeProofVerifier); | 107 DISALLOW_COPY_AND_ASSIGN(FakeProofVerifier); |
| 105 }; | 108 }; |
| 106 | 109 |
| 107 } // namespace | 110 } // namespace |
| 108 | 111 |
| 109 // static | 112 // static |
| 110 ProofSource* CryptoTestUtils::ProofSourceForTesting() { | 113 ProofSource* CryptoTestUtils::ProofSourceForTesting() { |
| 111 return new ProofSourceChromium(); | 114 ProofSourceChromium* source = new ProofSourceChromium(); |
| 115 base::FilePath certs_dir = GetTestCertsDirectory(); |
| 116 CHECK(source->Initialize( |
| 117 certs_dir.AppendASCII("quic_chain.crt"), |
| 118 certs_dir.AppendASCII("quic_test.example.com.key.pkcs8"))); |
| 119 return source; |
| 112 } | 120 } |
| 113 | 121 |
| 114 // static | 122 // static |
| 115 ProofVerifier* CryptoTestUtils::ProofVerifierForTesting() { | 123 ProofVerifier* CryptoTestUtils::ProofVerifierForTesting() { |
| 116 TestProofVerifierChromium* proof_verifier = new TestProofVerifierChromium( | 124 // TODO(rch): use a real cert verifier? |
| 117 CertVerifier::CreateDefault(), new TransportSecurityState, | 125 MockCertVerifier* cert_verifier = new MockCertVerifier(); |
| 118 "quic_root.crt"); | 126 net::CertVerifyResult verify_result; |
| 119 return proof_verifier; | 127 verify_result.verified_cert = |
| 128 ImportCertFromFile(GetTestCertsDirectory(), "quic_test.example.com.crt"); |
| 129 cert_verifier->AddResultForCertAndHost(verify_result.verified_cert.get(), |
| 130 "test.example.com", verify_result, OK); |
| 131 verify_result.verified_cert = ImportCertFromFile( |
| 132 GetTestCertsDirectory(), "quic_test_ecc.example.com.crt"); |
| 133 cert_verifier->AddResultForCertAndHost(verify_result.verified_cert.get(), |
| 134 "test.example.com", verify_result, OK); |
| 135 return new TestProofVerifierChromium( |
| 136 cert_verifier, new TransportSecurityState, "quic_root.crt"); |
| 120 } | 137 } |
| 121 | 138 |
| 122 // static | 139 // static |
| 123 ProofVerifyContext* CryptoTestUtils::ProofVerifyContextForTesting() { | 140 ProofVerifyContext* CryptoTestUtils::ProofVerifyContextForTesting() { |
| 124 return new ProofVerifyContextChromium(/*cert_verify_flags=*/0, BoundNetLog()); | 141 return new ProofVerifyContextChromium(/*cert_verify_flags=*/0, BoundNetLog()); |
| 125 } | 142 } |
| 126 | 143 |
| 127 // static | 144 // static |
| 128 ProofSource* CryptoTestUtils::FakeProofSourceForTesting() { | 145 ProofSource* CryptoTestUtils::FakeProofSourceForTesting() { |
| 129 return new FakeProofSource(); | 146 return new FakeProofSource(); |
| 130 } | 147 } |
| 131 | 148 |
| 132 // static | 149 // static |
| 133 ProofVerifier* CryptoTestUtils::FakeProofVerifierForTesting() { | 150 ProofVerifier* CryptoTestUtils::FakeProofVerifierForTesting() { |
| 134 return new FakeProofVerifier(); | 151 return new FakeProofVerifier(); |
| 135 } | 152 } |
| 136 | 153 |
| 137 // static | 154 // static |
| 138 ProofVerifyContext* CryptoTestUtils::FakeProofVerifyContextForTesting() { | 155 ProofVerifyContext* CryptoTestUtils::FakeProofVerifyContextForTesting() { |
| 139 return nullptr; | 156 return nullptr; |
| 140 } | 157 } |
| 141 | 158 |
| 142 } // namespace test | 159 } // namespace test |
| 143 | 160 |
| 144 } // namespace net | 161 } // namespace net |
| OLD | NEW |