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 #ifndef CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ | 5 #ifndef CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ |
6 #define CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ | 6 #define CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "net/http/certificate_report_sender.h" | |
14 #include "net/http/certificate_report_sender_impl.h" | |
13 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
14 #include "url/gurl.h" | 16 #include "url/gurl.h" |
15 | 17 |
16 namespace net { | 18 namespace net { |
17 class URLRequestContext; | 19 class URLRequestContext; |
18 class SSLInfo; | 20 class SSLInfo; |
19 } | 21 } |
20 | 22 |
21 namespace chrome_browser_net { | 23 namespace chrome_browser_net { |
22 | 24 |
23 class EncryptedCertLoggerRequest; | 25 class EncryptedCertLoggerRequest; |
24 | 26 |
25 // Provides functionality for sending reports about invalid SSL | 27 // Provides functionality for sending reports about invalid SSL |
26 // certificate chains to a report collection server. | 28 // certificate chains to a report collection server. |
27 class CertificateErrorReporter : public net::URLRequest::Delegate { | 29 class CertificateErrorReporter { |
28 public: | 30 public: |
29 // These represent the types of reports that can be sent. | 31 // These represent the types of reports that can be sent. |
30 enum ReportType { | 32 enum ReportType { |
31 // A report of a certificate chain that failed a certificate pinning | 33 // A report of a certificate chain that failed a certificate pinning |
32 // check. | 34 // check. |
33 REPORT_TYPE_PINNING_VIOLATION, | 35 REPORT_TYPE_PINNING_VIOLATION, |
34 // A report for an invalid certificate chain that is being sent for | 36 // A report for an invalid certificate chain that is being sent for |
35 // a user who has opted-in to the extended reporting program. | 37 // a user who has opted-in to the extended reporting program. |
36 REPORT_TYPE_EXTENDED_REPORTING | 38 REPORT_TYPE_EXTENDED_REPORTING |
37 }; | 39 }; |
38 | 40 |
39 // Represents whether or not to send cookies along with reports sent | |
40 // to the server. | |
41 enum CookiesPreference { SEND_COOKIES, DO_NOT_SEND_COOKIES }; | |
42 | |
43 // Creates a certificate error reporter that will send certificate | 41 // Creates a certificate error reporter that will send certificate |
44 // error reports to |upload_url|, using |request_context| as the | 42 // error reports to |upload_url|, using |request_context| as the |
45 // context for the reports. |cookies_preference| controls whether | 43 // context for the reports. |cookies_preference| controls whether |
46 // cookies will be sent along with the reports. | 44 // cookies will be sent along with the reports. |
47 CertificateErrorReporter(net::URLRequestContext* request_context, | 45 CertificateErrorReporter( |
48 const GURL& upload_url, | 46 net::URLRequestContext* request_context, |
49 CookiesPreference cookies_preference); | 47 const GURL& upload_url, |
48 net::CertificateReportSenderImpl::CookiesPreference cookies_preference); | |
50 | 49 |
51 // Allows tests to use a server public key with known private key. | 50 // Allows tests to use a server public key with known private key and |
52 CertificateErrorReporter(net::URLRequestContext* request_context, | 51 // a mock CertificateReportSender. |
53 const GURL& upload_url, | 52 CertificateErrorReporter( |
54 CookiesPreference cookies_preference, | 53 const GURL& upload_url, |
55 const uint8 server_public_key[32], | 54 const uint8 server_public_key[32], |
56 const uint32 server_public_key_version); | 55 const uint32 server_public_key_version, |
56 scoped_ptr<net::CertificateReportSender> certificate_report_sender); | |
57 | 57 |
58 ~CertificateErrorReporter() override; | 58 virtual ~CertificateErrorReporter(); |
59 | 59 |
60 // Sends a certificate report to the report collection server. The | 60 // Sends a certificate report to the report collection server. The |
61 // |serialized_report| is expected to be a serialized protobuf | 61 // |serialized_report| is expected to be a serialized protobuf |
62 // containing information about the hostname, certificate chain, and | 62 // containing information about the hostname, certificate chain, and |
63 // certificate errors encountered when validating the chain. | 63 // certificate errors encountered when validating the chain. |
64 // | 64 // |
65 // |SendReport| actually sends the report over the network; callers are | 65 // |SendReport| actually sends the report over the network; callers are |
66 // responsible for enforcing any preconditions (such as obtaining user | 66 // responsible for enforcing any preconditions (such as obtaining user |
67 // opt-in, only sending reports for certain hostnames, checking for | 67 // opt-in, only sending reports for certain hostnames, checking for |
68 // incognito mode, etc.). | 68 // incognito mode, etc.). |
69 // | 69 // |
70 // On some platforms (but not all), CertificateErrorReporter can use | 70 // On some platforms (but not all), CertificateErrorReporter can use |
71 // an HTTP endpoint to send encrypted extended reporting reports. On | 71 // an HTTP endpoint to send encrypted extended reporting reports. On |
72 // unsupported platforms, callers must send extended reporting reports | 72 // unsupported platforms, callers must send extended reporting reports |
73 // over SSL. | 73 // over SSL. |
74 virtual void SendReport(ReportType type, | 74 virtual void SendReport(ReportType type, |
75 const std::string& serialized_report); | 75 const std::string& serialized_report); |
76 | 76 |
77 // net::URLRequest::Delegate | |
78 void OnResponseStarted(net::URLRequest* request) override; | |
79 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | |
80 | |
81 // Callers can use this method to determine if sending reports over | 77 // Callers can use this method to determine if sending reports over |
82 // HTTP is supported. | 78 // HTTP is supported. |
83 static bool IsHttpUploadUrlSupported(); | 79 static bool IsHttpUploadUrlSupported(); |
84 | 80 |
85 // Used by tests. | 81 // Used by tests. |
86 static bool DecryptCertificateErrorReport( | 82 static bool DecryptCertificateErrorReport( |
davidben
2015/07/23 00:09:41
(Existing and soon to be irrelevant, but this prob
estark
2015/07/23 02:41:21
Done.
| |
87 const uint8 server_private_key[32], | 83 const uint8 server_private_key[32], |
88 const EncryptedCertLoggerRequest& encrypted_report, | 84 const EncryptedCertLoggerRequest& encrypted_report, |
89 std::string* decrypted_serialized_report); | 85 std::string* decrypted_serialized_report); |
90 | 86 |
91 private: | 87 private: |
92 // Creates a URLRequest with which to send a certificate report to the | 88 scoped_ptr<net::CertificateReportSender> certificate_report_sender_; |
93 // server. | |
94 virtual scoped_ptr<net::URLRequest> CreateURLRequest( | |
95 net::URLRequestContext* context); | |
96 | 89 |
97 // Sends a serialized report (encrypted or not) to the report | |
98 // collection server. | |
99 void SendSerializedRequest(const std::string& serialized_request); | |
100 | |
101 // Performs post-report cleanup. | |
102 void RequestComplete(net::URLRequest* request); | |
103 | |
104 net::URLRequestContext* const request_context_; | |
105 const GURL upload_url_; | 90 const GURL upload_url_; |
106 | 91 |
107 // Owns the contained requests. | |
108 std::set<net::URLRequest*> inflight_requests_; | |
109 | |
110 CookiesPreference cookies_preference_; | |
111 | |
112 const uint8* server_public_key_; | 92 const uint8* server_public_key_; |
113 const uint32 server_public_key_version_; | 93 const uint32 server_public_key_version_; |
114 | 94 |
115 DISALLOW_COPY_AND_ASSIGN(CertificateErrorReporter); | 95 DISALLOW_COPY_AND_ASSIGN(CertificateErrorReporter); |
116 }; | 96 }; |
117 | 97 |
118 } // namespace chrome_browser_net | 98 } // namespace chrome_browser_net |
119 | 99 |
120 #endif // CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ | 100 #endif // CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ |
OLD | NEW |