| 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 "chrome/browser/ssl/certificate_error_report.h" | 5 #include "chrome/browser/ssl/certificate_error_report.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string_util.h" | |
| 11 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 12 #include "chrome/browser/ssl/cert_logger.pb.h" | 11 #include "chrome/browser/ssl/cert_logger.pb.h" |
| 13 #include "net/cert/cert_status_flags.h" | 12 #include "net/cert/cert_status_flags.h" |
| 14 #include "net/cert/x509_certificate.h" | 13 #include "net/cert/x509_certificate.h" |
| 15 #include "net/ssl/ssl_info.h" | 14 #include "net/ssl/ssl_info.h" |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 void AddCertStatusToReportErrors(net::CertStatus cert_status, | 18 void AddCertStatusToReportErrors(net::CertStatus cert_status, |
| 20 CertLoggerRequest* report) { | 19 CertLoggerRequest* report) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 42 if (cert_status & net::CERT_STATUS_DATE_INVALID) | 41 if (cert_status & net::CERT_STATUS_DATE_INVALID) |
| 43 report->add_cert_error(CertLoggerRequest::ERR_CERT_DATE_INVALID); | 42 report->add_cert_error(CertLoggerRequest::ERR_CERT_DATE_INVALID); |
| 44 if (cert_status & net::CERT_STATUS_VALIDITY_TOO_LONG) | 43 if (cert_status & net::CERT_STATUS_VALIDITY_TOO_LONG) |
| 45 report->add_cert_error(CertLoggerRequest::ERR_CERT_VALIDITY_TOO_LONG); | 44 report->add_cert_error(CertLoggerRequest::ERR_CERT_VALIDITY_TOO_LONG); |
| 46 if (cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) | 45 if (cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) |
| 47 report->add_cert_error( | 46 report->add_cert_error( |
| 48 CertLoggerRequest::ERR_CERT_UNABLE_TO_CHECK_REVOCATION); | 47 CertLoggerRequest::ERR_CERT_UNABLE_TO_CHECK_REVOCATION); |
| 49 if (cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) | 48 if (cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) |
| 50 report->add_cert_error(CertLoggerRequest::ERR_CERT_NO_REVOCATION_MECHANISM); | 49 report->add_cert_error(CertLoggerRequest::ERR_CERT_NO_REVOCATION_MECHANISM); |
| 51 } | 50 } |
| 52 | |
| 53 bool CertificateChainToString(scoped_refptr<net::X509Certificate> cert, | |
| 54 std::string* result) { | |
| 55 std::vector<std::string> pem_encoded_chain; | |
| 56 if (!cert->GetPEMEncodedChain(&pem_encoded_chain)) | |
| 57 return false; | |
| 58 | |
| 59 *result = JoinString(pem_encoded_chain, std::string()); | |
| 60 return true; | |
| 61 } | |
| 62 | |
| 63 } // namespace | 51 } // namespace |
| 64 | 52 |
| 65 CertificateErrorReport::CertificateErrorReport() | 53 CertificateErrorReport::CertificateErrorReport() |
| 66 : cert_report_(new CertLoggerRequest()) { | 54 : cert_report_(new CertLoggerRequest()) { |
| 67 } | 55 } |
| 68 | 56 |
| 69 CertificateErrorReport::CertificateErrorReport(const std::string& hostname, | 57 CertificateErrorReport::CertificateErrorReport(const std::string& hostname, |
| 70 const net::SSLInfo& ssl_info) | 58 const net::SSLInfo& ssl_info) |
| 71 : cert_report_(new CertLoggerRequest()) { | 59 : cert_report_(new CertLoggerRequest()) { |
| 72 base::Time now = base::Time::Now(); | 60 base::Time now = base::Time::Now(); |
| 73 cert_report_->set_time_usec(now.ToInternalValue()); | 61 cert_report_->set_time_usec(now.ToInternalValue()); |
| 74 cert_report_->set_hostname(hostname); | 62 cert_report_->set_hostname(hostname); |
| 75 | 63 |
| 76 if (!CertificateChainToString(ssl_info.cert, | 64 std::vector<std::string> pem_encoded_chain; |
| 77 cert_report_->mutable_cert_chain())) { | 65 if (!ssl_info.cert->GetPEMEncodedChain(&pem_encoded_chain)) { |
| 78 LOG(ERROR) << "Could not get PEM encoded chain."; | 66 LOG(ERROR) << "Could not get PEM encoded chain."; |
| 79 } | 67 } |
| 80 | 68 |
| 81 if (ssl_info.unverified_cert && | 69 std::string* cert_chain = cert_report_->mutable_cert_chain(); |
| 82 !CertificateChainToString( | 70 for (size_t i = 0; i < pem_encoded_chain.size(); ++i) |
| 83 ssl_info.unverified_cert, | 71 cert_chain->append(pem_encoded_chain[i]); |
| 84 cert_report_->mutable_unverified_cert_chain())) { | |
| 85 LOG(ERROR) << "Could not get PEM encoded unverified certificate chain."; | |
| 86 } | |
| 87 | 72 |
| 88 cert_report_->add_pin(ssl_info.pinning_failure_log); | 73 cert_report_->add_pin(ssl_info.pinning_failure_log); |
| 89 | 74 |
| 90 AddCertStatusToReportErrors(ssl_info.cert_status, cert_report_.get()); | 75 AddCertStatusToReportErrors(ssl_info.cert_status, cert_report_.get()); |
| 91 } | 76 } |
| 92 | 77 |
| 93 CertificateErrorReport::~CertificateErrorReport() { | 78 CertificateErrorReport::~CertificateErrorReport() { |
| 94 } | 79 } |
| 95 | 80 |
| 96 bool CertificateErrorReport::InitializeFromString( | 81 bool CertificateErrorReport::InitializeFromString( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 124 break; | 109 break; |
| 125 } | 110 } |
| 126 | 111 |
| 127 interstitial_info->set_user_proceeded(proceed_decision == USER_PROCEEDED); | 112 interstitial_info->set_user_proceeded(proceed_decision == USER_PROCEEDED); |
| 128 interstitial_info->set_overridable(overridable == INTERSTITIAL_OVERRIDABLE); | 113 interstitial_info->set_overridable(overridable == INTERSTITIAL_OVERRIDABLE); |
| 129 } | 114 } |
| 130 | 115 |
| 131 const std::string& CertificateErrorReport::hostname() const { | 116 const std::string& CertificateErrorReport::hostname() const { |
| 132 return cert_report_->hostname(); | 117 return cert_report_->hostname(); |
| 133 } | 118 } |
| OLD | NEW |