| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/certificate_reporting/error_report.h" | 5 #include "components/certificate_reporting/error_report.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 using net::SSLInfo; | 34 using net::SSLInfo; |
| 35 using testing::UnorderedElementsAre; | 35 using testing::UnorderedElementsAre; |
| 36 using testing::UnorderedElementsAreArray; | 36 using testing::UnorderedElementsAreArray; |
| 37 | 37 |
| 38 namespace certificate_reporting { | 38 namespace certificate_reporting { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 const char kDummyHostname[] = "dummy.hostname.com"; | 42 const char kDummyHostname[] = "dummy.hostname.com"; |
| 43 const char kDummyFailureLog[] = "dummy failure log"; | 43 const char kDummyFailureLog[] = "dummy failure log"; |
| 44 const char kTestCertFilename[] = "test_mail_google_com.pem"; | 44 const char kTestCertFilename[] = "x509_verify_results.chain.pem"; |
| 45 | 45 |
| 46 const net::CertStatus kCertStatus = | 46 const net::CertStatus kCertStatus = |
| 47 net::CERT_STATUS_COMMON_NAME_INVALID | net::CERT_STATUS_REVOKED; | 47 net::CERT_STATUS_COMMON_NAME_INVALID | net::CERT_STATUS_REVOKED; |
| 48 | 48 |
| 49 const CertLoggerRequest::CertError kFirstReportedCertError = | 49 const CertLoggerRequest::CertError kFirstReportedCertError = |
| 50 CertLoggerRequest::ERR_CERT_COMMON_NAME_INVALID; | 50 CertLoggerRequest::ERR_CERT_COMMON_NAME_INVALID; |
| 51 const CertLoggerRequest::CertError kSecondReportedCertError = | 51 const CertLoggerRequest::CertError kSecondReportedCertError = |
| 52 CertLoggerRequest::ERR_CERT_REVOKED; | 52 CertLoggerRequest::ERR_CERT_REVOKED; |
| 53 | 53 |
| 54 // Whether to include an unverified certificate chain in the test | 54 // Whether to include an unverified certificate chain in the test |
| (...skipping 14 matching lines...) Expand all Loading... |
| 69 info->unverified_cert = net::ImportCertFromFile( | 69 info->unverified_cert = net::ImportCertFromFile( |
| 70 net::GetTestCertsDirectory(), kTestCertFilename); | 70 net::GetTestCertsDirectory(), kTestCertFilename); |
| 71 ASSERT_TRUE(info->unverified_cert); | 71 ASSERT_TRUE(info->unverified_cert); |
| 72 } | 72 } |
| 73 info->is_issued_by_known_root = true; | 73 info->is_issued_by_known_root = true; |
| 74 info->cert_status = cert_status; | 74 info->cert_status = cert_status; |
| 75 info->pinning_failure_log = kDummyFailureLog; | 75 info->pinning_failure_log = kDummyFailureLog; |
| 76 } | 76 } |
| 77 | 77 |
| 78 std::string GetPEMEncodedChain() { | 78 std::string GetPEMEncodedChain() { |
| 79 base::FilePath cert_path = | |
| 80 net::GetTestCertsDirectory().AppendASCII(kTestCertFilename); | |
| 81 std::string cert_data; | 79 std::string cert_data; |
| 82 EXPECT_TRUE(base::ReadFileToString(cert_path, &cert_data)); | 80 std::vector<std::string> pem_certs; |
| 81 scoped_refptr<net::X509Certificate> cert = |
| 82 net::ImportCertFromFile(net::GetTestCertsDirectory(), kTestCertFilename); |
| 83 if (!cert || !cert->GetPEMEncodedChain(&pem_certs)) { |
| 84 ADD_FAILURE(); |
| 85 return cert_data; |
| 86 } |
| 87 for (const auto& cert : pem_certs) { |
| 88 cert_data += cert; |
| 89 } |
| 83 return cert_data; | 90 return cert_data; |
| 84 } | 91 } |
| 85 | 92 |
| 86 void VerifyErrorReportSerialization( | 93 void VerifyErrorReportSerialization( |
| 87 const ErrorReport& report, | 94 const ErrorReport& report, |
| 88 const SSLInfo& ssl_info, | 95 const SSLInfo& ssl_info, |
| 89 std::vector<CertLoggerRequest::CertError> cert_errors) { | 96 std::vector<CertLoggerRequest::CertError> cert_errors) { |
| 90 std::string serialized_report; | 97 std::string serialized_report; |
| 91 ASSERT_TRUE(report.Serialize(&serialized_report)); | 98 ASSERT_TRUE(report.Serialize(&serialized_report)); |
| 92 | 99 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 CertLoggerRequest parsed; | 260 CertLoggerRequest parsed; |
| 254 ASSERT_TRUE(parsed.ParseFromString(serialized_report)); | 261 ASSERT_TRUE(parsed.ParseFromString(serialized_report)); |
| 255 EXPECT_EQ(CertLoggerFeaturesInfo::ANDROID_AIA_FETCHING_ENABLED, | 262 EXPECT_EQ(CertLoggerFeaturesInfo::ANDROID_AIA_FETCHING_ENABLED, |
| 256 parsed.features_info().android_aia_fetching_status()); | 263 parsed.features_info().android_aia_fetching_status()); |
| 257 } | 264 } |
| 258 #endif | 265 #endif |
| 259 | 266 |
| 260 } // namespace | 267 } // namespace |
| 261 | 268 |
| 262 } // namespace certificate_reporting | 269 } // namespace certificate_reporting |
| OLD | NEW |