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 3 // found in the LICENSE file. 4 5 #include "net/quic/test_tools/crypto_test_utils.h" 6 7 #include "base/memory/ref_counted.h" 8 #include "base/memory/scoped_ptr.h" 9 #include "net/base/test_data_directory.h" 10 #include "net/cert/cert_verifier.h" 11 #include "net/cert/test_root_certs.h" 12 #include "net/cert/x509_certificate.h" 13 #include "net/http/transport_security_state.h" 14 #include "net/quic/crypto/proof_source_chromium.h" 15 #include "net/quic/crypto/proof_verifier_chromium.h" 16 #include "net/test/cert_test_util.h" 17 18 namespace net { 19 20 namespace test { 21 22 class TestProofVerifierChromium : public ProofVerifierChromium { 23 public: 24 TestProofVerifierChromium(CertVerifier* cert_verifier, 25 TransportSecurityState* transport_security_state, 26 const std::string& cert_file) 27 : ProofVerifierChromium(cert_verifier, transport_security_state), 28 cert_verifier_(cert_verifier), 29 transport_security_state_(transport_security_state) { 30 // Load and install the root for the validated chain. 31 scoped_refptr<X509Certificate> root_cert = 32 ImportCertFromFile(GetTestCertsDirectory(), cert_file); 33 scoped_root_.Reset(root_cert.get()); 34 } 35 virtual ~TestProofVerifierChromium() {} 36 37 private: 38 ScopedTestRoot scoped_root_; 39 scoped_ptr<CertVerifier> cert_verifier_; 40 scoped_ptr<TransportSecurityState> transport_security_state_; 41 }; 42 43 // static 44 ProofSource* CryptoTestUtils::ProofSourceForTesting() { 45 return new ProofSourceChromium(); 46 } 47 48 // static 49 ProofVerifier* CryptoTestUtils::ProofVerifierForTesting() { 50 TestProofVerifierChromium* proof_verifier = 51 new TestProofVerifierChromium(CertVerifier::CreateDefault(), 52 new TransportSecurityState, 53 "quic_root.crt"); 54 return proof_verifier; 55 } 56 57 // static 58 ProofVerifyContext* CryptoTestUtils::ProofVerifyContextForTesting() { 59 return new ProofVerifyContextChromium(BoundNetLog()); 60 } 61 62 } // namespace test 63 64 } // namespace net 65