summaryrefslogtreecommitdiff
path: root/chromium/components/certificate_reporting
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-01-04 14:17:57 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-01-05 10:05:06 +0000
commit39d357e3248f80abea0159765ff39554affb40db (patch)
treeaba0e6bfb76de0244bba0f5fdbd64b830dd6e621 /chromium/components/certificate_reporting
parent87778abf5a1f89266f37d1321b92a21851d8244d (diff)
downloadqtwebengine-chromium-39d357e3248f80abea0159765ff39554affb40db.tar.gz
BASELINE: Update Chromium to 55.0.2883.105
And updates ninja to 1.7.2 Change-Id: I20d43c737f82764d857ada9a55586901b18b9243 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/components/certificate_reporting')
-rw-r--r--chromium/components/certificate_reporting/BUILD.gn3
-rw-r--r--chromium/components/certificate_reporting/error_reporter.cc25
-rw-r--r--chromium/components/certificate_reporting/error_reporter.h3
-rw-r--r--chromium/components/certificate_reporting/error_reporter_unittest.cc115
4 files changed, 105 insertions, 41 deletions
diff --git a/chromium/components/certificate_reporting/BUILD.gn b/chromium/components/certificate_reporting/BUILD.gn
index d54b2916ccb..eee31993b70 100644
--- a/chromium/components/certificate_reporting/BUILD.gn
+++ b/chromium/components/certificate_reporting/BUILD.gn
@@ -4,7 +4,6 @@
import("//third_party/protobuf/proto_library.gni")
-# GYP version: components/certificate_reporting.gyp:certificate_reporting
static_library("certificate_reporting") {
sources = [
"cert_logger.proto",
@@ -27,14 +26,12 @@ static_library("certificate_reporting") {
]
}
-# GYP version: components/certificate_reporting.gypi:cert_logger_proto
proto_library("cert_logger_proto") {
sources = [
"cert_logger.proto",
]
}
-# GYP version: components/certificate_reporting.gypi:encrypted_cert_logger_proto
proto_library("encrypted_cert_logger_proto") {
sources = [
"encrypted_cert_logger.proto",
diff --git a/chromium/components/certificate_reporting/error_reporter.cc b/chromium/components/certificate_reporting/error_reporter.cc
index a4beff826a7..3e639ea5d70 100644
--- a/chromium/components/certificate_reporting/error_reporter.cc
+++ b/chromium/components/certificate_reporting/error_reporter.cc
@@ -11,6 +11,8 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
+#include "base/metrics/histogram_macros.h"
+#include "base/metrics/sparse_histogram.h"
#include "components/certificate_reporting/encrypted_cert_logger.pb.h"
#include "crypto/aead.h"
#include "crypto/curve25519.h"
@@ -98,6 +100,12 @@ bool EncryptSerializedReport(const uint8_t* server_public_key,
return true;
}
+// Records an UMA histogram of the net errors when certificate reports
+// fail to send.
+void RecordUMAOnFailure(const GURL& report_uri, int net_error) {
+ UMA_HISTOGRAM_SPARSE_SLOWLY("SSL.CertificateErrorReportFailure", -net_error);
+}
+
} // namespace
ErrorReporter::ErrorReporter(
@@ -108,8 +116,10 @@ ErrorReporter::ErrorReporter(
upload_url,
kServerPublicKey,
kServerPublicKeyVersion,
- base::WrapUnique(
- new net::ReportSender(request_context, cookies_preference))) {}
+ base::MakeUnique<net::ReportSender>(request_context,
+ cookies_preference,
+ base::Bind(RecordUMAOnFailure))) {
+}
ErrorReporter::ErrorReporter(
const GURL& upload_url,
@@ -129,9 +139,9 @@ ErrorReporter::~ErrorReporter() {}
void ErrorReporter::SendExtendedReportingReport(
const std::string& serialized_report) {
if (upload_url_.SchemeIsCryptographic()) {
- certificate_report_sender_->Send(upload_url_, serialized_report);
+ certificate_report_sender_->Send(upload_url_, "application/octet-stream",
+ serialized_report);
} else {
- DCHECK(IsHttpUploadUrlSupported());
EncryptedCertLoggerRequest encrypted_report;
if (!EncryptSerializedReport(server_public_key_, server_public_key_version_,
serialized_report, &encrypted_report)) {
@@ -140,14 +150,11 @@ void ErrorReporter::SendExtendedReportingReport(
}
std::string serialized_encrypted_report;
encrypted_report.SerializeToString(&serialized_encrypted_report);
- certificate_report_sender_->Send(upload_url_, serialized_encrypted_report);
+ certificate_report_sender_->Send(upload_url_, "application/octet-stream",
+ serialized_encrypted_report);
}
}
-bool ErrorReporter::IsHttpUploadUrlSupported() {
- return true;
-}
-
// Used only by tests.
bool ErrorReporter::DecryptErrorReport(
const uint8_t server_private_key[32],
diff --git a/chromium/components/certificate_reporting/error_reporter.h b/chromium/components/certificate_reporting/error_reporter.h
index ed4a1ee98ac..c4a15d6ef6b 100644
--- a/chromium/components/certificate_reporting/error_reporter.h
+++ b/chromium/components/certificate_reporting/error_reporter.h
@@ -63,9 +63,6 @@ class ErrorReporter {
virtual void SendExtendedReportingReport(
const std::string& serialized_report);
- // Whether sending reports over HTTP is supported.
- static bool IsHttpUploadUrlSupported();
-
// Used by tests.
static bool DecryptErrorReport(
const uint8_t server_private_key[32],
diff --git a/chromium/components/certificate_reporting/error_reporter_unittest.cc b/chromium/components/certificate_reporting/error_reporter_unittest.cc
index 5de9737c07a..6e83ca165be 100644
--- a/chromium/components/certificate_reporting/error_reporter_unittest.cc
+++ b/chromium/components/certificate_reporting/error_reporter_unittest.cc
@@ -14,9 +14,14 @@
#include "base/bind_helpers.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/test/histogram_tester.h"
#include "components/certificate_reporting/encrypted_cert_logger.pb.h"
#include "crypto/curve25519.h"
+#include "net/test/url_request/url_request_failed_job.h"
#include "net/url_request/report_sender.h"
+#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace certificate_reporting {
@@ -27,6 +32,7 @@ const char kDummyHttpReportUri[] = "http://example.test";
const char kDummyHttpsReportUri[] = "https://example.test";
const char kDummyReport[] = "a dummy report";
const uint32_t kServerPublicKeyTestVersion = 16;
+const char kFailureHistogramName[] = "SSL.CertificateErrorReportFailure";
// A mock ReportSender that keeps track of the last report
// sent.
@@ -36,22 +42,50 @@ class MockCertificateReportSender : public net::ReportSender {
: net::ReportSender(nullptr, DO_NOT_SEND_COOKIES) {}
~MockCertificateReportSender() override {}
- void Send(const GURL& report_uri, const std::string& report) override {
+ void Send(const GURL& report_uri,
+ base::StringPiece content_type,
+ base::StringPiece report) override {
latest_report_uri_ = report_uri;
- latest_report_ = report;
+ report.CopyToString(&latest_report_);
+ content_type.CopyToString(&latest_content_type_);
}
const GURL& latest_report_uri() { return latest_report_uri_; }
const std::string& latest_report() { return latest_report_; }
+ const std::string& latest_content_type() { return latest_content_type_; }
+
private:
GURL latest_report_uri_;
std::string latest_report_;
+ std::string latest_content_type_;
DISALLOW_COPY_AND_ASSIGN(MockCertificateReportSender);
};
+// A test network delegate that allows the user to specify a callback to
+// be run whenever a net::URLRequest is destroyed.
+class TestCertificateReporterNetworkDelegate : public net::NetworkDelegateImpl {
+ public:
+ TestCertificateReporterNetworkDelegate()
+ : url_request_destroyed_callback_(base::Bind(&base::DoNothing)) {}
+
+ void set_url_request_destroyed_callback(const base::Closure& callback) {
+ url_request_destroyed_callback_ = callback;
+ }
+
+ // net::NetworkDelegateImpl:
+ void OnURLRequestDestroyed(net::URLRequest* request) override {
+ url_request_destroyed_callback_.Run();
+ }
+
+ private:
+ base::Closure url_request_destroyed_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestCertificateReporterNetworkDelegate);
+};
+
class ErrorReporterTest : public ::testing::Test {
public:
ErrorReporterTest() {
@@ -62,8 +96,11 @@ class ErrorReporterTest : public ::testing::Test {
~ErrorReporterTest() override {}
protected:
+ base::MessageLoopForIO loop_;
uint8_t server_public_key_[32];
uint8_t server_private_key_[32];
+
+ DISALLOW_COPY_AND_ASSIGN(ErrorReporterTest);
};
// Test that ErrorReporter::SendExtendedReportingReport sends
@@ -81,30 +118,56 @@ TEST_F(ErrorReporterTest, ExtendedReportingSendReport) {
EXPECT_EQ(mock_report_sender->latest_report(), kDummyReport);
// Data should be encrypted when sent to an HTTP URL.
- if (ErrorReporter::IsHttpUploadUrlSupported()) {
- MockCertificateReportSender* http_mock_report_sender =
- new MockCertificateReportSender();
- GURL http_url(kDummyHttpReportUri);
- ErrorReporter http_reporter(http_url, server_public_key_,
- kServerPublicKeyTestVersion,
- base::WrapUnique(http_mock_report_sender));
- http_reporter.SendExtendedReportingReport(kDummyReport);
-
- EXPECT_EQ(http_mock_report_sender->latest_report_uri(), http_url);
-
- std::string uploaded_report;
- EncryptedCertLoggerRequest encrypted_request;
- ASSERT_TRUE(encrypted_request.ParseFromString(
- http_mock_report_sender->latest_report()));
- EXPECT_EQ(kServerPublicKeyTestVersion,
- encrypted_request.server_public_key_version());
- EXPECT_EQ(EncryptedCertLoggerRequest::AEAD_ECDH_AES_128_CTR_HMAC_SHA256,
- encrypted_request.algorithm());
- ASSERT_TRUE(ErrorReporter::DecryptErrorReport(
- server_private_key_, encrypted_request, &uploaded_report));
-
- EXPECT_EQ(kDummyReport, uploaded_report);
- }
+ MockCertificateReportSender* http_mock_report_sender =
+ new MockCertificateReportSender();
+ GURL http_url(kDummyHttpReportUri);
+ ErrorReporter http_reporter(http_url, server_public_key_,
+ kServerPublicKeyTestVersion,
+ base::WrapUnique(http_mock_report_sender));
+ http_reporter.SendExtendedReportingReport(kDummyReport);
+
+ EXPECT_EQ(http_mock_report_sender->latest_report_uri(), http_url);
+ EXPECT_EQ("application/octet-stream",
+ http_mock_report_sender->latest_content_type());
+
+ std::string uploaded_report;
+ EncryptedCertLoggerRequest encrypted_request;
+ ASSERT_TRUE(encrypted_request.ParseFromString(
+ http_mock_report_sender->latest_report()));
+ EXPECT_EQ(kServerPublicKeyTestVersion,
+ encrypted_request.server_public_key_version());
+ EXPECT_EQ(EncryptedCertLoggerRequest::AEAD_ECDH_AES_128_CTR_HMAC_SHA256,
+ encrypted_request.algorithm());
+ ASSERT_TRUE(ErrorReporter::DecryptErrorReport(
+ server_private_key_, encrypted_request, &uploaded_report));
+
+ EXPECT_EQ(kDummyReport, uploaded_report);
+}
+
+// Tests that an UMA histogram is recorded if a report fails to send.
+TEST_F(ErrorReporterTest, UMAOnFailure) {
+ net::URLRequestFailedJob::AddUrlHandler();
+
+ base::HistogramTester histograms;
+ histograms.ExpectTotalCount(kFailureHistogramName, 0);
+
+ base::RunLoop run_loop;
+ net::TestURLRequestContext context(true);
+ TestCertificateReporterNetworkDelegate test_delegate;
+ test_delegate.set_url_request_destroyed_callback(run_loop.QuitClosure());
+ context.set_network_delegate(&test_delegate);
+ context.Init();
+
+ GURL report_uri(
+ net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_FAILED));
+ ErrorReporter reporter(&context, report_uri,
+ net::ReportSender::DO_NOT_SEND_COOKIES);
+ reporter.SendExtendedReportingReport(kDummyReport);
+ run_loop.Run();
+
+ histograms.ExpectTotalCount(kFailureHistogramName, 1);
+ histograms.ExpectBucketCount(kFailureHistogramName,
+ -net::ERR_CONNECTION_FAILED, 1);
}
// This test decrypts a "known gold" report. It's intentionally brittle