blob: d384abeb71944905e3aa95e0d6b27b287c55dc5c [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
5#include "net/base/cert_test_util.h"
6
[email protected]32765f82010-12-16 00:01:377#include "base/file_path.h"
[email protected]c81d9dcc2010-03-17 00:51:448#include "base/file_util.h"
[email protected]c81d9dcc2010-03-17 00:51:449#include "base/path_service.h"
[email protected]7d015e42012-03-14 16:15:1210#include "net/base/ev_root_ca_metadata.h"
[email protected]c81d9dcc2010-03-17 00:51:4411#include "net/base/x509_certificate.h"
[email protected]7d015e42012-03-14 16:15:1212#include "testing/gtest/include/gtest/gtest.h"
[email protected]c81d9dcc2010-03-17 00:51:4413
14namespace net {
15
[email protected]e54d0af2012-03-03 01:07:1516CertificateList CreateCertificateListFromFile(
[email protected]6cdfd7f2013-02-08 20:40:1517 const base::FilePath& certs_dir,
[email protected]e54d0af2012-03-03 01:07:1518 const std::string& cert_file,
19 int format) {
[email protected]6cdfd7f2013-02-08 20:40:1520 base::FilePath cert_path = certs_dir.AppendASCII(cert_file);
[email protected]e54d0af2012-03-03 01:07:1521 std::string cert_data;
22 if (!file_util::ReadFileToString(cert_path, &cert_data))
23 return CertificateList();
24 return X509Certificate::CreateCertificateListFromBytes(cert_data.data(),
25 cert_data.size(),
26 format);
27}
28
[email protected]32765f82010-12-16 00:01:3729scoped_refptr<X509Certificate> ImportCertFromFile(
[email protected]6cdfd7f2013-02-08 20:40:1530 const base::FilePath& certs_dir,
[email protected]32765f82010-12-16 00:01:3731 const std::string& cert_file) {
[email protected]6cdfd7f2013-02-08 20:40:1532 base::FilePath cert_path = certs_dir.AppendASCII(cert_file);
[email protected]32765f82010-12-16 00:01:3733 std::string cert_data;
34 if (!file_util::ReadFileToString(cert_path, &cert_data))
[email protected]1e5fead2010-10-08 14:33:1135 return NULL;
[email protected]1e5fead2010-10-08 14:33:1136
[email protected]32765f82010-12-16 00:01:3737 CertificateList certs_in_file =
38 X509Certificate::CreateCertificateListFromBytes(
39 cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO);
40 if (certs_in_file.empty())
[email protected]1e5fead2010-10-08 14:33:1141 return NULL;
[email protected]32765f82010-12-16 00:01:3742 return certs_in_file[0];
[email protected]1e5fead2010-10-08 14:33:1143}
[email protected]c81d9dcc2010-03-17 00:51:4444
[email protected]7d015e42012-03-14 16:15:1245ScopedTestEVPolicy::ScopedTestEVPolicy(EVRootCAMetadata* ev_root_ca_metadata,
[email protected]ede03212012-09-07 12:52:2646 const SHA1HashValue& fingerprint,
[email protected]7d015e42012-03-14 16:15:1247 const char* policy)
48 : fingerprint_(fingerprint),
49 ev_root_ca_metadata_(ev_root_ca_metadata) {
50 EXPECT_TRUE(ev_root_ca_metadata->AddEVCA(fingerprint, policy));
51}
52
53ScopedTestEVPolicy::~ScopedTestEVPolicy() {
54 EXPECT_TRUE(ev_root_ca_metadata_->RemoveEVCA(fingerprint_));
55}
56
[email protected]c81d9dcc2010-03-17 00:51:4457} // namespace net