| 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; | 23 class CertLoggerRequest; |
| 24 | 24 |
| 25 extern const char kExtendedReportingUploadUrl[]; |
| 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 : public net::URLRequest::Delegate { |
| 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 // Create a certificate error reporter that will send certificate | 41 // Create a certificate error reporter that will send certificate |
| 40 // error reports to |upload_url|, using |request_context| as the | 42 // error reports to |upload_url|, using |request_context| as the |
| 41 // context for the reports. | 43 // context for the reports. |
| 42 CertificateErrorReporter(net::URLRequestContext* request_context, | 44 CertificateErrorReporter(net::URLRequestContext* request_context, |
| 43 const GURL& upload_url); | 45 const GURL& upload_url); |
| 44 | 46 |
| 45 ~CertificateErrorReporter() override; | 47 ~CertificateErrorReporter() override; |
| 46 | 48 |
| 47 // Construct, serialize, and send a certificate reporter to the report | 49 // Construct, serialize, and send a certificate report to the report |
| 48 // collection server containing the |ssl_info| associated with a | 50 // collection server containing the |ssl_info| associated with a |
| 49 // connection to |hostname|. | 51 // connection to |hostname|. |
| 50 virtual void SendReport(ReportType type, | 52 virtual void SendReport(ReportType type, |
| 51 const std::string& hostname, | 53 const std::string& hostname, |
| 52 const net::SSLInfo& ssl_info); | 54 const net::SSLInfo& ssl_info); |
| 53 | 55 |
| 54 // net::URLRequest::Delegate | 56 // net::URLRequest::Delegate |
| 55 void OnResponseStarted(net::URLRequest* request) override; | 57 void OnResponseStarted(net::URLRequest* request) override; |
| 56 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | 58 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
| 57 | 59 |
| 60 protected: |
| 61 enum CookiesPreference { SEND_COOKIES, DO_NOT_SEND_COOKIES }; |
| 62 |
| 58 private: | 63 private: |
| 59 // Create a URLRequest with which to send a certificate report to the | 64 // Create a URLRequest with which to send a certificate report to the |
| 60 // server. | 65 // server. |
| 61 virtual scoped_ptr<net::URLRequest> CreateURLRequest( | 66 virtual scoped_ptr<net::URLRequest> CreateURLRequest( |
| 62 net::URLRequestContext* context); | 67 net::URLRequestContext* context, |
| 68 CookiesPreference cookies_preference); |
| 63 | 69 |
| 64 // Serialize and send a CertLoggerRequest protobuf to the report | 70 // Serialize and send a CertLoggerRequest protobuf to the report |
| 65 // collection server. | 71 // collection server. |
| 66 void SendCertLoggerRequest(const CertLoggerRequest& request); | 72 void SendCertLoggerRequest(ReportType type, const CertLoggerRequest& request); |
| 67 | 73 |
| 68 // Populate the CertLoggerRequest for a report. | 74 // Populate the CertLoggerRequest for a report. |
| 69 static void BuildReport(const std::string& hostname, | 75 static void BuildReport(const std::string& hostname, |
| 70 const net::SSLInfo& ssl_info, | 76 const net::SSLInfo& ssl_info, |
| 71 CertLoggerRequest* out_request); | 77 CertLoggerRequest* out_request); |
| 72 | 78 |
| 73 // Performs post-report cleanup. | 79 // Performs post-report cleanup. |
| 74 void RequestComplete(net::URLRequest* request); | 80 void RequestComplete(net::URLRequest* request); |
| 75 | 81 |
| 76 net::URLRequestContext* const request_context_; | 82 net::URLRequestContext* const request_context_; |
| 77 const GURL upload_url_; | 83 const GURL upload_url_; |
| 78 | 84 |
| 79 // Owns the contained requests. | 85 // Owns the contained requests. |
| 80 std::set<net::URLRequest*> inflight_requests_; | 86 std::set<net::URLRequest*> inflight_requests_; |
| 81 | 87 |
| 82 DISALLOW_COPY_AND_ASSIGN(CertificateErrorReporter); | 88 DISALLOW_COPY_AND_ASSIGN(CertificateErrorReporter); |
| 83 }; | 89 }; |
| 84 | 90 |
| 85 } // namespace chrome_browser_net | 91 } // namespace chrome_browser_net |
| 86 | 92 |
| 87 #endif // CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ | 93 #endif // CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ |
| OLD | NEW |