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/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 class URLRequestContext; | 17 class URLRequestContext; |
18 class SSLInfo; | 18 class SSLInfo; |
19 } | 19 } |
20 | 20 |
21 namespace chrome_browser_net { | 21 namespace chrome_browser_net { |
22 | 22 |
23 class CertLoggerRequest; | |
24 class EncryptedCertLoggerRequest; | 23 class EncryptedCertLoggerRequest; |
25 | 24 |
26 // Provides functionality for sending reports about invalid SSL | 25 // Provides functionality for sending reports about invalid SSL |
27 // certificate chains to a report collection server. | 26 // certificate chains to a report collection server. |
28 class CertificateErrorReporter : public net::URLRequest::Delegate { | 27 class CertificateErrorReporter : public net::URLRequest::Delegate { |
29 public: | 28 public: |
30 // These represent the types of reports that can be sent. | 29 // These represent the types of reports that can be sent. |
31 enum ReportType { | 30 enum ReportType { |
32 // A report of a certificate chain that failed a certificate pinning | 31 // A report of a certificate chain that failed a certificate pinning |
33 // check. | 32 // check. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 // SendReport actually sends the report over the network; callers are | 64 // SendReport actually sends the report over the network; callers are |
66 // responsible for enforcing any preconditions (such as obtaining user | 65 // responsible for enforcing any preconditions (such as obtaining user |
67 // opt-in, only sending reports for certain hostnames, checking for | 66 // opt-in, only sending reports for certain hostnames, checking for |
68 // incognito mode, etc.). | 67 // incognito mode, etc.). |
69 // | 68 // |
70 // On some platforms (but not all), CertificateErrorReporter can use | 69 // On some platforms (but not all), CertificateErrorReporter can use |
71 // an HTTP endpoint to send encrypted extended reporting reports. On | 70 // an HTTP endpoint to send encrypted extended reporting reports. On |
72 // unsupported platforms, callers must send extended reporting reports | 71 // unsupported platforms, callers must send extended reporting reports |
73 // over SSL. | 72 // over SSL. |
74 virtual void SendReport(ReportType type, | 73 virtual void SendReport(ReportType type, |
75 const std::string& hostname, | 74 const std::string& serialized_report); |
eroman
2015/05/12 00:27:51
Please add some description of what serialized_rep
estark
2015/05/12 20:42:15
Done.
| |
76 const net::SSLInfo& ssl_info); | |
77 | 75 |
78 // net::URLRequest::Delegate | 76 // net::URLRequest::Delegate |
79 void OnResponseStarted(net::URLRequest* request) override; | 77 void OnResponseStarted(net::URLRequest* request) override; |
80 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | 78 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
81 | 79 |
82 // Callers can use this method to determine if sending reports over | 80 // Callers can use this method to determine if sending reports over |
83 // HTTP is supported. | 81 // HTTP is supported. |
84 static bool IsHttpUploadUrlSupported(); | 82 static bool IsHttpUploadUrlSupported(); |
85 | 83 |
86 // Used by tests. | 84 // Used by tests. |
87 static bool DecryptCertificateErrorReport( | 85 static bool DecryptCertificateErrorReport( |
88 const uint8 server_private_key[32], | 86 const uint8 server_private_key[32], |
89 const EncryptedCertLoggerRequest& encrypted_report, | 87 const EncryptedCertLoggerRequest& encrypted_report, |
90 CertLoggerRequest* decrypted_report); | 88 std::string* decrypted_serialized_report); |
91 | 89 |
92 private: | 90 private: |
93 // Create a URLRequest with which to send a certificate report to the | 91 // Create a URLRequest with which to send a certificate report to the |
94 // server. | 92 // server. |
95 virtual scoped_ptr<net::URLRequest> CreateURLRequest( | 93 virtual scoped_ptr<net::URLRequest> CreateURLRequest( |
96 net::URLRequestContext* context); | 94 net::URLRequestContext* context); |
97 | 95 |
98 // Serialize and send a CertLoggerRequest protobuf to the report | 96 // Send a serialized report (encrypted or not) to the report |
eroman
2015/05/12 00:27:51
nit: All of these comments should be descriptive "
estark
2015/05/12 20:42:16
Done.
| |
99 // collection server. | 97 // collection server. |
100 void SendCertLoggerRequest(const CertLoggerRequest& request); | |
101 | |
102 void SendSerializedRequest(const std::string& serialized_request); | 98 void SendSerializedRequest(const std::string& serialized_request); |
103 | 99 |
104 // Populate the CertLoggerRequest for a report. | |
105 static void BuildReport(const std::string& hostname, | |
106 const net::SSLInfo& ssl_info, | |
107 CertLoggerRequest* out_request); | |
108 | |
109 // Performs post-report cleanup. | 100 // Performs post-report cleanup. |
110 void RequestComplete(net::URLRequest* request); | 101 void RequestComplete(net::URLRequest* request); |
111 | 102 |
112 net::URLRequestContext* const request_context_; | 103 net::URLRequestContext* const request_context_; |
113 const GURL upload_url_; | 104 const GURL upload_url_; |
114 | 105 |
115 // Owns the contained requests. | 106 // Owns the contained requests. |
116 std::set<net::URLRequest*> inflight_requests_; | 107 std::set<net::URLRequest*> inflight_requests_; |
117 | 108 |
118 CookiesPreference cookies_preference_; | 109 CookiesPreference cookies_preference_; |
119 | 110 |
120 const uint8* server_public_key_; | 111 const uint8* server_public_key_; |
121 const uint32 server_public_key_version_; | 112 const uint32 server_public_key_version_; |
122 | 113 |
123 DISALLOW_COPY_AND_ASSIGN(CertificateErrorReporter); | 114 DISALLOW_COPY_AND_ASSIGN(CertificateErrorReporter); |
124 }; | 115 }; |
125 | 116 |
126 } // namespace chrome_browser_net | 117 } // namespace chrome_browser_net |
127 | 118 |
128 #endif // CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ | 119 #endif // CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ |
OLD | NEW |