| 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 class EncryptedCertLoggerRequest; |
| 25 |
| 26 // These functions are used by tests. |
| 27 bool Seal(const std::string& aead_key, |
| 28 const std::string& nonce, |
| 29 const std::string& plaintext, |
| 30 std::string* const ciphertext); |
| 31 |
| 32 bool DecryptCertificateErrorReport( |
| 33 const uint8 server_private_key[32], |
| 34 const EncryptedCertLoggerRequest& encrypted_report, |
| 35 CertLoggerRequest* decrypted_report); |
| 24 | 36 |
| 25 // Provides functionality for sending reports about invalid SSL | 37 // Provides functionality for sending reports about invalid SSL |
| 26 // certificate chains to a report collection server. | 38 // certificate chains to a report collection server. |
| 27 class CertificateErrorReporter : public net::URLRequest::Delegate { | 39 class CertificateErrorReporter : public net::URLRequest::Delegate { |
| 28 public: | 40 public: |
| 29 // These represent the types of reports that can be sent. | 41 // These represent the types of reports that can be sent. |
| 30 enum ReportType { | 42 enum ReportType { |
| 31 // A report of a certificate chain that failed a certificate pinning | 43 // A report of a certificate chain that failed a certificate pinning |
| 32 // check. | 44 // check. |
| 33 REPORT_TYPE_PINNING_VIOLATION, | 45 REPORT_TYPE_PINNING_VIOLATION, |
| 34 // A report for an invalid certificate chain that is being sent for | 46 // A report for an invalid certificate chain that is being sent for |
| 35 // a user who has opted-in to the extended reporting program. | 47 // a user who has opted-in to the extended reporting program. |
| 36 REPORT_TYPE_EXTENDED_REPORTING | 48 REPORT_TYPE_EXTENDED_REPORTING |
| 37 }; | 49 }; |
| 38 | 50 |
| 39 // Represents whether or not to send cookies along with reports sent | 51 // Represents whether or not to send cookies along with reports sent |
| 40 // to the server. | 52 // to the server. |
| 41 enum CookiesPreference { SEND_COOKIES, DO_NOT_SEND_COOKIES }; | 53 enum CookiesPreference { SEND_COOKIES, DO_NOT_SEND_COOKIES }; |
| 42 | 54 |
| 43 // Create a certificate error reporter that will send certificate | 55 // Create a certificate error reporter that will send certificate |
| 44 // error reports to |upload_url|, using |request_context| as the | 56 // error reports to |upload_url|, using |request_context| as the |
| 45 // context for the reports. |cookies_preference| controls whether | 57 // context for the reports. |cookies_preference| controls whether |
| 46 // cookies will be sent along with the reports. | 58 // cookies will be sent along with the reports. |
| 47 CertificateErrorReporter(net::URLRequestContext* request_context, | 59 CertificateErrorReporter(net::URLRequestContext* request_context, |
| 48 const GURL& upload_url, | 60 const GURL& upload_url, |
| 49 CookiesPreference cookies_preference); | 61 CookiesPreference cookies_preference); |
| 50 | 62 |
| 63 // Allows tests to use a server public key with known private key. |
| 64 CertificateErrorReporter(net::URLRequestContext* request_context, |
| 65 const GURL& upload_url, |
| 66 CookiesPreference cookies_preference, |
| 67 const uint8 server_public_key[32], |
| 68 const uint32 server_public_key_version); |
| 69 |
| 51 ~CertificateErrorReporter() override; | 70 ~CertificateErrorReporter() override; |
| 52 | 71 |
| 53 // Construct, serialize, and send a certificate report to the report | 72 // Construct, serialize, and send a certificate report to the report |
| 54 // collection server containing the |ssl_info| associated with a | 73 // collection server containing the |ssl_info| associated with a |
| 55 // connection to |hostname|. | 74 // connection to |hostname|. |
| 56 // | 75 // |
| 57 // SendReport actually sends the report over the network; callers are | 76 // SendReport actually sends the report over the network; callers are |
| 58 // responsible for enforcing any preconditions (such as obtaining user | 77 // responsible for enforcing any preconditions (such as obtaining user |
| 59 // opt-in, only sending reports for certain hostnames, checking for | 78 // opt-in, only sending reports for certain hostnames, checking for |
| 60 // incognito mode, etc.). | 79 // incognito mode, etc.). |
| 61 virtual void SendReport(ReportType type, | 80 virtual void SendReport(ReportType type, |
| 62 const std::string& hostname, | 81 const std::string& hostname, |
| 63 const net::SSLInfo& ssl_info); | 82 const net::SSLInfo& ssl_info); |
| 64 | 83 |
| 65 // net::URLRequest::Delegate | 84 // net::URLRequest::Delegate |
| 66 void OnResponseStarted(net::URLRequest* request) override; | 85 void OnResponseStarted(net::URLRequest* request) override; |
| 67 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | 86 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
| 68 | 87 |
| 69 private: | 88 private: |
| 70 // Create a URLRequest with which to send a certificate report to the | 89 // Create a URLRequest with which to send a certificate report to the |
| 71 // server. | 90 // server. |
| 72 virtual scoped_ptr<net::URLRequest> CreateURLRequest( | 91 virtual scoped_ptr<net::URLRequest> CreateURLRequest( |
| 73 net::URLRequestContext* context); | 92 net::URLRequestContext* context); |
| 74 | 93 |
| 75 // Serialize and send a CertLoggerRequest protobuf to the report | 94 // Serialize and send a CertLoggerRequest protobuf to the report |
| 76 // collection server. | 95 // collection server. |
| 77 void SendCertLoggerRequest(const CertLoggerRequest& request); | 96 void SendCertLoggerRequest(const CertLoggerRequest& request); |
| 78 | 97 |
| 98 void SendSerializedRequest(const std::string& serialized_request); |
| 99 |
| 79 // Populate the CertLoggerRequest for a report. | 100 // Populate the CertLoggerRequest for a report. |
| 80 static void BuildReport(const std::string& hostname, | 101 static void BuildReport(const std::string& hostname, |
| 81 const net::SSLInfo& ssl_info, | 102 const net::SSLInfo& ssl_info, |
| 82 CertLoggerRequest* out_request); | 103 CertLoggerRequest* out_request); |
| 83 | 104 |
| 84 // Performs post-report cleanup. | 105 // Performs post-report cleanup. |
| 85 void RequestComplete(net::URLRequest* request); | 106 void RequestComplete(net::URLRequest* request); |
| 86 | 107 |
| 87 net::URLRequestContext* const request_context_; | 108 net::URLRequestContext* const request_context_; |
| 88 const GURL upload_url_; | 109 const GURL upload_url_; |
| 89 | 110 |
| 90 // Owns the contained requests. | 111 // Owns the contained requests. |
| 91 std::set<net::URLRequest*> inflight_requests_; | 112 std::set<net::URLRequest*> inflight_requests_; |
| 92 | 113 |
| 93 CookiesPreference cookies_preference_; | 114 CookiesPreference cookies_preference_; |
| 94 | 115 |
| 116 const uint8* server_public_key_; |
| 117 const uint32 server_public_key_version_; |
| 118 |
| 95 DISALLOW_COPY_AND_ASSIGN(CertificateErrorReporter); | 119 DISALLOW_COPY_AND_ASSIGN(CertificateErrorReporter); |
| 96 }; | 120 }; |
| 97 | 121 |
| 98 } // namespace chrome_browser_net | 122 } // namespace chrome_browser_net |
| 99 | 123 |
| 100 #endif // CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ | 124 #endif // CHROME_BROWSER_NET_CERTIFICATE_ERROR_REPORTER_H_ |
| OLD | NEW |