| 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 #include "chrome/browser/net/certificate_error_reporter.h" | 5 #include "chrome/browser/net/certificate_error_reporter.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "chrome/browser/net/cert_logger.pb.h" | 12 #include "chrome/browser/net/cert_logger.pb.h" |
| 13 #include "net/base/elements_upload_data_stream.h" | 13 #include "net/base/elements_upload_data_stream.h" |
| 14 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 15 #include "net/base/request_priority.h" | 15 #include "net/base/request_priority.h" |
| 16 #include "net/base/upload_bytes_element_reader.h" | 16 #include "net/base/upload_bytes_element_reader.h" |
| 17 #include "net/cert/x509_certificate.h" | 17 #include "net/cert/x509_certificate.h" |
| 18 #include "net/ssl/ssl_info.h" | 18 #include "net/ssl/ssl_info.h" |
| 19 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 20 | 20 |
| 21 namespace chrome_browser_net { | 21 namespace chrome_browser_net { |
| 22 | 22 |
| 23 // URL to upload invalid certificate chain reports |
| 24 // TODO(estark): Fill this in with the real URL when live. |
| 25 const char kExtendedReportingUploadUrl[] = "http://example.test"; |
| 26 |
| 23 CertificateErrorReporter::CertificateErrorReporter( | 27 CertificateErrorReporter::CertificateErrorReporter( |
| 24 net::URLRequestContext* request_context, | 28 net::URLRequestContext* request_context, |
| 25 const GURL& upload_url) | 29 const GURL& upload_url) |
| 26 : request_context_(request_context), upload_url_(upload_url) { | 30 : request_context_(request_context), upload_url_(upload_url) { |
| 27 DCHECK(!upload_url.is_empty()); | 31 DCHECK(!upload_url.is_empty()); |
| 28 } | 32 } |
| 29 | 33 |
| 34 CertificateErrorReporter::CertificateErrorReporter(const GURL& upload_url) |
| 35 : CertificateErrorReporter(nullptr, upload_url) { |
| 36 } |
| 37 |
| 30 CertificateErrorReporter::~CertificateErrorReporter() { | 38 CertificateErrorReporter::~CertificateErrorReporter() { |
| 31 STLDeleteElements(&inflight_requests_); | 39 STLDeleteElements(&inflight_requests_); |
| 32 } | 40 } |
| 33 | 41 |
| 34 void CertificateErrorReporter::SendReport(ReportType type, | 42 void CertificateErrorReporter::SendReport(ReportType type, |
| 35 const std::string& hostname, | 43 const std::string& hostname, |
| 36 const net::SSLInfo& ssl_info) { | 44 const net::SSLInfo& ssl_info) { |
| 45 SendReport(type, request_context_, hostname, ssl_info); |
| 46 } |
| 47 |
| 48 void CertificateErrorReporter::SendReport( |
| 49 ReportType type, |
| 50 net::URLRequestContext* request_context, |
| 51 const std::string& hostname, |
| 52 const net::SSLInfo& ssl_info) { |
| 37 CertLoggerRequest request; | 53 CertLoggerRequest request; |
| 38 std::string out; | 54 std::string out; |
| 39 | 55 |
| 40 BuildReport(hostname, ssl_info, &request); | 56 BuildReport(hostname, ssl_info, &request); |
| 41 | 57 |
| 42 switch (type) { | 58 switch (type) { |
| 43 case REPORT_TYPE_PINNING_VIOLATION: | 59 case REPORT_TYPE_PINNING_VIOLATION: |
| 44 SendCertLoggerRequest(request); | 60 SendCertLoggerRequest(request); |
| 45 break; | 61 break; |
| 46 case REPORT_TYPE_EXTENDED_REPORTING: | 62 case REPORT_TYPE_EXTENDED_REPORTING: |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 139 } |
| 124 | 140 |
| 125 void CertificateErrorReporter::RequestComplete(net::URLRequest* request) { | 141 void CertificateErrorReporter::RequestComplete(net::URLRequest* request) { |
| 126 std::set<net::URLRequest*>::iterator i = inflight_requests_.find(request); | 142 std::set<net::URLRequest*>::iterator i = inflight_requests_.find(request); |
| 127 DCHECK(i != inflight_requests_.end()); | 143 DCHECK(i != inflight_requests_.end()); |
| 128 scoped_ptr<net::URLRequest> url_request(*i); | 144 scoped_ptr<net::URLRequest> url_request(*i); |
| 129 inflight_requests_.erase(i); | 145 inflight_requests_.erase(i); |
| 130 } | 146 } |
| 131 | 147 |
| 132 } // namespace chrome_browser_net | 148 } // namespace chrome_browser_net |
| OLD | NEW |