OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ |
| 6 #define CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <string> |
| 10 |
| 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "net/url_request/url_request.h" |
| 14 #include "url/gurl.h" |
| 15 |
| 16 namespace net { |
| 17 class URLRequestContext; |
| 18 class SSLInfo; |
| 19 } |
| 20 |
| 21 namespace chrome_browser_net { |
| 22 |
| 23 class CertLoggerRequest; |
| 24 |
| 25 // Provides functionality for sending reports about invalid SSL |
| 26 // certificate chains to a report collection server. |
| 27 class CertificateErrorReporter : public net::URLRequest::Delegate { |
| 28 public: |
| 29 enum ReportType { |
| 30 REPORT_TYPE_PINNING_VIOLATION, |
| 31 REPORT_TYPE_EXTENDED_REPORTING |
| 32 }; |
| 33 |
| 34 CertificateErrorReporter(net::URLRequestContext* request_context, |
| 35 const GURL& upload_url); |
| 36 |
| 37 ~CertificateErrorReporter() override; |
| 38 |
| 39 // Construct, serialize, and send a certificate reporter to the report |
| 40 // collection server containing the |ssl_info| associated with a |
| 41 // connection to |hostname|. |
| 42 virtual void SendReport(ReportType type, |
| 43 const std::string& hostname, |
| 44 const net::SSLInfo& ssl_info); |
| 45 |
| 46 // net::URLRequest::Delegate |
| 47 void OnResponseStarted(net::URLRequest* request) override; |
| 48 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
| 49 |
| 50 private: |
| 51 // Allow tests to access private data members. |
| 52 FRIEND_TEST_ALL_PREFIXES(CertificateErrorReporterTest, |
| 53 ReportIsBuiltCorrectly); |
| 54 |
| 55 // Create a URLRequest with which to send a certificate report to the |
| 56 // server. |
| 57 virtual scoped_ptr<net::URLRequest> CreateURLRequest( |
| 58 net::URLRequestContext* context); |
| 59 |
| 60 // Serialize and send a CertLoggerRequest protobuf to the report |
| 61 // collection server. |
| 62 void SendCertLoggerRequest(const CertLoggerRequest& request); |
| 63 |
| 64 // Populate the CertLoggerRequest for a report. |
| 65 static void BuildReport(const std::string& hostname, |
| 66 const net::SSLInfo& ssl_info, |
| 67 CertLoggerRequest* out_request); |
| 68 |
| 69 // Performs post-report cleanup. |
| 70 void RequestComplete(net::URLRequest* request); |
| 71 |
| 72 net::URLRequestContext* const request_context_; |
| 73 const GURL upload_url_; |
| 74 |
| 75 // Owns the contained requests. |
| 76 std::set<net::URLRequest*> inflight_requests_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(CertificateErrorReporter); |
| 79 }; |
| 80 |
| 81 } // namespace chrome_browser_net |
| 82 |
| 83 #endif // CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ |
OLD | NEW |