| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_fraudulent_certificate_reporter.h" | 5 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "chrome/browser/net/cert_logger.pb.h" | 13 #include "chrome/browser/net/cert_logger.pb.h" |
| 14 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 15 #include "net/base/ssl_info.h" | 15 #include "net/base/ssl_info.h" |
| 16 #include "net/base/upload_data.h" | 16 #include "net/base/upload_bytes_element_reader.h" |
| 17 #include "net/base/upload_data_stream.h" |
| 17 #include "net/base/x509_certificate.h" | 18 #include "net/base/x509_certificate.h" |
| 18 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 19 | 20 |
| 20 namespace chrome_browser_net { | 21 namespace chrome_browser_net { |
| 21 | 22 |
| 22 // TODO(palmer): Switch to HTTPS when the error handling delegate is more | 23 // TODO(palmer): Switch to HTTPS when the error handling delegate is more |
| 23 // sophisticated. Ultimately we plan to attempt the report on many transports. | 24 // sophisticated. Ultimately we plan to attempt the report on many transports. |
| 24 static const char kFraudulentCertificateUploadEndpoint[] = | 25 static const char kFraudulentCertificateUploadEndpoint[] = |
| 25 "http://clients3.google.com/log_cert_error"; | 26 "http://clients3.google.com/log_cert_error"; |
| 26 | 27 |
| 27 ChromeFraudulentCertificateReporter::ChromeFraudulentCertificateReporter( | 28 ChromeFraudulentCertificateReporter::ChromeFraudulentCertificateReporter( |
| 28 net::URLRequestContext* request_context) | 29 net::URLRequestContext* request_context) |
| 29 : request_context_(request_context), | 30 : request_context_(request_context), |
| 30 upload_url_(kFraudulentCertificateUploadEndpoint) { | 31 upload_url_(kFraudulentCertificateUploadEndpoint) { |
| 31 } | 32 } |
| 32 | 33 |
| 33 ChromeFraudulentCertificateReporter::~ChromeFraudulentCertificateReporter() { | 34 ChromeFraudulentCertificateReporter::~ChromeFraudulentCertificateReporter() { |
| 34 STLDeleteElements(&inflight_requests_); | 35 STLDeleteElements(&inflight_requests_); |
| 35 } | 36 } |
| 36 | 37 |
| 37 static std::string BuildReport( | 38 static std::string BuildReport(const std::string& hostname, |
| 38 const std::string& hostname, | 39 const net::SSLInfo& ssl_info) { |
| 39 const net::SSLInfo& ssl_info) { | |
| 40 CertLoggerRequest request; | 40 CertLoggerRequest request; |
| 41 base::Time now = base::Time::Now(); | 41 base::Time now = base::Time::Now(); |
| 42 request.set_time_usec(now.ToInternalValue()); | 42 request.set_time_usec(now.ToInternalValue()); |
| 43 request.set_hostname(hostname); | 43 request.set_hostname(hostname); |
| 44 | 44 |
| 45 std::vector<std::string> pem_encoded_chain; | 45 std::vector<std::string> pem_encoded_chain; |
| 46 if (!ssl_info.cert->GetPEMEncodedChain(&pem_encoded_chain)) { | 46 if (!ssl_info.cert->GetPEMEncodedChain(&pem_encoded_chain)) { |
| 47 LOG(ERROR) << "Could not get PEM encoded chain."; | 47 LOG(ERROR) << "Could not get PEM encoded chain."; |
| 48 } | 48 } |
| 49 std::string* cert_chain = request.mutable_cert_chain(); | 49 std::string* cert_chain = request.mutable_cert_chain(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 72 if (!net::TransportSecurityState::IsGooglePinnedProperty(hostname, | 72 if (!net::TransportSecurityState::IsGooglePinnedProperty(hostname, |
| 73 sni_available)) { | 73 sni_available)) { |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 | 76 |
| 77 std::string report = BuildReport(hostname, ssl_info); | 77 std::string report = BuildReport(hostname, ssl_info); |
| 78 | 78 |
| 79 net::URLRequest* url_request = CreateURLRequest(request_context_); | 79 net::URLRequest* url_request = CreateURLRequest(request_context_); |
| 80 url_request->set_method("POST"); | 80 url_request->set_method("POST"); |
| 81 | 81 |
| 82 scoped_refptr<net::UploadData> upload_data(new net::UploadData()); | 82 scoped_ptr<net::UploadElementReader> reader( |
| 83 upload_data->AppendBytes(report.data(), report.size()); | 83 net::UploadOwnedBytesElementReader::CreateWithString(report)); |
| 84 url_request->set_upload(upload_data); | 84 url_request->set_upload(make_scoped_ptr( |
| 85 net::UploadDataStream::CreateWithReader(reader.Pass(), 0))); |
| 85 | 86 |
| 86 net::HttpRequestHeaders headers; | 87 net::HttpRequestHeaders headers; |
| 87 headers.SetHeader(net::HttpRequestHeaders::kContentType, | 88 headers.SetHeader(net::HttpRequestHeaders::kContentType, |
| 88 "x-application/chrome-fraudulent-cert-report"); | 89 "x-application/chrome-fraudulent-cert-report"); |
| 89 url_request->SetExtraRequestHeaders(headers); | 90 url_request->SetExtraRequestHeaders(headers); |
| 90 | 91 |
| 91 inflight_requests_.insert(url_request); | 92 inflight_requests_.insert(url_request); |
| 92 url_request->Start(); | 93 url_request->Start(); |
| 93 } | 94 } |
| 94 | 95 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 114 LOG(WARNING) << "Certificate upload HTTP status: " | 115 LOG(WARNING) << "Certificate upload HTTP status: " |
| 115 << request->GetResponseCode(); | 116 << request->GetResponseCode(); |
| 116 } | 117 } |
| 117 RequestComplete(request); | 118 RequestComplete(request); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void ChromeFraudulentCertificateReporter::OnReadCompleted( | 121 void ChromeFraudulentCertificateReporter::OnReadCompleted( |
| 121 net::URLRequest* request, int bytes_read) {} | 122 net::URLRequest* request, int bytes_read) {} |
| 122 | 123 |
| 123 } // namespace chrome_browser_net | 124 } // namespace chrome_browser_net |
| OLD | NEW |