1 // Copyright (c) 2012 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 #ifndef NET_TEST_CERT_TEST_UTIL_H_ 6 #define NET_TEST_CERT_TEST_UTIL_H_ 7 8 #include <string> 9 10 #include "base/memory/ref_counted.h" 11 #include "net/cert/x509_cert_types.h" 12 #include "net/cert/x509_certificate.h" 13 14 namespace base { 15 class FilePath; 16 } 17 18 namespace net { 19 20 class EVRootCAMetadata; 21 22 // Imports all of the certificates in |cert_file|, a file in |certs_dir|, 23 // // into a CertificateList. 24 CertificateList CreateCertificateListFromFile(const base::FilePath& certs_dir, 25 const std::string& cert_file, 26 int format); 27 28 // Imports all of the certificates in |cert_file|, a file in |certs_dir|, into 29 // a new X509Certificate. The first certificate in the chain will be used for 30 // the returned cert, with any additional certificates configured as 31 // intermediate certificates. 32 scoped_refptr<X509Certificate> CreateCertificateChainFromFile( 33 const base::FilePath& certs_dir, 34 const std::string& cert_file, 35 int format); 36 37 // Imports a single certificate from |cert_file|. 38 // |certs_dir| represents the test certificates directory. |cert_file| is the 39 // name of the certificate file. If cert_file contains multiple certificates, 40 // the first certificate found will be returned. 41 scoped_refptr<X509Certificate> ImportCertFromFile(const base::FilePath& certs_dir, 42 const std::string& cert_file); 43 44 // ScopedTestEVPolicy causes certificates marked with |policy|, issued from a 45 // root with the given fingerprint, to be treated as EV. |policy| is expressed 46 // as a string of dotted numbers: i.e. "1.2.3.4". 47 // This should only be used in unittests as adding a CA twice causes a CHECK 48 // failure. 49 class ScopedTestEVPolicy { 50 public: 51 ScopedTestEVPolicy(EVRootCAMetadata* ev_root_ca_metadata, 52 const SHA1HashValue& fingerprint, 53 const char* policy); 54 ~ScopedTestEVPolicy(); 55 56 private: 57 SHA1HashValue fingerprint_; 58 EVRootCAMetadata* const ev_root_ca_metadata_; 59 }; 60 61 } // namespace net 62 63 #endif // NET_TEST_CERT_TEST_UTIL_H_ 64