Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: net/test/cert_test_util.cc

Issue 27026002: CT: Adding preliminary Certificate Transparency support to Chromium. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Distinguish between SCTs from unknown logs and unverified ones Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/test/cert_test_util.h ('k') | net/url_request/url_request_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/test/cert_test_util.h" 5 #include "net/test/cert_test_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "net/cert/ev_root_ca_metadata.h" 10 #include "net/cert/ev_root_ca_metadata.h"
11 #include "net/cert/x509_certificate.h" 11 #include "net/cert/x509_certificate.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 CertificateList CreateCertificateListFromFile( 16 CertificateList CreateCertificateListFromFile(
17 const base::FilePath& certs_dir, 17 const base::FilePath& certs_dir,
18 const std::string& cert_file, 18 const std::string& cert_file,
19 int format) { 19 int format) {
20 base::FilePath cert_path = certs_dir.AppendASCII(cert_file); 20 base::FilePath cert_path = certs_dir.AppendASCII(cert_file);
21 std::string cert_data; 21 std::string cert_data;
22 if (!base::ReadFileToString(cert_path, &cert_data)) 22 if (!base::ReadFileToString(cert_path, &cert_data))
23 return CertificateList(); 23 return CertificateList();
24 return X509Certificate::CreateCertificateListFromBytes(cert_data.data(), 24 return X509Certificate::CreateCertificateListFromBytes(cert_data.data(),
25 cert_data.size(), 25 cert_data.size(),
26 format); 26 format);
27 } 27 }
28 28
29 scoped_refptr<X509Certificate> CreateCertificateChainFromFile(
30 const base::FilePath& certs_dir,
31 const std::string& cert_file,
32 int format) {
33 CertificateList certs = CreateCertificateListFromFile(certs_dir, cert_file,
34 format);
35 if (certs.empty())
36 return NULL;
37 X509Certificate::OSCertHandles intermediates;
38 for (size_t i = 1; i < certs.size(); ++i)
39 intermediates.push_back(certs[i]->os_cert_handle());
40
41 scoped_refptr<X509Certificate> result(X509Certificate::CreateFromHandle(
42 certs[0]->os_cert_handle(), intermediates));
43 return result;
44 }
45
29 scoped_refptr<X509Certificate> ImportCertFromFile( 46 scoped_refptr<X509Certificate> ImportCertFromFile(
30 const base::FilePath& certs_dir, 47 const base::FilePath& certs_dir,
31 const std::string& cert_file) { 48 const std::string& cert_file) {
32 base::FilePath cert_path = certs_dir.AppendASCII(cert_file); 49 base::FilePath cert_path = certs_dir.AppendASCII(cert_file);
33 std::string cert_data; 50 std::string cert_data;
34 if (!base::ReadFileToString(cert_path, &cert_data)) 51 if (!base::ReadFileToString(cert_path, &cert_data))
35 return NULL; 52 return NULL;
36 53
37 CertificateList certs_in_file = 54 CertificateList certs_in_file =
38 X509Certificate::CreateCertificateListFromBytes( 55 X509Certificate::CreateCertificateListFromBytes(
39 cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO); 56 cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO);
40 if (certs_in_file.empty()) 57 if (certs_in_file.empty())
41 return NULL; 58 return NULL;
42 return certs_in_file[0]; 59 return certs_in_file[0];
43 } 60 }
44 61
45 ScopedTestEVPolicy::ScopedTestEVPolicy(EVRootCAMetadata* ev_root_ca_metadata, 62 ScopedTestEVPolicy::ScopedTestEVPolicy(EVRootCAMetadata* ev_root_ca_metadata,
46 const SHA1HashValue& fingerprint, 63 const SHA1HashValue& fingerprint,
47 const char* policy) 64 const char* policy)
48 : fingerprint_(fingerprint), 65 : fingerprint_(fingerprint),
49 ev_root_ca_metadata_(ev_root_ca_metadata) { 66 ev_root_ca_metadata_(ev_root_ca_metadata) {
50 EXPECT_TRUE(ev_root_ca_metadata->AddEVCA(fingerprint, policy)); 67 EXPECT_TRUE(ev_root_ca_metadata->AddEVCA(fingerprint, policy));
51 } 68 }
52 69
53 ScopedTestEVPolicy::~ScopedTestEVPolicy() { 70 ScopedTestEVPolicy::~ScopedTestEVPolicy() {
54 EXPECT_TRUE(ev_root_ca_metadata_->RemoveEVCA(fingerprint_)); 71 EXPECT_TRUE(ev_root_ca_metadata_->RemoveEVCA(fingerprint_));
55 } 72 }
56 73
57 } // namespace net 74 } // namespace net
OLDNEW
« no previous file with comments | « net/test/cert_test_util.h ('k') | net/url_request/url_request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698