OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ssl/certificate_error_report.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include "base/stl_util.h" |
| 10 #include "base/time/time.h" |
| 11 #include "net/cert/cert_status_flags.h" |
| 12 #include "net/cert/x509_certificate.h" |
| 13 #include "net/ssl/ssl_info.h" |
| 14 |
| 15 namespace { |
| 16 |
| 17 using chrome_browser_ssl::CertLoggerRequest; |
| 18 |
| 19 void AddCertStatusToReportErrors(net::CertStatus cert_status, |
| 20 CertLoggerRequest* report) { |
| 21 if (cert_status & net::CERT_STATUS_REVOKED) |
| 22 report->add_cert_error(CertLoggerRequest::ERR_CERT_REVOKED); |
| 23 if (cert_status & net::CERT_STATUS_INVALID) |
| 24 report->add_cert_error(CertLoggerRequest::ERR_CERT_INVALID); |
| 25 if (cert_status & net::CERT_STATUS_PINNED_KEY_MISSING) |
| 26 report->add_cert_error( |
| 27 CertLoggerRequest::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN); |
| 28 if (cert_status & net::CERT_STATUS_AUTHORITY_INVALID) |
| 29 report->add_cert_error(CertLoggerRequest::ERR_CERT_AUTHORITY_INVALID); |
| 30 if (cert_status & net::CERT_STATUS_COMMON_NAME_INVALID) |
| 31 report->add_cert_error(CertLoggerRequest::ERR_CERT_COMMON_NAME_INVALID); |
| 32 if (cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) |
| 33 report->add_cert_error(CertLoggerRequest::ERR_CERT_NON_UNIQUE_NAME); |
| 34 if (cert_status & net::CERT_STATUS_NAME_CONSTRAINT_VIOLATION) |
| 35 report->add_cert_error( |
| 36 CertLoggerRequest::ERR_CERT_NAME_CONSTRAINT_VIOLATION); |
| 37 if (cert_status & net::CERT_STATUS_WEAK_SIGNATURE_ALGORITHM) |
| 38 report->add_cert_error( |
| 39 CertLoggerRequest::ERR_CERT_WEAK_SIGNATURE_ALGORITHM); |
| 40 if (cert_status & net::CERT_STATUS_WEAK_KEY) |
| 41 report->add_cert_error(CertLoggerRequest::ERR_CERT_WEAK_KEY); |
| 42 if (cert_status & net::CERT_STATUS_DATE_INVALID) |
| 43 report->add_cert_error(CertLoggerRequest::ERR_CERT_DATE_INVALID); |
| 44 if (cert_status & net::CERT_STATUS_VALIDITY_TOO_LONG) |
| 45 report->add_cert_error(CertLoggerRequest::ERR_CERT_VALIDITY_TOO_LONG); |
| 46 if (cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) |
| 47 report->add_cert_error( |
| 48 CertLoggerRequest::ERR_CERT_UNABLE_TO_CHECK_REVOCATION); |
| 49 if (cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) |
| 50 report->add_cert_error(CertLoggerRequest::ERR_CERT_NO_REVOCATION_MECHANISM); |
| 51 } |
| 52 } // namespace |
| 53 |
| 54 namespace chrome_browser_ssl { |
| 55 |
| 56 CertificateErrorReport::CertificateErrorReport() { |
| 57 } |
| 58 |
| 59 CertificateErrorReport::CertificateErrorReport(const std::string& hostname, |
| 60 const net::SSLInfo& ssl_info) { |
| 61 base::Time now = base::Time::Now(); |
| 62 cert_report_.set_time_usec(now.ToInternalValue()); |
| 63 cert_report_.set_hostname(hostname); |
| 64 |
| 65 std::vector<std::string> pem_encoded_chain; |
| 66 if (!ssl_info.cert->GetPEMEncodedChain(&pem_encoded_chain)) { |
| 67 LOG(ERROR) << "Could not get PEM encoded chain."; |
| 68 } |
| 69 |
| 70 std::string* cert_chain = cert_report_.mutable_cert_chain(); |
| 71 for (size_t i = 0; i < pem_encoded_chain.size(); ++i) |
| 72 cert_chain->append(pem_encoded_chain[i]); |
| 73 |
| 74 cert_report_.add_pin(ssl_info.pinning_failure_log); |
| 75 |
| 76 AddCertStatusToReportErrors(ssl_info.cert_status, &cert_report_); |
| 77 } |
| 78 |
| 79 CertificateErrorReport::~CertificateErrorReport() { |
| 80 } |
| 81 |
| 82 bool CertificateErrorReport::InitializeFromString( |
| 83 const std::string& serialized_report) { |
| 84 return cert_report_.ParseFromString(serialized_report); |
| 85 } |
| 86 |
| 87 bool CertificateErrorReport::Serialize(std::string* output) const { |
| 88 return cert_report_.SerializeToString(output); |
| 89 } |
| 90 |
| 91 const std::string& CertificateErrorReport::hostname() const { |
| 92 return cert_report_.hostname(); |
| 93 } |
| 94 |
| 95 } // namespace chrome_browser_ssl |
OLD | NEW |