blob: f5b104b12255f64c2a8e9dd8126c4b89f1e3edfa [file] [log] [blame]
[email protected]e54d0af2012-03-03 01:07:151// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c81d9dcc2010-03-17 00:51:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]6e7845ae2013-03-29 21:48:115#ifndef NET_TEST_CERT_TEST_UTIL_H_
6#define NET_TEST_CERT_TEST_UTIL_H_
[email protected]c81d9dcc2010-03-17 00:51:447
[email protected]32765f82010-12-16 00:01:378#include <string>
9
[email protected]3b63f8f42011-03-28 01:54:1510#include "base/memory/ref_counted.h"
[email protected]6e7845ae2013-03-29 21:48:1111#include "net/cert/x509_cert_types.h"
12#include "net/cert/x509_certificate.h"
eromance65aff2017-02-04 00:05:3213#include "testing/gtest/include/gtest/gtest.h"
[email protected]c81d9dcc2010-03-17 00:51:4414
davidben71f35ff2015-04-17 20:54:4815#if defined(USE_NSS_CERTS)
[email protected]83e1ae32014-07-18 10:57:0716// From <pk11pub.h>
17typedef struct PK11SlotInfoStr PK11SlotInfo;
18#endif
19
[email protected]a3ef4832013-02-02 05:12:3320namespace base {
[email protected]864b1362010-08-19 03:49:3821class FilePath;
[email protected]a3ef4832013-02-02 05:12:3322}
[email protected]864b1362010-08-19 03:49:3823
[email protected]c81d9dcc2010-03-17 00:51:4424namespace net {
25
[email protected]7d015e42012-03-14 16:15:1226class EVRootCAMetadata;
27
davidben71f35ff2015-04-17 20:54:4828#if defined(USE_NSS_CERTS)
davidben85bad9e2015-05-11 20:20:1029// Imports a private key from file |key_filename| in |dir| into |slot|. The file
30// must contain a PKCS#8 PrivateKeyInfo in DER encoding. Returns true on success
31// and false on failure.
32bool ImportSensitiveKeyFromFile(const base::FilePath& dir,
33 const std::string& key_filename,
34 PK11SlotInfo* slot);
[email protected]cc9b29fb2014-08-02 11:52:2635
36bool ImportClientCertToSlot(const scoped_refptr<X509Certificate>& cert,
37 PK11SlotInfo* slot);
38
39scoped_refptr<X509Certificate> ImportClientCertAndKeyFromFile(
40 const base::FilePath& dir,
41 const std::string& cert_filename,
42 const std::string& key_filename,
43 PK11SlotInfo* slot);
[email protected]83e1ae32014-07-18 10:57:0744#endif
45
46// Imports all of the certificates in |cert_file|, a file in |certs_dir|, into a
47// CertificateList.
[email protected]a3ef4832013-02-02 05:12:3348CertificateList CreateCertificateListFromFile(const base::FilePath& certs_dir,
[email protected]e54d0af2012-03-03 01:07:1549 const std::string& cert_file,
50 int format);
51
eromance65aff2017-02-04 00:05:3252// Imports all the certificates given a list of filenames, and assigns the
53// result to |*certs|. The filenames are relative to the test certificates
54// directory.
55::testing::AssertionResult LoadCertificateFiles(
56 const std::vector<std::string>& cert_filenames,
57 CertificateList* certs);
58
[email protected]1f11d6f2013-11-24 22:33:0059// Imports all of the certificates in |cert_file|, a file in |certs_dir|, into
60// a new X509Certificate. The first certificate in the chain will be used for
61// the returned cert, with any additional certificates configured as
62// intermediate certificates.
63scoped_refptr<X509Certificate> CreateCertificateChainFromFile(
64 const base::FilePath& certs_dir,
65 const std::string& cert_file,
66 int format);
67
68// Imports a single certificate from |cert_file|.
[email protected]42fdb452012-11-01 12:44:4069// |certs_dir| represents the test certificates directory. |cert_file| is the
[email protected]32765f82010-12-16 00:01:3770// name of the certificate file. If cert_file contains multiple certificates,
71// the first certificate found will be returned.
[email protected]a3ef4832013-02-02 05:12:3372scoped_refptr<X509Certificate> ImportCertFromFile(const base::FilePath& certs_dir,
[email protected]32765f82010-12-16 00:01:3773 const std::string& cert_file);
[email protected]c81d9dcc2010-03-17 00:51:4474
[email protected]7d015e42012-03-14 16:15:1275// ScopedTestEVPolicy causes certificates marked with |policy|, issued from a
76// root with the given fingerprint, to be treated as EV. |policy| is expressed
77// as a string of dotted numbers: i.e. "1.2.3.4".
78// This should only be used in unittests as adding a CA twice causes a CHECK
79// failure.
80class ScopedTestEVPolicy {
81 public:
82 ScopedTestEVPolicy(EVRootCAMetadata* ev_root_ca_metadata,
[email protected]ede03212012-09-07 12:52:2683 const SHA1HashValue& fingerprint,
[email protected]7d015e42012-03-14 16:15:1284 const char* policy);
85 ~ScopedTestEVPolicy();
86
87 private:
[email protected]ede03212012-09-07 12:52:2688 SHA1HashValue fingerprint_;
[email protected]7d015e42012-03-14 16:15:1289 EVRootCAMetadata* const ev_root_ca_metadata_;
90};
91
[email protected]c81d9dcc2010-03-17 00:51:4492} // namespace net
93
[email protected]6e7845ae2013-03-29 21:48:1194#endif // NET_TEST_CERT_TEST_UTIL_H_