| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chrome_expect_ct_reporter.h" | 5 #include "chrome/browser/ssl/chrome_expect_ct_reporter.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/metrics/sparse_histogram.h" |
| 13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 15 #include "base/values.h" | 17 #include "base/values.h" |
| 16 #include "chrome/common/chrome_features.h" | 18 #include "chrome/common/chrome_features.h" |
| 17 #include "net/url_request/certificate_report_sender.h" | 19 #include "net/url_request/certificate_report_sender.h" |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 std::string TimeToISO8601(const base::Time& t) { | 23 std::string TimeToISO8601(const base::Time& t) { |
| 22 base::Time::Exploded exploded; | 24 base::Time::Exploded exploded; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 base::Base64Encode(sct_and_status.sct->extensions, &extensions); | 96 base::Base64Encode(sct_and_status.sct->extensions, &extensions); |
| 95 sct->SetString("extensions", extensions); | 97 sct->SetString("extensions", extensions); |
| 96 std::string signature; | 98 std::string signature; |
| 97 base::Base64Encode(sct_and_status.sct->signature.signature_data, &signature); | 99 base::Base64Encode(sct_and_status.sct->signature.signature_data, &signature); |
| 98 sct->SetString("signature", signature); | 100 sct->SetString("signature", signature); |
| 99 | 101 |
| 100 list_item->Set("sct", std::move(sct)); | 102 list_item->Set("sct", std::move(sct)); |
| 101 list->Append(std::move(list_item)); | 103 list->Append(std::move(list_item)); |
| 102 } | 104 } |
| 103 | 105 |
| 106 // Records an UMA histogram of the net errors when Expect CT reports |
| 107 // fails to send. |
| 108 void RecordUMAOnFailure(const GURL& report_uri, int net_error) { |
| 109 UMA_HISTOGRAM_SPARSE_SLOWLY("SSL.ExpectCTReportFailure", net_error); |
| 110 } |
| 111 |
| 104 } // namespace | 112 } // namespace |
| 105 | 113 |
| 106 ChromeExpectCTReporter::ChromeExpectCTReporter( | 114 ChromeExpectCTReporter::ChromeExpectCTReporter( |
| 107 net::URLRequestContext* request_context) | 115 net::URLRequestContext* request_context) |
| 108 : report_sender_(new net::CertificateReportSender( | 116 : report_sender_(new net::CertificateReportSender( |
| 109 request_context, | 117 request_context, |
| 110 net::CertificateReportSender::DO_NOT_SEND_COOKIES)) {} | 118 net::CertificateReportSender::DO_NOT_SEND_COOKIES, |
| 119 base::Bind(RecordUMAOnFailure))) {} |
| 111 | 120 |
| 112 ChromeExpectCTReporter::~ChromeExpectCTReporter() {} | 121 ChromeExpectCTReporter::~ChromeExpectCTReporter() {} |
| 113 | 122 |
| 114 void ChromeExpectCTReporter::OnExpectCTFailed( | 123 void ChromeExpectCTReporter::OnExpectCTFailed( |
| 115 const net::HostPortPair& host_port_pair, | 124 const net::HostPortPair& host_port_pair, |
| 116 const GURL& report_uri, | 125 const GURL& report_uri, |
| 117 const net::SSLInfo& ssl_info) { | 126 const net::SSLInfo& ssl_info) { |
| 118 if (report_uri.is_empty()) | 127 if (report_uri.is_empty()) |
| 119 return; | 128 return; |
| 120 | 129 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 report.Set("valid-scts", std::move(valid_scts)); | 167 report.Set("valid-scts", std::move(valid_scts)); |
| 159 | 168 |
| 160 std::string serialized_report; | 169 std::string serialized_report; |
| 161 if (!base::JSONWriter::Write(report, &serialized_report)) { | 170 if (!base::JSONWriter::Write(report, &serialized_report)) { |
| 162 LOG(ERROR) << "Failed to serialize Expect CT report"; | 171 LOG(ERROR) << "Failed to serialize Expect CT report"; |
| 163 return; | 172 return; |
| 164 } | 173 } |
| 165 | 174 |
| 166 report_sender_->Send(report_uri, serialized_report); | 175 report_sender_->Send(report_uri, serialized_report); |
| 167 } | 176 } |
| OLD | NEW |