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/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 namespace net { | 17 namespace net { |
17 class URLRequestContext; | 18 class URLRequestContext; |
18 class SSLInfo; | 19 class SSLInfo; |
19 } | 20 } |
20 | 21 |
21 namespace chrome_browser_net { | 22 namespace chrome_browser_net { |
22 | 23 |
23 class CertLoggerRequest; | 24 class CertLoggerRequest; |
24 | 25 |
26 extern const char kExtendedReportingUploadUrl[]; | |
27 | |
25 // Provides functionality for sending reports about invalid SSL | 28 // Provides functionality for sending reports about invalid SSL |
26 // certificate chains to a report collection server. | 29 // certificate chains to a report collection server. |
27 class CertificateErrorReporter : public net::URLRequest::Delegate { | 30 class CertificateErrorReporter |
31 : public net::URLRequest::Delegate, | |
32 public base::RefCountedThreadSafe<CertificateErrorReporter> { | |
Ryan Sleevi
2015/03/14 03:09:42
Definitely don't want to do this
estark
2015/03/16 23:40:52
Done.
| |
28 public: | 33 public: |
29 // These represent the types of reports that can be sent. | 34 // These represent the types of reports that can be sent. |
30 enum ReportType { | 35 enum ReportType { |
31 // A report of a certificate chain that failed a certificate pinning | 36 // A report of a certificate chain that failed a certificate pinning |
32 // check. | 37 // check. |
33 REPORT_TYPE_PINNING_VIOLATION, | 38 REPORT_TYPE_PINNING_VIOLATION, |
34 // A report for an invalid certificate chain that is being sent for | 39 // A report for an invalid certificate chain that is being sent for |
35 // a user who has opted-in to the extended reporting program. | 40 // a user who has opted-in to the extended reporting program. |
36 REPORT_TYPE_EXTENDED_REPORTING | 41 REPORT_TYPE_EXTENDED_REPORTING |
37 }; | 42 }; |
38 | 43 |
39 // Create a certificate error reporter that will send certificate | 44 // Create a certificate error reporter that will send certificate |
40 // error reports to |upload_url|, using |request_context| as the | 45 // error reports to |upload_url|, using |request_context| as the |
41 // context for the reports. | 46 // context for the reports. |
42 CertificateErrorReporter(net::URLRequestContext* request_context, | 47 CertificateErrorReporter(net::URLRequestContext* request_context, |
43 const GURL& upload_url); | 48 const GURL& upload_url); |
44 | 49 |
45 ~CertificateErrorReporter() override; | 50 // Create a certificate error reporter that will send certificate |
51 // error reports to |upload_url|. A request context will have to be | |
52 // specified when calling |SendReport|. Useful for constructing | |
53 // reporters when not on the IO thread. | |
54 explicit CertificateErrorReporter(const GURL& upload_url); | |
46 | 55 |
47 // Construct, serialize, and send a certificate reporter to the report | 56 // Construct, serialize, and send a certificate reporter to the report |
48 // collection server containing the |ssl_info| associated with a | 57 // collection server containing the |ssl_info| associated with a |
49 // connection to |hostname|. | 58 // connection to |hostname|. |
50 virtual void SendReport(ReportType type, | 59 virtual void SendReport(ReportType type, |
51 const std::string& hostname, | 60 const std::string& hostname, |
52 const net::SSLInfo& ssl_info); | 61 const net::SSLInfo& ssl_info); |
62 // Construct, serialize, and send a certificate reporter to the report | |
felt
2015/03/13 19:18:11
Is this sending a cert "report", or a cert "report
estark
2015/03/16 23:40:52
Done.
| |
63 // collection server containing the |ssl_info| associated with a | |
64 // connection to |hostname|. Uses |request_context| as the context for | |
65 // the request sent to the server. | |
66 virtual void SendReport(ReportType type, | |
67 net::URLRequestContext* request_context, | |
68 const std::string& hostname, | |
69 const net::SSLInfo& ssl_info); | |
53 | 70 |
54 // net::URLRequest::Delegate | 71 // net::URLRequest::Delegate |
55 void OnResponseStarted(net::URLRequest* request) override; | 72 void OnResponseStarted(net::URLRequest* request) override; |
56 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | 73 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
57 | 74 |
75 protected: | |
76 ~CertificateErrorReporter() override; | |
77 | |
58 private: | 78 private: |
79 friend class base::RefCountedThreadSafe<CertificateErrorReporter>; | |
80 | |
59 // Create a URLRequest with which to send a certificate report to the | 81 // Create a URLRequest with which to send a certificate report to the |
60 // server. | 82 // server. |
61 virtual scoped_ptr<net::URLRequest> CreateURLRequest( | 83 virtual scoped_ptr<net::URLRequest> CreateURLRequest( |
62 net::URLRequestContext* context); | 84 net::URLRequestContext* context); |
63 | 85 |
64 // Serialize and send a CertLoggerRequest protobuf to the report | 86 // Serialize and send a CertLoggerRequest protobuf to the report |
65 // collection server. | 87 // collection server. |
66 void SendCertLoggerRequest(const CertLoggerRequest& request); | 88 void SendCertLoggerRequest(const CertLoggerRequest& request); |
67 | 89 |
68 // Populate the CertLoggerRequest for a report. | 90 // Populate the CertLoggerRequest for a report. |
69 static void BuildReport(const std::string& hostname, | 91 static void BuildReport(const std::string& hostname, |
70 const net::SSLInfo& ssl_info, | 92 const net::SSLInfo& ssl_info, |
71 CertLoggerRequest* out_request); | 93 CertLoggerRequest* out_request); |
72 | 94 |
73 // Performs post-report cleanup. | 95 // Performs post-report cleanup. |
74 void RequestComplete(net::URLRequest* request); | 96 void RequestComplete(net::URLRequest* request); |
75 | 97 |
76 net::URLRequestContext* const request_context_; | 98 net::URLRequestContext* const request_context_; |
77 const GURL upload_url_; | 99 const GURL upload_url_; |
78 | 100 |
79 // Owns the contained requests. | 101 // Owns the contained requests. |
80 std::set<net::URLRequest*> inflight_requests_; | 102 std::set<net::URLRequest*> inflight_requests_; |
81 | 103 |
82 DISALLOW_COPY_AND_ASSIGN(CertificateErrorReporter); | 104 DISALLOW_COPY_AND_ASSIGN(CertificateErrorReporter); |
83 }; | 105 }; |
84 | 106 |
85 } // namespace chrome_browser_net | 107 } // namespace chrome_browser_net |
86 | 108 |
87 #endif // CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ | 109 #endif // CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ |
OLD | NEW |