Chromium Code Reviews| 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" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 net::URLRequestContext* request_context) | 33 net::URLRequestContext* request_context) |
| 34 : request_context_(request_context), | 34 : request_context_(request_context), |
| 35 pinning_violation_upload_url_(kFraudulentCertificateUploadEndpoint), | 35 pinning_violation_upload_url_(kFraudulentCertificateUploadEndpoint), |
| 36 invalid_chain_upload_url_(kInvalidCertificateChainUploadEndpoint) { | 36 invalid_chain_upload_url_(kInvalidCertificateChainUploadEndpoint) { |
| 37 } | 37 } |
| 38 | 38 |
| 39 ChromeFraudulentCertificateReporter::~ChromeFraudulentCertificateReporter() { | 39 ChromeFraudulentCertificateReporter::~ChromeFraudulentCertificateReporter() { |
| 40 STLDeleteElements(&inflight_requests_); | 40 STLDeleteElements(&inflight_requests_); |
| 41 } | 41 } |
| 42 | 42 |
| 43 static std::string BuildReport(const std::string& hostname, | 43 // Helper function for |BuildReport|. Appends each PEM-encoded |
| 44 const net::SSLInfo& ssl_info) { | 44 // certificate in the chain starting at |cert| to |chain_from_report|. |
| 45 static void AddCertChainToReport(const scoped_refptr<net::X509Certificate> cert, | |
| 46 std::string* chain_from_report) { | |
| 47 std::vector<std::string> pem_encoded_chain; | |
| 48 if (!cert || !cert->GetPEMEncodedChain(&pem_encoded_chain)) { | |
|
felt
2015/02/25 16:41:32
is it possible and expected that this can be calle
| |
| 49 LOG(ERROR) << "Could not get PEM encoded chain."; | |
|
felt
2015/02/25 16:41:32
should there also be a return here?
| |
| 50 } | |
| 51 for (size_t i = 0; i < pem_encoded_chain.size(); ++i) | |
| 52 *chain_from_report += pem_encoded_chain[i]; | |
| 53 } | |
| 54 | |
| 55 std::string ChromeFraudulentCertificateReporter::BuildReport( | |
| 56 ChromeFraudulentCertificateReporter::ReportType type, | |
| 57 const std::string& hostname, | |
| 58 const net::SSLInfo& ssl_info) { | |
| 45 CertLoggerRequest request; | 59 CertLoggerRequest request; |
| 46 base::Time now = base::Time::Now(); | 60 base::Time now = base::Time::Now(); |
| 47 request.set_time_usec(now.ToInternalValue()); | 61 request.set_time_usec(now.ToInternalValue()); |
| 48 request.set_hostname(hostname); | 62 request.set_hostname(hostname); |
| 49 | 63 |
| 50 std::vector<std::string> pem_encoded_chain; | 64 AddCertChainToReport(ssl_info.cert, request.mutable_cert_chain()); |
| 51 if (!ssl_info.cert->GetPEMEncodedChain(&pem_encoded_chain)) { | 65 if (type == |
| 52 LOG(ERROR) << "Could not get PEM encoded chain."; | 66 ChromeFraudulentCertificateReporter::REPORT_TYPE_EXTENDED_REPORTING) { |
| 67 AddCertChainToReport(ssl_info.unverified_server_cert, | |
| 68 request.mutable_unverified_server_cert_chain()); | |
| 53 } | 69 } |
| 54 std::string* cert_chain = request.mutable_cert_chain(); | |
| 55 for (size_t i = 0; i < pem_encoded_chain.size(); ++i) | |
| 56 *cert_chain += pem_encoded_chain[i]; | |
| 57 | 70 |
| 58 request.add_pin(ssl_info.pinning_failure_log); | 71 request.add_pin(ssl_info.pinning_failure_log); |
| 59 | 72 |
| 60 std::string out; | 73 std::string out; |
| 61 request.SerializeToString(&out); | 74 request.SerializeToString(&out); |
| 62 return out; | 75 return out; |
| 63 } | 76 } |
| 64 | 77 |
| 65 scoped_ptr<net::URLRequest> | 78 scoped_ptr<net::URLRequest> |
| 66 ChromeFraudulentCertificateReporter::CreateURLRequest( | 79 ChromeFraudulentCertificateReporter::CreateURLRequest( |
| 67 net::URLRequestContext* context, | 80 net::URLRequestContext* context, |
| 68 const GURL& upload_url) { | 81 const GURL& upload_url) { |
| 69 scoped_ptr<net::URLRequest> request = | 82 scoped_ptr<net::URLRequest> request = |
| 70 context->CreateRequest(upload_url, net::DEFAULT_PRIORITY, this, NULL); | 83 context->CreateRequest(upload_url, net::DEFAULT_PRIORITY, this, NULL); |
| 71 request->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 84 request->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 72 net::LOAD_DO_NOT_SAVE_COOKIES); | 85 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 73 return request.Pass(); | 86 return request.Pass(); |
| 74 } | 87 } |
| 75 | 88 |
| 76 void ChromeFraudulentCertificateReporter::SendReport( | 89 void ChromeFraudulentCertificateReporter::SendReport( |
| 77 ReportType type, | 90 ReportType type, |
| 78 const std::string& hostname, | 91 const std::string& hostname, |
| 79 const net::SSLInfo& ssl_info) { | 92 const net::SSLInfo& ssl_info) { |
| 80 if (type == REPORT_TYPE_EXTENDED_REPORTING) { | 93 if (type == REPORT_TYPE_EXTENDED_REPORTING) { |
| 81 // TODO(estark): Double-check that the user is opted in. | 94 // TODO(estark): Double-check that the user is opted in. |
| 82 | 95 |
| 83 // TODO(estark): Temporarily, since there is no upload endpoint, just log | 96 // TODO(estark): Temporarily, since there is no upload endpoint, just log |
| 84 // the information. | 97 // the information. |
| 85 LOG(ERROR) << "SSL report for " << hostname << ":\n" | 98 LOG(ERROR) << "SSL report for " << hostname << ":\n" |
| 86 << BuildReport(hostname, ssl_info) << "\n\n"; | 99 << BuildReport(type, hostname, ssl_info) << "\n\n"; |
| 87 return; | 100 return; |
| 88 } | 101 } |
| 89 | 102 |
| 90 // We do silent/automatic reporting ONLY for Google properties. For other | 103 // We do silent/automatic reporting ONLY for Google properties. For other |
| 91 // domains (when we start supporting that), we will ask for user permission. | 104 // domains (when we start supporting that), we will ask for user permission. |
| 92 if (!net::TransportSecurityState::IsGooglePinnedProperty(hostname)) { | 105 if (!net::TransportSecurityState::IsGooglePinnedProperty(hostname)) { |
| 93 return; | 106 return; |
| 94 } | 107 } |
| 95 | 108 |
| 96 std::string report = BuildReport(hostname, ssl_info); | 109 std::string report = BuildReport(type, hostname, ssl_info); |
| 97 | 110 |
| 98 scoped_ptr<net::URLRequest> url_request = | 111 scoped_ptr<net::URLRequest> url_request = |
| 99 CreateURLRequest(request_context_, pinning_violation_upload_url_); | 112 CreateURLRequest(request_context_, pinning_violation_upload_url_); |
| 100 url_request->set_method("POST"); | 113 url_request->set_method("POST"); |
| 101 | 114 |
| 102 scoped_ptr<net::UploadElementReader> reader( | 115 scoped_ptr<net::UploadElementReader> reader( |
| 103 net::UploadOwnedBytesElementReader::CreateWithString(report)); | 116 net::UploadOwnedBytesElementReader::CreateWithString(report)); |
| 104 url_request->set_upload( | 117 url_request->set_upload( |
| 105 net::ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); | 118 net::ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); |
| 106 | 119 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 LOG(WARNING) << "Certificate upload HTTP status: " | 154 LOG(WARNING) << "Certificate upload HTTP status: " |
| 142 << request->GetResponseCode(); | 155 << request->GetResponseCode(); |
| 143 } | 156 } |
| 144 RequestComplete(request); | 157 RequestComplete(request); |
| 145 } | 158 } |
| 146 | 159 |
| 147 void ChromeFraudulentCertificateReporter::OnReadCompleted( | 160 void ChromeFraudulentCertificateReporter::OnReadCompleted( |
| 148 net::URLRequest* request, int bytes_read) {} | 161 net::URLRequest* request, int bytes_read) {} |
| 149 | 162 |
| 150 } // namespace chrome_browser_net | 163 } // namespace chrome_browser_net |
| OLD | NEW |