| 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/time.h" | 12 #include "base/time/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/request_priority.h" |
| 15 #include "net/base/upload_bytes_element_reader.h" | 16 #include "net/base/upload_bytes_element_reader.h" |
| 16 #include "net/base/upload_data_stream.h" | 17 #include "net/base/upload_data_stream.h" |
| 17 #include "net/cert/x509_certificate.h" | 18 #include "net/cert/x509_certificate.h" |
| 18 #include "net/ssl/ssl_info.h" | 19 #include "net/ssl/ssl_info.h" |
| 19 #include "net/url_request/url_request_context.h" | 20 #include "net/url_request/url_request_context.h" |
| 20 | 21 |
| 21 namespace chrome_browser_net { | 22 namespace chrome_browser_net { |
| 22 | 23 |
| 23 // TODO(palmer): Switch to HTTPS when the error handling delegate is more | 24 // TODO(palmer): Switch to HTTPS when the error handling delegate is more |
| 24 // sophisticated. Ultimately we plan to attempt the report on many transports. | 25 // sophisticated. Ultimately we plan to attempt the report on many transports. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 48 } | 49 } |
| 49 std::string* cert_chain = request.mutable_cert_chain(); | 50 std::string* cert_chain = request.mutable_cert_chain(); |
| 50 for (size_t i = 0; i < pem_encoded_chain.size(); ++i) | 51 for (size_t i = 0; i < pem_encoded_chain.size(); ++i) |
| 51 *cert_chain += pem_encoded_chain[i]; | 52 *cert_chain += pem_encoded_chain[i]; |
| 52 | 53 |
| 53 std::string out; | 54 std::string out; |
| 54 request.SerializeToString(&out); | 55 request.SerializeToString(&out); |
| 55 return out; | 56 return out; |
| 56 } | 57 } |
| 57 | 58 |
| 58 net::URLRequest* ChromeFraudulentCertificateReporter::CreateURLRequest( | 59 scoped_ptr<net::URLRequest> |
| 59 net::URLRequestContext* context) { | 60 ChromeFraudulentCertificateReporter::CreateURLRequest( |
| 60 net::URLRequest* request = context->CreateRequest(upload_url_, this); | 61 net::URLRequestContext* context) { |
| 62 scoped_ptr<net::URLRequest> request = |
| 63 context->CreateRequest(upload_url_, net::DEFAULT_PRIORITY, this); |
| 61 request->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES | | 64 request->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 62 net::LOAD_DO_NOT_SAVE_COOKIES); | 65 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 63 return request; | 66 return request.Pass(); |
| 64 } | 67 } |
| 65 | 68 |
| 66 void ChromeFraudulentCertificateReporter::SendReport( | 69 void ChromeFraudulentCertificateReporter::SendReport( |
| 67 const std::string& hostname, | 70 const std::string& hostname, |
| 68 const net::SSLInfo& ssl_info, | 71 const net::SSLInfo& ssl_info, |
| 69 bool sni_available) { | 72 bool sni_available) { |
| 70 // We do silent/automatic reporting ONLY for Google properties. For other | 73 // We do silent/automatic reporting ONLY for Google properties. For other |
| 71 // domains (when we start supporting that), we will ask for user permission. | 74 // domains (when we start supporting that), we will ask for user permission. |
| 72 if (!net::TransportSecurityState::IsGooglePinnedProperty(hostname, | 75 if (!net::TransportSecurityState::IsGooglePinnedProperty(hostname, |
| 73 sni_available)) { | 76 sni_available)) { |
| 74 return; | 77 return; |
| 75 } | 78 } |
| 76 | 79 |
| 77 std::string report = BuildReport(hostname, ssl_info); | 80 std::string report = BuildReport(hostname, ssl_info); |
| 78 | 81 |
| 79 net::URLRequest* url_request = CreateURLRequest(request_context_); | 82 scoped_ptr<net::URLRequest> url_request = CreateURLRequest(request_context_); |
| 80 url_request->set_method("POST"); | 83 url_request->set_method("POST"); |
| 81 | 84 |
| 82 scoped_ptr<net::UploadElementReader> reader( | 85 scoped_ptr<net::UploadElementReader> reader( |
| 83 net::UploadOwnedBytesElementReader::CreateWithString(report)); | 86 net::UploadOwnedBytesElementReader::CreateWithString(report)); |
| 84 url_request->set_upload(make_scoped_ptr( | 87 url_request->set_upload(make_scoped_ptr( |
| 85 net::UploadDataStream::CreateWithReader(reader.Pass(), 0))); | 88 net::UploadDataStream::CreateWithReader(reader.Pass(), 0))); |
| 86 | 89 |
| 87 net::HttpRequestHeaders headers; | 90 net::HttpRequestHeaders headers; |
| 88 headers.SetHeader(net::HttpRequestHeaders::kContentType, | 91 headers.SetHeader(net::HttpRequestHeaders::kContentType, |
| 89 "x-application/chrome-fraudulent-cert-report"); | 92 "x-application/chrome-fraudulent-cert-report"); |
| 90 url_request->SetExtraRequestHeaders(headers); | 93 url_request->SetExtraRequestHeaders(headers); |
| 91 | 94 |
| 92 inflight_requests_.insert(url_request); | 95 net::URLRequest* raw_url_request = url_request.get(); |
| 93 url_request->Start(); | 96 inflight_requests_.insert(url_request.release()); |
| 97 raw_url_request->Start(); |
| 94 } | 98 } |
| 95 | 99 |
| 96 void ChromeFraudulentCertificateReporter::RequestComplete( | 100 void ChromeFraudulentCertificateReporter::RequestComplete( |
| 97 net::URLRequest* request) { | 101 net::URLRequest* request) { |
| 98 std::set<net::URLRequest*>::iterator i = inflight_requests_.find(request); | 102 std::set<net::URLRequest*>::iterator i = inflight_requests_.find(request); |
| 99 DCHECK(i != inflight_requests_.end()); | 103 DCHECK(i != inflight_requests_.end()); |
| 100 delete *i; | 104 delete *i; |
| 101 inflight_requests_.erase(i); | 105 inflight_requests_.erase(i); |
| 102 } | 106 } |
| 103 | 107 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 115 LOG(WARNING) << "Certificate upload HTTP status: " | 119 LOG(WARNING) << "Certificate upload HTTP status: " |
| 116 << request->GetResponseCode(); | 120 << request->GetResponseCode(); |
| 117 } | 121 } |
| 118 RequestComplete(request); | 122 RequestComplete(request); |
| 119 } | 123 } |
| 120 | 124 |
| 121 void ChromeFraudulentCertificateReporter::OnReadCompleted( | 125 void ChromeFraudulentCertificateReporter::OnReadCompleted( |
| 122 net::URLRequest* request, int bytes_read) {} | 126 net::URLRequest* request, int bytes_read) {} |
| 123 | 127 |
| 124 } // namespace chrome_browser_net | 128 } // namespace chrome_browser_net |
| OLD | NEW |