diff options
author | jbroman <jbroman@chromium.org> | 2015-09-04 21:30:09 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-05 04:31:02 +0000 |
commit | 782fdafb6dcdbbc8221ef82f032e92de1d342237 (patch) | |
tree | a0794960b0c84c1c710bcef19b7a6617d75702fc /chrome/browser/ssl/certificate_error_report.cc | |
parent | c249c9597b460a38507953a901942f4c09499c99 (diff) | |
download | chromium_src-782fdafb6dcdbbc8221ef82f032e92de1d342237.zip chromium_src-782fdafb6dcdbbc8221ef82f032e92de1d342237.tar.gz chromium_src-782fdafb6dcdbbc8221ef82f032e92de1d342237.tar.bz2 |
Revert of Componentize CertificateErrorReport and CertificateErrorReporter (patchset #12 id:210001 of https://codereview.chromium.org/1302423003/ )
Reason for revert:
Speculative revert to fix:
http://build.chromium.org/p/chromium.mac/builders/iOS_Device/builds/19626
http://build.chromium.org/p/chromium.mac/builders/iOS_Simulator_(dbg)
Original issue's description:
> Componentize CertificateErrorReport and CertificateErrorReporter
>
> BUG=516697
>
> Committed: https://crrev.com/93df64e3cdc40d6a30f7944e211e334ce1880cf7
> Cr-Commit-Position: refs/heads/master@{#347551}
TBR=droger@chromium.org,felt@chromium.org,blundell@chromium.org,mattm@chromium.org,thestig@chromium.org,davidben@chromium.org,estark@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=516697
Review URL: https://codereview.chromium.org/1332473002
Cr-Commit-Position: refs/heads/master@{#347555}
Diffstat (limited to 'chrome/browser/ssl/certificate_error_report.cc')
-rw-r--r-- | chrome/browser/ssl/certificate_error_report.cc | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/chrome/browser/ssl/certificate_error_report.cc b/chrome/browser/ssl/certificate_error_report.cc new file mode 100644 index 0000000..49ca918 --- /dev/null +++ b/chrome/browser/ssl/certificate_error_report.cc @@ -0,0 +1,124 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ssl/certificate_error_report.h" + +#include <vector> + +#include "base/stl_util.h" +#include "base/strings/string_util.h" +#include "base/time/time.h" +#include "chrome/browser/ssl/cert_logger.pb.h" +#include "net/cert/cert_status_flags.h" +#include "net/cert/x509_certificate.h" +#include "net/ssl/ssl_info.h" + +namespace { + +void AddCertStatusToReportErrors(net::CertStatus cert_status, + CertLoggerRequest* report) { +#define COPY_CERT_STATUS(error) RENAME_CERT_STATUS(error, CERT_##error) +#define RENAME_CERT_STATUS(status_error, logger_error) \ + if (cert_status & net::CERT_STATUS_##status_error) \ + report->add_cert_error(CertLoggerRequest::ERR_##logger_error); + + COPY_CERT_STATUS(REVOKED) + COPY_CERT_STATUS(INVALID) + RENAME_CERT_STATUS(PINNED_KEY_MISSING, SSL_PINNED_KEY_NOT_IN_CERT_CHAIN) + COPY_CERT_STATUS(AUTHORITY_INVALID) + COPY_CERT_STATUS(COMMON_NAME_INVALID) + COPY_CERT_STATUS(NON_UNIQUE_NAME) + COPY_CERT_STATUS(NAME_CONSTRAINT_VIOLATION) + COPY_CERT_STATUS(WEAK_SIGNATURE_ALGORITHM) + COPY_CERT_STATUS(WEAK_KEY) + COPY_CERT_STATUS(DATE_INVALID) + COPY_CERT_STATUS(VALIDITY_TOO_LONG) + COPY_CERT_STATUS(UNABLE_TO_CHECK_REVOCATION) + COPY_CERT_STATUS(NO_REVOCATION_MECHANISM) + +#undef RENAME_CERT_STATUS +#undef COPY_CERT_STATUS +} + +bool CertificateChainToString(scoped_refptr<net::X509Certificate> cert, + std::string* result) { + std::vector<std::string> pem_encoded_chain; + if (!cert->GetPEMEncodedChain(&pem_encoded_chain)) + return false; + + *result = base::JoinString(pem_encoded_chain, ""); + return true; +} + +} // namespace + +CertificateErrorReport::CertificateErrorReport() + : cert_report_(new CertLoggerRequest()) { +} + +CertificateErrorReport::CertificateErrorReport(const std::string& hostname, + const net::SSLInfo& ssl_info) + : cert_report_(new CertLoggerRequest()) { + base::Time now = base::Time::Now(); + cert_report_->set_time_usec(now.ToInternalValue()); + cert_report_->set_hostname(hostname); + + if (!CertificateChainToString(ssl_info.cert, + cert_report_->mutable_cert_chain())) { + LOG(ERROR) << "Could not get PEM encoded chain."; + } + + if (ssl_info.unverified_cert && + !CertificateChainToString( + ssl_info.unverified_cert, + cert_report_->mutable_unverified_cert_chain())) { + LOG(ERROR) << "Could not get PEM encoded unverified certificate chain."; + } + + cert_report_->add_pin(ssl_info.pinning_failure_log); + + AddCertStatusToReportErrors(ssl_info.cert_status, cert_report_.get()); +} + +CertificateErrorReport::~CertificateErrorReport() { +} + +bool CertificateErrorReport::InitializeFromString( + const std::string& serialized_report) { + return cert_report_->ParseFromString(serialized_report); +} + +bool CertificateErrorReport::Serialize(std::string* output) const { + return cert_report_->SerializeToString(output); +} + +void CertificateErrorReport::SetInterstitialInfo( + const InterstitialReason& interstitial_reason, + const ProceedDecision& proceed_decision, + const Overridable& overridable) { + CertLoggerInterstitialInfo* interstitial_info = + cert_report_->mutable_interstitial_info(); + + switch (interstitial_reason) { + case INTERSTITIAL_SSL: + interstitial_info->set_interstitial_reason( + CertLoggerInterstitialInfo::INTERSTITIAL_SSL); + break; + case INTERSTITIAL_CAPTIVE_PORTAL: + interstitial_info->set_interstitial_reason( + CertLoggerInterstitialInfo::INTERSTITIAL_CAPTIVE_PORTAL); + break; + case INTERSTITIAL_CLOCK: + interstitial_info->set_interstitial_reason( + CertLoggerInterstitialInfo::INTERSTITIAL_CLOCK); + break; + } + + interstitial_info->set_user_proceeded(proceed_decision == USER_PROCEEDED); + interstitial_info->set_overridable(overridable == INTERSTITIAL_OVERRIDABLE); +} + +const std::string& CertificateErrorReport::hostname() const { + return cert_report_->hostname(); +} |