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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 TransportSecurityState* transport_security_state, | 27 TransportSecurityState* transport_security_state, |
28 const std::string& cert_file) | 28 const std::string& cert_file) |
29 : ProofVerifierChromium(cert_verifier, transport_security_state), | 29 : ProofVerifierChromium(cert_verifier, transport_security_state), |
30 cert_verifier_(cert_verifier), | 30 cert_verifier_(cert_verifier), |
31 transport_security_state_(transport_security_state) { | 31 transport_security_state_(transport_security_state) { |
32 // Load and install the root for the validated chain. | 32 // Load and install the root for the validated chain. |
33 scoped_refptr<X509Certificate> root_cert = | 33 scoped_refptr<X509Certificate> root_cert = |
34 ImportCertFromFile(GetTestCertsDirectory(), cert_file); | 34 ImportCertFromFile(GetTestCertsDirectory(), cert_file); |
35 scoped_root_.Reset(root_cert.get()); | 35 scoped_root_.Reset(root_cert.get()); |
36 } | 36 } |
37 virtual ~TestProofVerifierChromium() {} | 37 ~TestProofVerifierChromium() override {} |
38 | 38 |
39 private: | 39 private: |
40 ScopedTestRoot scoped_root_; | 40 ScopedTestRoot scoped_root_; |
41 scoped_ptr<CertVerifier> cert_verifier_; | 41 scoped_ptr<CertVerifier> cert_verifier_; |
42 scoped_ptr<TransportSecurityState> transport_security_state_; | 42 scoped_ptr<TransportSecurityState> transport_security_state_; |
43 }; | 43 }; |
44 | 44 |
45 const char kLeafCert[] = "leaf"; | 45 const char kLeafCert[] = "leaf"; |
46 const char kIntermediateCert[] = "intermediate"; | 46 const char kIntermediateCert[] = "intermediate"; |
47 const char kSignature[] = "signature"; | 47 const char kSignature[] = "signature"; |
48 | 48 |
49 class FakeProofSource : public ProofSource { | 49 class FakeProofSource : public ProofSource { |
50 public: | 50 public: |
51 FakeProofSource() : certs_(2) { | 51 FakeProofSource() : certs_(2) { |
52 certs_[0] = kLeafCert; | 52 certs_[0] = kLeafCert; |
53 certs_[1] = kIntermediateCert; | 53 certs_[1] = kIntermediateCert; |
54 } | 54 } |
55 virtual ~FakeProofSource() {} | 55 ~FakeProofSource() override {} |
56 | 56 |
57 // ProofSource interface | 57 // ProofSource interface |
58 virtual bool GetProof(const std::string& hostname, | 58 bool GetProof(const std::string& hostname, |
59 const std::string& server_config, | 59 const std::string& server_config, |
60 bool ecdsa_ok, | 60 bool ecdsa_ok, |
61 const std::vector<std::string>** out_certs, | 61 const std::vector<std::string>** out_certs, |
62 std::string* out_signature) override { | 62 std::string* out_signature) override { |
63 *out_certs = &certs_; | 63 *out_certs = &certs_; |
64 *out_signature = kSignature; | 64 *out_signature = kSignature; |
65 return true; | 65 return true; |
66 } | 66 } |
67 | 67 |
68 private: | 68 private: |
69 std::vector<std::string> certs_; | 69 std::vector<std::string> certs_; |
70 DISALLOW_COPY_AND_ASSIGN(FakeProofSource); | 70 DISALLOW_COPY_AND_ASSIGN(FakeProofSource); |
71 }; | 71 }; |
72 | 72 |
73 class FakeProofVerifier : public ProofVerifier { | 73 class FakeProofVerifier : public ProofVerifier { |
74 public: | 74 public: |
75 FakeProofVerifier() {} | 75 FakeProofVerifier() {} |
76 virtual ~FakeProofVerifier() {} | 76 ~FakeProofVerifier() override {} |
77 | 77 |
78 // ProofVerifier interface | 78 // ProofVerifier interface |
79 virtual QuicAsyncStatus VerifyProof( | 79 QuicAsyncStatus VerifyProof(const std::string& hostname, |
80 const std::string& hostname, | 80 const std::string& server_config, |
81 const std::string& server_config, | 81 const std::vector<std::string>& certs, |
82 const std::vector<std::string>& certs, | 82 const std::string& signature, |
83 const std::string& signature, | 83 const ProofVerifyContext* verify_context, |
84 const ProofVerifyContext* verify_context, | 84 std::string* error_details, |
85 std::string* error_details, | 85 scoped_ptr<ProofVerifyDetails>* verify_details, |
86 scoped_ptr<ProofVerifyDetails>* verify_details, | 86 ProofVerifierCallback* callback) override { |
87 ProofVerifierCallback* callback) override { | |
88 error_details->clear(); | 87 error_details->clear(); |
89 scoped_ptr<ProofVerifyDetailsChromium> verify_details_chromium( | 88 scoped_ptr<ProofVerifyDetailsChromium> verify_details_chromium( |
90 new ProofVerifyDetailsChromium); | 89 new ProofVerifyDetailsChromium); |
91 if (certs.size() != 2 || certs[0] != kLeafCert || | 90 if (certs.size() != 2 || certs[0] != kLeafCert || |
92 certs[1] != kIntermediateCert || signature != kSignature) { | 91 certs[1] != kIntermediateCert || signature != kSignature) { |
93 *error_details = "Invalid proof"; | 92 *error_details = "Invalid proof"; |
94 verify_details_chromium->cert_verify_result.cert_status = | 93 verify_details_chromium->cert_verify_result.cert_status = |
95 CERT_STATUS_INVALID; | 94 CERT_STATUS_INVALID; |
96 *verify_details = verify_details_chromium.Pass(); | 95 *verify_details = verify_details_chromium.Pass(); |
97 return QUIC_FAILURE; | 96 return QUIC_FAILURE; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 135 } |
137 | 136 |
138 // static | 137 // static |
139 ProofVerifyContext* CryptoTestUtils::FakeProofVerifyContextForTesting() { | 138 ProofVerifyContext* CryptoTestUtils::FakeProofVerifyContextForTesting() { |
140 return nullptr; | 139 return nullptr; |
141 } | 140 } |
142 | 141 |
143 } // namespace test | 142 } // namespace test |
144 | 143 |
145 } // namespace net | 144 } // namespace net |
OLD | NEW |