| 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 "net/cert/ev_root_ca_metadata.h" |   9 #include "net/cert/ev_root_ca_metadata.h" | 
|  10 #include "net/cert/x509_certificate.h" |  10 #include "net/cert/x509_certificate.h" | 
|  11 #include "testing/gtest/include/gtest/gtest.h" |  11 #include "net/test/test_data_directory.h" | 
|  12  |  12  | 
|  13 namespace net { |  13 namespace net { | 
|  14  |  14  | 
|  15 CertificateList CreateCertificateListFromFile( |  15 CertificateList CreateCertificateListFromFile( | 
|  16     const base::FilePath& certs_dir, |  16     const base::FilePath& certs_dir, | 
|  17     const std::string& cert_file, |  17     const std::string& cert_file, | 
|  18     int format) { |  18     int format) { | 
|  19   base::FilePath cert_path = certs_dir.AppendASCII(cert_file); |  19   base::FilePath cert_path = certs_dir.AppendASCII(cert_file); | 
|  20   std::string cert_data; |  20   std::string cert_data; | 
|  21   if (!base::ReadFileToString(cert_path, &cert_data)) |  21   if (!base::ReadFileToString(cert_path, &cert_data)) | 
|  22     return CertificateList(); |  22     return CertificateList(); | 
|  23   return X509Certificate::CreateCertificateListFromBytes(cert_data.data(), |  23   return X509Certificate::CreateCertificateListFromBytes(cert_data.data(), | 
|  24                                                          cert_data.size(), |  24                                                          cert_data.size(), | 
|  25                                                          format); |  25                                                          format); | 
|  26 } |  26 } | 
|  27  |  27  | 
 |  28 ::testing::AssertionResult LoadCertificateFiles( | 
 |  29     const std::vector<std::string>& cert_filenames, | 
 |  30     CertificateList* certs) { | 
 |  31   certs->clear(); | 
 |  32   for (const std::string& filename : cert_filenames) { | 
 |  33     scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( | 
 |  34         GetTestCertsDirectory(), filename, X509Certificate::FORMAT_AUTO); | 
 |  35     if (!cert) | 
 |  36       return ::testing::AssertionFailure() | 
 |  37              << "Failed loading certificate from file: " << filename | 
 |  38              << " (in directory: " << GetTestCertsDirectory().value() << ")"; | 
 |  39     certs->push_back(cert); | 
 |  40   } | 
 |  41  | 
 |  42   return ::testing::AssertionSuccess(); | 
 |  43 } | 
 |  44  | 
|  28 scoped_refptr<X509Certificate> CreateCertificateChainFromFile( |  45 scoped_refptr<X509Certificate> CreateCertificateChainFromFile( | 
|  29     const base::FilePath& certs_dir, |  46     const base::FilePath& certs_dir, | 
|  30     const std::string& cert_file, |  47     const std::string& cert_file, | 
|  31     int format) { |  48     int format) { | 
|  32   CertificateList certs = CreateCertificateListFromFile( |  49   CertificateList certs = CreateCertificateListFromFile( | 
|  33       certs_dir, cert_file, format); |  50       certs_dir, cert_file, format); | 
|  34   if (certs.empty()) |  51   if (certs.empty()) | 
|  35     return NULL; |  52     return NULL; | 
|  36  |  53  | 
|  37   X509Certificate::OSCertHandles intermediates; |  54   X509Certificate::OSCertHandles intermediates; | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
|  65     : fingerprint_(fingerprint), |  82     : fingerprint_(fingerprint), | 
|  66       ev_root_ca_metadata_(ev_root_ca_metadata) { |  83       ev_root_ca_metadata_(ev_root_ca_metadata) { | 
|  67   EXPECT_TRUE(ev_root_ca_metadata->AddEVCA(fingerprint, policy)); |  84   EXPECT_TRUE(ev_root_ca_metadata->AddEVCA(fingerprint, policy)); | 
|  68 } |  85 } | 
|  69  |  86  | 
|  70 ScopedTestEVPolicy::~ScopedTestEVPolicy() { |  87 ScopedTestEVPolicy::~ScopedTestEVPolicy() { | 
|  71   EXPECT_TRUE(ev_root_ca_metadata_->RemoveEVCA(fingerprint_)); |  88   EXPECT_TRUE(ev_root_ca_metadata_->RemoveEVCA(fingerprint_)); | 
|  72 } |  89 } | 
|  73  |  90  | 
|  74 }  // namespace net |  91 }  // namespace net | 
| OLD | NEW |