| 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/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
| 15 #include "net/base/test_data_directory.h" | 15 #include "net/base/test_data_directory.h" |
| 16 #include "net/cert/cert_status_flags.h" | 16 #include "net/cert/cert_status_flags.h" |
| 17 #include "net/cert/cert_verifier.h" | 17 #include "net/cert/cert_verifier.h" |
| 18 #include "net/cert/cert_verify_result.h" | 18 #include "net/cert/cert_verify_result.h" |
| 19 #include "net/cert/ct_verifier.h" |
| 19 #include "net/cert/mock_cert_verifier.h" | 20 #include "net/cert/mock_cert_verifier.h" |
| 21 #include "net/cert/multi_log_ct_verifier.h" |
| 20 #include "net/cert/test_root_certs.h" | 22 #include "net/cert/test_root_certs.h" |
| 21 #include "net/cert/x509_certificate.h" | 23 #include "net/cert/x509_certificate.h" |
| 22 #include "net/cert/x509_util.h" | 24 #include "net/cert/x509_util.h" |
| 23 #include "net/http/transport_security_state.h" | 25 #include "net/http/transport_security_state.h" |
| 24 #include "net/log/net_log.h" | 26 #include "net/log/net_log.h" |
| 25 #include "net/quic/crypto/crypto_utils.h" | 27 #include "net/quic/crypto/crypto_utils.h" |
| 26 #include "net/quic/crypto/proof_source_chromium.h" | 28 #include "net/quic/crypto/proof_source_chromium.h" |
| 27 #include "net/quic/crypto/proof_verifier_chromium.h" | 29 #include "net/quic/crypto/proof_verifier_chromium.h" |
| 28 #include "net/ssl/ssl_config_service.h" | 30 #include "net/ssl/ssl_config_service.h" |
| 29 #include "net/test/cert_test_util.h" | 31 #include "net/test/cert_test_util.h" |
| 30 | 32 |
| 31 using base::StringPiece; | 33 using base::StringPiece; |
| 32 using base::StringPrintf; | 34 using base::StringPrintf; |
| 33 using std::string; | 35 using std::string; |
| 34 using std::vector; | 36 using std::vector; |
| 35 | 37 |
| 36 namespace net { | 38 namespace net { |
| 37 | 39 |
| 38 namespace test { | 40 namespace test { |
| 39 | 41 |
| 40 namespace { | 42 namespace { |
| 41 | 43 |
| 42 class TestProofVerifierChromium : public ProofVerifierChromium { | 44 class TestProofVerifierChromium : public ProofVerifierChromium { |
| 43 public: | 45 public: |
| 44 TestProofVerifierChromium( | 46 TestProofVerifierChromium( |
| 45 scoped_ptr<CertVerifier> cert_verifier, | 47 scoped_ptr<CertVerifier> cert_verifier, |
| 46 scoped_ptr<TransportSecurityState> transport_security_state, | 48 scoped_ptr<TransportSecurityState> transport_security_state, |
| 49 scoped_ptr<CTVerifier> cert_transparency_verifier, |
| 47 const std::string& cert_file) | 50 const std::string& cert_file) |
| 48 : ProofVerifierChromium(cert_verifier.get(), | 51 : ProofVerifierChromium(cert_verifier.get(), |
| 49 nullptr, | 52 nullptr, |
| 50 transport_security_state.get()), | 53 transport_security_state.get(), |
| 54 cert_transparency_verifier.get()), |
| 51 cert_verifier_(cert_verifier.Pass()), | 55 cert_verifier_(cert_verifier.Pass()), |
| 52 transport_security_state_(transport_security_state.Pass()) { | 56 transport_security_state_(transport_security_state.Pass()), |
| 57 cert_transparency_verifier_(cert_transparency_verifier.Pass()) { |
| 53 // Load and install the root for the validated chain. | 58 // Load and install the root for the validated chain. |
| 54 scoped_refptr<X509Certificate> root_cert = | 59 scoped_refptr<X509Certificate> root_cert = |
| 55 ImportCertFromFile(GetTestCertsDirectory(), cert_file); | 60 ImportCertFromFile(GetTestCertsDirectory(), cert_file); |
| 56 scoped_root_.Reset(root_cert.get()); | 61 scoped_root_.Reset(root_cert.get()); |
| 57 } | 62 } |
| 58 | 63 |
| 59 ~TestProofVerifierChromium() override {} | 64 ~TestProofVerifierChromium() override {} |
| 60 | 65 |
| 61 CertVerifier* cert_verifier() { return cert_verifier_.get(); } | 66 CertVerifier* cert_verifier() { return cert_verifier_.get(); } |
| 62 | 67 |
| 63 private: | 68 private: |
| 64 ScopedTestRoot scoped_root_; | 69 ScopedTestRoot scoped_root_; |
| 65 scoped_ptr<CertVerifier> cert_verifier_; | 70 scoped_ptr<CertVerifier> cert_verifier_; |
| 66 scoped_ptr<TransportSecurityState> transport_security_state_; | 71 scoped_ptr<TransportSecurityState> transport_security_state_; |
| 72 scoped_ptr<CTVerifier> cert_transparency_verifier_; |
| 67 }; | 73 }; |
| 68 | 74 |
| 69 const char kSignature[] = "signature"; | 75 const char kSignature[] = "signature"; |
| 70 const char kSCT[] = "CryptoServerTests"; | 76 const char kSCT[] = "CryptoServerTests"; |
| 71 | 77 |
| 72 class FakeProofSource : public ProofSource { | 78 class FakeProofSource : public ProofSource { |
| 73 public: | 79 public: |
| 74 FakeProofSource() {} | 80 FakeProofSource() {} |
| 75 ~FakeProofSource() override {} | 81 ~FakeProofSource() override {} |
| 76 | 82 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 private: | 126 private: |
| 121 std::vector<std::string> certificates_; | 127 std::vector<std::string> certificates_; |
| 122 | 128 |
| 123 DISALLOW_COPY_AND_ASSIGN(FakeProofSource); | 129 DISALLOW_COPY_AND_ASSIGN(FakeProofSource); |
| 124 }; | 130 }; |
| 125 | 131 |
| 126 class FakeProofVerifier : public TestProofVerifierChromium { | 132 class FakeProofVerifier : public TestProofVerifierChromium { |
| 127 public: | 133 public: |
| 128 FakeProofVerifier(scoped_ptr<CertVerifier> cert_verifier, | 134 FakeProofVerifier(scoped_ptr<CertVerifier> cert_verifier, |
| 129 scoped_ptr<TransportSecurityState> transport_security_state, | 135 scoped_ptr<TransportSecurityState> transport_security_state, |
| 136 scoped_ptr<CTVerifier> cert_transparency_verifier, |
| 130 const std::string& cert_file) | 137 const std::string& cert_file) |
| 131 : TestProofVerifierChromium(cert_verifier.Pass(), | 138 : TestProofVerifierChromium(cert_verifier.Pass(), |
| 132 transport_security_state.Pass(), | 139 transport_security_state.Pass(), |
| 140 cert_transparency_verifier.Pass(), |
| 133 cert_file) {} | 141 cert_file) {} |
| 134 ~FakeProofVerifier() override {} | 142 ~FakeProofVerifier() override {} |
| 135 | 143 |
| 136 // ProofVerifier interface | 144 // ProofVerifier interface |
| 137 QuicAsyncStatus VerifyProof(const std::string& hostname, | 145 QuicAsyncStatus VerifyProof(const std::string& hostname, |
| 138 const std::string& server_config, | 146 const std::string& server_config, |
| 139 const std::vector<std::string>& certs, | 147 const std::vector<std::string>& certs, |
| 140 const std::string& cert_sct, | 148 const std::string& cert_sct, |
| 141 const std::string& signature, | 149 const std::string& signature, |
| 142 const ProofVerifyContext* verify_context, | 150 const ProofVerifyContext* verify_context, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 ImportCertFromFile(GetTestCertsDirectory(), "quic_test.example.com.crt"); | 231 ImportCertFromFile(GetTestCertsDirectory(), "quic_test.example.com.crt"); |
| 224 cert_verifier->AddResultForCertAndHost(verify_result.verified_cert.get(), | 232 cert_verifier->AddResultForCertAndHost(verify_result.verified_cert.get(), |
| 225 "test.example.com", verify_result, OK); | 233 "test.example.com", verify_result, OK); |
| 226 verify_result.verified_cert = ImportCertFromFile( | 234 verify_result.verified_cert = ImportCertFromFile( |
| 227 GetTestCertsDirectory(), "quic_test_ecc.example.com.crt"); | 235 GetTestCertsDirectory(), "quic_test_ecc.example.com.crt"); |
| 228 cert_verifier->AddResultForCertAndHost(verify_result.verified_cert.get(), | 236 cert_verifier->AddResultForCertAndHost(verify_result.verified_cert.get(), |
| 229 "test.example.com", verify_result, OK); | 237 "test.example.com", verify_result, OK); |
| 230 if (use_real_proof_verifier) { | 238 if (use_real_proof_verifier) { |
| 231 return new TestProofVerifierChromium( | 239 return new TestProofVerifierChromium( |
| 232 cert_verifier.Pass(), make_scoped_ptr(new TransportSecurityState), | 240 cert_verifier.Pass(), make_scoped_ptr(new TransportSecurityState), |
| 233 "quic_root.crt"); | 241 make_scoped_ptr(new MultiLogCTVerifier), "quic_root.crt"); |
| 234 } | 242 } |
| 235 #if defined(USE_OPENSSL) | 243 #if defined(USE_OPENSSL) |
| 236 return new TestProofVerifierChromium( | 244 return new TestProofVerifierChromium( |
| 237 cert_verifier.Pass(), make_scoped_ptr(new TransportSecurityState), | 245 cert_verifier.Pass(), make_scoped_ptr(new TransportSecurityState), |
| 238 "quic_root.crt"); | 246 make_scoped_ptr(new MultiLogCTVerifier), "quic_root.crt"); |
| 239 #else | 247 #else |
| 240 return new FakeProofVerifier(cert_verifier.Pass(), | 248 return new FakeProofVerifier( |
| 241 make_scoped_ptr(new TransportSecurityState), | 249 cert_verifier.Pass(), make_scoped_ptr(new TransportSecurityState), |
| 242 "quic_root.crt"); | 250 make_scoped_ptr(new MultiLogCTVerifier), "quic_root.crt"); |
| 243 #endif | 251 #endif |
| 244 } | 252 } |
| 245 | 253 |
| 246 // static | 254 // static |
| 247 ProofVerifier* CryptoTestUtils::ProofVerifierForTesting() { | 255 ProofVerifier* CryptoTestUtils::ProofVerifierForTesting() { |
| 248 return ProofVerifierForTestingInternal(/*use_real_proof_verifier=*/false); | 256 return ProofVerifierForTestingInternal(/*use_real_proof_verifier=*/false); |
| 249 } | 257 } |
| 250 | 258 |
| 251 // static | 259 // static |
| 252 ProofVerifier* CryptoTestUtils::RealProofVerifierForTesting() { | 260 ProofVerifier* CryptoTestUtils::RealProofVerifierForTesting() { |
| 253 return ProofVerifierForTestingInternal(/*use_real_proof_verifier=*/true); | 261 return ProofVerifierForTestingInternal(/*use_real_proof_verifier=*/true); |
| 254 } | 262 } |
| 255 | 263 |
| 256 // static | 264 // static |
| 257 ProofVerifyContext* CryptoTestUtils::ProofVerifyContextForTesting() { | 265 ProofVerifyContext* CryptoTestUtils::ProofVerifyContextForTesting() { |
| 258 return new ProofVerifyContextChromium(/*cert_verify_flags=*/0, BoundNetLog()); | 266 return new ProofVerifyContextChromium(/*cert_verify_flags=*/0, BoundNetLog()); |
| 259 } | 267 } |
| 260 | 268 |
| 261 } // namespace test | 269 } // namespace test |
| 262 | 270 |
| 263 } // namespace net | 271 } // namespace net |
| OLD | NEW |