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