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/test_data_directory.h" | 9 #include "net/base/test_data_directory.h" |
10 #include "net/cert/cert_verifier.h" | 10 #include "net/cert/cert_verifier.h" |
11 #include "net/cert/test_root_certs.h" | 11 #include "net/cert/test_root_certs.h" |
12 #include "net/cert/x509_certificate.h" | 12 #include "net/cert/x509_certificate.h" |
13 #include "net/quic/crypto/proof_source_chromium.h" | 13 #include "net/quic/crypto/proof_source_chromium.h" |
14 #include "net/quic/crypto/proof_verifier_chromium.h" | 14 #include "net/quic/crypto/proof_verifier_chromium.h" |
15 #include "net/test/cert_test_util.h" | 15 #include "net/test/cert_test_util.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 namespace test { | 19 namespace test { |
20 | 20 |
21 namespace { | |
22 | |
21 class TestProofVerifierChromium : public ProofVerifierChromium { | 23 class TestProofVerifierChromium : public ProofVerifierChromium { |
22 public: | 24 public: |
23 TestProofVerifierChromium(CertVerifier* cert_verifier, | 25 TestProofVerifierChromium(CertVerifier* cert_verifier, |
24 const std::string& cert_file) | 26 const std::string& cert_file) |
25 : ProofVerifierChromium(cert_verifier), | 27 : ProofVerifierChromium(cert_verifier), |
26 cert_verifier_(cert_verifier) { | 28 cert_verifier_(cert_verifier) { |
27 // Load and install the root for the validated chain. | 29 // Load and install the root for the validated chain. |
28 scoped_refptr<X509Certificate> root_cert = | 30 scoped_refptr<X509Certificate> root_cert = |
29 ImportCertFromFile(GetTestCertsDirectory(), cert_file); | 31 ImportCertFromFile(GetTestCertsDirectory(), cert_file); |
30 scoped_root_.Reset(root_cert.get()); | 32 scoped_root_.Reset(root_cert.get()); |
31 } | 33 } |
32 virtual ~TestProofVerifierChromium() {} | 34 virtual ~TestProofVerifierChromium() {} |
33 | 35 |
34 private: | 36 private: |
35 ScopedTestRoot scoped_root_; | 37 ScopedTestRoot scoped_root_; |
36 scoped_ptr<CertVerifier> cert_verifier_; | 38 scoped_ptr<CertVerifier> cert_verifier_; |
37 }; | 39 }; |
38 | 40 |
41 const char kLeafCert[] = "leaf"; | |
42 const char kIntermediateCert[] = "intermediate"; | |
43 const char kSignature[] = "signature"; | |
44 | |
45 class MockProofSource : public ProofSource { | |
Ryan Hamilton
2014/06/25 18:55:15
Consider naming these classes "TestFoo" instead of
wtc
2014/06/28 16:03:30
There are many MockFoo classes in src/net that don
Ryan Hamilton
2014/06/30 17:47:03
Fixed sounds great to me!
wtc
2014/06/30 19:35:14
I decided to use "Fake".
| |
46 public: | |
47 MockProofSource() : certs_(2) { | |
48 certs_[0] = kLeafCert; | |
49 certs_[1] = kIntermediateCert; | |
50 } | |
51 virtual ~MockProofSource() {} | |
52 | |
53 // ProofSource interface | |
54 virtual bool GetProof(const std::string& hostname, | |
55 const std::string& server_config, | |
56 bool ecdsa_ok, | |
57 const std::vector<std::string>** out_certs, | |
58 std::string* out_signature) OVERRIDE { | |
59 *out_certs = &certs_; | |
60 *out_signature = kSignature; | |
61 return true; | |
62 } | |
63 | |
64 private: | |
65 std::vector<std::string> certs_; | |
66 DISALLOW_COPY_AND_ASSIGN(MockProofSource); | |
67 }; | |
68 | |
69 class MockProofVerifier : public ProofVerifier { | |
70 public: | |
71 MockProofVerifier() {} | |
72 virtual ~MockProofVerifier() {} | |
73 | |
74 // ProofVerifier interface | |
75 virtual QuicAsyncStatus VerifyProof( | |
76 const std::string& hostname, | |
77 const std::string& server_config, | |
78 const std::vector<std::string>& certs, | |
79 const std::string& signature, | |
80 const ProofVerifyContext* verify_context, | |
81 std::string* error_details, | |
82 scoped_ptr<ProofVerifyDetails>* verify_details, | |
83 ProofVerifierCallback* callback) OVERRIDE { | |
84 error_details->clear(); | |
85 scoped_ptr<ProofVerifyDetailsChromium> verify_details_chromium( | |
86 new ProofVerifyDetailsChromium); | |
87 if (certs.size() != 2 || certs[0] != kLeafCert || | |
88 certs[1] != kIntermediateCert || signature != kSignature) { | |
89 *error_details = "Invalid proof"; | |
90 verify_details_chromium->cert_verify_result.cert_status = | |
91 CERT_STATUS_INVALID; | |
92 *verify_details = verify_details_chromium.Pass(); | |
93 return QUIC_FAILURE; | |
94 } | |
95 *verify_details = verify_details_chromium.Pass(); | |
96 return QUIC_SUCCESS; | |
97 } | |
98 | |
99 private: | |
100 DISALLOW_COPY_AND_ASSIGN(MockProofVerifier); | |
101 }; | |
102 | |
103 } // namespace | |
104 | |
39 // static | 105 // static |
40 ProofSource* CryptoTestUtils::ProofSourceForTesting() { | 106 ProofSource* CryptoTestUtils::ProofSourceForTesting() { |
41 return new ProofSourceChromium(); | 107 return new ProofSourceChromium(); |
42 } | 108 } |
43 | 109 |
44 // static | 110 // static |
45 ProofVerifier* CryptoTestUtils::ProofVerifierForTesting() { | 111 ProofVerifier* CryptoTestUtils::ProofVerifierForTesting() { |
46 TestProofVerifierChromium* proof_verifier = new TestProofVerifierChromium( | 112 TestProofVerifierChromium* proof_verifier = new TestProofVerifierChromium( |
47 CertVerifier::CreateDefault(), "quic_root.crt"); | 113 CertVerifier::CreateDefault(), "quic_root.crt"); |
48 return proof_verifier; | 114 return proof_verifier; |
49 } | 115 } |
50 | 116 |
51 // static | 117 // static |
52 ProofVerifyContext* CryptoTestUtils::ProofVerifyContextForTesting() { | 118 ProofVerifyContext* CryptoTestUtils::ProofVerifyContextForTesting() { |
53 return new ProofVerifyContextChromium(BoundNetLog()); | 119 return new ProofVerifyContextChromium(BoundNetLog()); |
54 } | 120 } |
55 | 121 |
122 // static | |
123 ProofSource* CryptoTestUtils::MockProofSourceForTesting() { | |
124 return new MockProofSource(); | |
125 } | |
126 | |
127 // static | |
128 ProofVerifier* CryptoTestUtils::MockProofVerifierForTesting() { | |
129 return new MockProofVerifier(); | |
130 } | |
131 | |
132 // static | |
133 ProofVerifyContext* CryptoTestUtils::MockProofVerifyContextForTesting() { | |
134 return NULL; | |
135 } | |
136 | |
56 } // namespace test | 137 } // namespace test |
57 | 138 |
58 } // namespace net | 139 } // namespace net |
OLD | NEW |