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/safe_browsing/ping_manager.h" | 5 #include "chrome/browser/safe_browsing/ping_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "chrome/browser/net/certificate_error_reporter.h" | 11 #include "chrome/browser/net/certificate_error_reporter.h" |
12 #include "chrome/common/env_vars.h" | 12 #include "chrome/common/env_vars.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #include "google_apis/google_api_keys.h" | 14 #include "google_apis/google_api_keys.h" |
15 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
17 #include "net/ssl/ssl_info.h" | 17 #include "net/ssl/ssl_info.h" |
18 #include "net/url_request/url_fetcher.h" | 18 #include "net/url_request/url_fetcher.h" |
19 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
20 #include "net/url_request/url_request_status.h" | 20 #include "net/url_request/url_request_status.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
23 using chrome_browser_net::CertificateErrorReporter; | 23 using chrome_browser_net::CertificateErrorReporter; |
24 using content::BrowserThread; | 24 using content::BrowserThread; |
25 | 25 |
26 namespace { | 26 namespace { |
27 // URLs to upload invalid certificate chain reports. The HTTP URL is | 27 // URL to upload invalid certificate chain reports |
28 // preferred since a client seeing an invalid cert might not be able to | 28 const char kExtendedReportingUploadUrl[] = |
29 // make an HTTPS connection to report it. | |
30 // TODO(estark): insert the production HTTP URL when it's ready | |
31 const char kExtendedReportingUploadUrlInsecure[] = ""; | |
32 const char kExtendedReportingUploadUrlSecure[] = | |
33 "https://sb-ssl.google.com/safebrowsing/clientreport/chrome-certs"; | 29 "https://sb-ssl.google.com/safebrowsing/clientreport/chrome-certs"; |
34 } // namespace | 30 } // namespace |
35 | 31 |
36 // SafeBrowsingPingManager implementation ---------------------------------- | 32 // SafeBrowsingPingManager implementation ---------------------------------- |
37 | 33 |
38 // static | 34 // static |
39 SafeBrowsingPingManager* SafeBrowsingPingManager::Create( | 35 SafeBrowsingPingManager* SafeBrowsingPingManager::Create( |
40 net::URLRequestContextGetter* request_context_getter, | 36 net::URLRequestContextGetter* request_context_getter, |
41 const SafeBrowsingProtocolConfig& config) { | 37 const SafeBrowsingProtocolConfig& config) { |
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
43 return new SafeBrowsingPingManager(request_context_getter, config); | 39 return new SafeBrowsingPingManager(request_context_getter, config); |
44 } | 40 } |
45 | 41 |
46 SafeBrowsingPingManager::SafeBrowsingPingManager( | 42 SafeBrowsingPingManager::SafeBrowsingPingManager( |
47 net::URLRequestContextGetter* request_context_getter, | 43 net::URLRequestContextGetter* request_context_getter, |
48 const SafeBrowsingProtocolConfig& config) | 44 const SafeBrowsingProtocolConfig& config) |
49 : client_name_(config.client_name), | 45 : client_name_(config.client_name), |
50 request_context_getter_(request_context_getter), | 46 request_context_getter_(request_context_getter), |
51 url_prefix_(config.url_prefix) { | 47 url_prefix_(config.url_prefix), |
| 48 certificate_error_reporter_( |
| 49 request_context_getter |
| 50 ? new CertificateErrorReporter( |
| 51 request_context_getter->GetURLRequestContext(), |
| 52 GURL(kExtendedReportingUploadUrl), |
| 53 CertificateErrorReporter::SEND_COOKIES) |
| 54 : nullptr) { |
52 DCHECK(!url_prefix_.empty()); | 55 DCHECK(!url_prefix_.empty()); |
53 | 56 |
54 if (request_context_getter) { | |
55 bool use_insecure_certificate_upload_url = | |
56 CertificateErrorReporter::IsHttpUploadUrlSupported() && | |
57 strlen(kExtendedReportingUploadUrlInsecure) > 0; | |
58 GURL certificate_upload_url(use_insecure_certificate_upload_url | |
59 ? kExtendedReportingUploadUrlInsecure | |
60 : kExtendedReportingUploadUrlSecure); | |
61 | |
62 certificate_error_reporter_.reset(new CertificateErrorReporter( | |
63 request_context_getter->GetURLRequestContext(), certificate_upload_url, | |
64 CertificateErrorReporter::SEND_COOKIES)); | |
65 } | |
66 | |
67 version_ = SafeBrowsingProtocolManagerHelper::Version(); | 57 version_ = SafeBrowsingProtocolManagerHelper::Version(); |
68 } | 58 } |
69 | 59 |
70 SafeBrowsingPingManager::~SafeBrowsingPingManager() { | 60 SafeBrowsingPingManager::~SafeBrowsingPingManager() { |
71 // Delete in-progress safebrowsing reports (hits and details). | 61 // Delete in-progress safebrowsing reports (hits and details). |
72 STLDeleteContainerPointers(safebrowsing_reports_.begin(), | 62 STLDeleteContainerPointers(safebrowsing_reports_.begin(), |
73 safebrowsing_reports_.end()); | 63 safebrowsing_reports_.end()); |
74 } | 64 } |
75 | 65 |
76 // net::URLFetcherDelegate implementation ---------------------------------- | 66 // net::URLFetcherDelegate implementation ---------------------------------- |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 url_prefix_.c_str(), | 175 url_prefix_.c_str(), |
186 client_name_.c_str(), | 176 client_name_.c_str(), |
187 version_.c_str()); | 177 version_.c_str()); |
188 std::string api_key = google_apis::GetAPIKey(); | 178 std::string api_key = google_apis::GetAPIKey(); |
189 if (!api_key.empty()) { | 179 if (!api_key.empty()) { |
190 base::StringAppendF(&url, "&key=%s", | 180 base::StringAppendF(&url, "&key=%s", |
191 net::EscapeQueryParamValue(api_key, true).c_str()); | 181 net::EscapeQueryParamValue(api_key, true).c_str()); |
192 } | 182 } |
193 return GURL(url); | 183 return GURL(url); |
194 } | 184 } |
OLD | NEW |