| OLD | NEW |
| 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/threading/thread_restrictions.h" |
| 9 #include "net/cert/ev_root_ca_metadata.h" | 10 #include "net/cert/ev_root_ca_metadata.h" |
| 10 #include "net/cert/x509_certificate.h" | 11 #include "net/cert/x509_certificate.h" |
| 11 #include "net/test/test_data_directory.h" | 12 #include "net/test/test_data_directory.h" |
| 12 | 13 |
| 13 namespace net { | 14 namespace net { |
| 14 | 15 |
| 15 CertificateList CreateCertificateListFromFile( | 16 CertificateList CreateCertificateListFromFile( |
| 16 const base::FilePath& certs_dir, | 17 const base::FilePath& certs_dir, |
| 17 const std::string& cert_file, | 18 const std::string& cert_file, |
| 18 int format) { | 19 int format) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 intermediates.push_back(certs[i]->os_cert_handle()); | 57 intermediates.push_back(certs[i]->os_cert_handle()); |
| 57 | 58 |
| 58 scoped_refptr<X509Certificate> result(X509Certificate::CreateFromHandle( | 59 scoped_refptr<X509Certificate> result(X509Certificate::CreateFromHandle( |
| 59 certs[0]->os_cert_handle(), intermediates)); | 60 certs[0]->os_cert_handle(), intermediates)); |
| 60 return result; | 61 return result; |
| 61 } | 62 } |
| 62 | 63 |
| 63 scoped_refptr<X509Certificate> ImportCertFromFile( | 64 scoped_refptr<X509Certificate> ImportCertFromFile( |
| 64 const base::FilePath& certs_dir, | 65 const base::FilePath& certs_dir, |
| 65 const std::string& cert_file) { | 66 const std::string& cert_file) { |
| 67 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 66 base::FilePath cert_path = certs_dir.AppendASCII(cert_file); | 68 base::FilePath cert_path = certs_dir.AppendASCII(cert_file); |
| 67 std::string cert_data; | 69 std::string cert_data; |
| 68 if (!base::ReadFileToString(cert_path, &cert_data)) | 70 if (!base::ReadFileToString(cert_path, &cert_data)) |
| 69 return NULL; | 71 return NULL; |
| 70 | 72 |
| 71 CertificateList certs_in_file = | 73 CertificateList certs_in_file = |
| 72 X509Certificate::CreateCertificateListFromBytes( | 74 X509Certificate::CreateCertificateListFromBytes( |
| 73 cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO); | 75 cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO); |
| 74 if (certs_in_file.empty()) | 76 if (certs_in_file.empty()) |
| 75 return NULL; | 77 return NULL; |
| 76 return certs_in_file[0]; | 78 return certs_in_file[0]; |
| 77 } | 79 } |
| 78 | 80 |
| 79 ScopedTestEVPolicy::ScopedTestEVPolicy(EVRootCAMetadata* ev_root_ca_metadata, | 81 ScopedTestEVPolicy::ScopedTestEVPolicy(EVRootCAMetadata* ev_root_ca_metadata, |
| 80 const SHA1HashValue& fingerprint, | 82 const SHA1HashValue& fingerprint, |
| 81 const char* policy) | 83 const char* policy) |
| 82 : fingerprint_(fingerprint), | 84 : fingerprint_(fingerprint), |
| 83 ev_root_ca_metadata_(ev_root_ca_metadata) { | 85 ev_root_ca_metadata_(ev_root_ca_metadata) { |
| 84 EXPECT_TRUE(ev_root_ca_metadata->AddEVCA(fingerprint, policy)); | 86 EXPECT_TRUE(ev_root_ca_metadata->AddEVCA(fingerprint, policy)); |
| 85 } | 87 } |
| 86 | 88 |
| 87 ScopedTestEVPolicy::~ScopedTestEVPolicy() { | 89 ScopedTestEVPolicy::~ScopedTestEVPolicy() { |
| 88 EXPECT_TRUE(ev_root_ca_metadata_->RemoveEVCA(fingerprint_)); | 90 EXPECT_TRUE(ev_root_ca_metadata_->RemoveEVCA(fingerprint_)); |
| 89 } | 91 } |
| 90 | 92 |
| 91 } // namespace net | 93 } // namespace net |
| OLD | NEW |