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.
5 #ifndef CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_
6 #define CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "net/url_request/certificate_report_sender.h"
17 class URLRequestContext
;
21 namespace chrome_browser_net
{
23 class EncryptedCertLoggerRequest
;
25 // Provides functionality for sending reports about invalid SSL
26 // certificate chains to a report collection server.
27 class CertificateErrorReporter
{
29 // These represent the types of reports that can be sent.
31 // A report of a certificate chain that failed a certificate pinning
33 REPORT_TYPE_PINNING_VIOLATION
,
34 // A report for an invalid certificate chain that is being sent for
35 // a user who has opted-in to the extended reporting program.
36 REPORT_TYPE_EXTENDED_REPORTING
39 // Creates a certificate error reporter that will send certificate
40 // error reports to |upload_url|, using |request_context| as the
41 // context for the reports. |cookies_preference| controls whether
42 // cookies will be sent along with the reports.
43 CertificateErrorReporter(
44 net::URLRequestContext
* request_context
,
45 const GURL
& upload_url
,
46 net::CertificateReportSender::CookiesPreference cookies_preference
);
48 // Allows tests to use a server public key with known private key and
49 // a mock CertificateReportSender.
50 CertificateErrorReporter(
51 const GURL
& upload_url
,
52 const uint8 server_public_key
[32],
53 const uint32 server_public_key_version
,
54 scoped_ptr
<net::CertificateReportSender
> certificate_report_sender
);
56 virtual ~CertificateErrorReporter();
58 // Sends a certificate report to the report collection server. The
59 // |serialized_report| is expected to be a serialized protobuf
60 // containing information about the hostname, certificate chain, and
61 // certificate errors encountered when validating the chain.
63 // |SendReport| actually sends the report over the network; callers are
64 // responsible for enforcing any preconditions (such as obtaining user
65 // opt-in, only sending reports for certain hostnames, checking for
66 // incognito mode, etc.).
68 // On some platforms (but not all), CertificateErrorReporter can use
69 // an HTTP endpoint to send encrypted extended reporting reports. On
70 // unsupported platforms, callers must send extended reporting reports
72 virtual void SendReport(ReportType type
,
73 const std::string
& serialized_report
);
75 // Callers can use this method to determine if sending reports over
77 static bool IsHttpUploadUrlSupported();
79 #if defined(USE_OPENSSL)
81 static bool DecryptCertificateErrorReport(
82 const uint8 server_private_key
[32],
83 const EncryptedCertLoggerRequest
& encrypted_report
,
84 std::string
* decrypted_serialized_report
);
88 scoped_ptr
<net::CertificateReportSender
> certificate_report_sender_
;
90 const GURL upload_url_
;
92 const uint8
* server_public_key_
;
93 const uint32 server_public_key_version_
;
95 DISALLOW_COPY_AND_ASSIGN(CertificateErrorReporter
);
98 } // namespace chrome_browser_net
100 #endif // CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_