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 // URLs to upload invalid certificate chain reports. The HTTP URL is |
28 // preferred since a client seeing an invalid cert might not be able to | 28 // preferred since a client seeing an invalid cert might not be able to |
29 // make an HTTPS connection to report it. | 29 // make an HTTPS connection to report it. |
30 // TODO(estark): insert the production HTTP URL when it's ready | 30 const char kExtendedReportingUploadUrlInsecure[] = |
31 const char kExtendedReportingUploadUrlInsecure[] = ""; | 31 "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" |
| 32 "chrome-certs"; |
32 const char kExtendedReportingUploadUrlSecure[] = | 33 const char kExtendedReportingUploadUrlSecure[] = |
33 "https://sb-ssl.google.com/safebrowsing/clientreport/chrome-certs"; | 34 "https://sb-ssl.google.com/safebrowsing/clientreport/chrome-certs"; |
34 } // namespace | 35 } // namespace |
35 | 36 |
36 // SafeBrowsingPingManager implementation ---------------------------------- | 37 // SafeBrowsingPingManager implementation ---------------------------------- |
37 | 38 |
38 // static | 39 // static |
39 SafeBrowsingPingManager* SafeBrowsingPingManager::Create( | 40 SafeBrowsingPingManager* SafeBrowsingPingManager::Create( |
40 net::URLRequestContextGetter* request_context_getter, | 41 net::URLRequestContextGetter* request_context_getter, |
41 const SafeBrowsingProtocolConfig& config) { | 42 const SafeBrowsingProtocolConfig& config) { |
42 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 43 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
43 return new SafeBrowsingPingManager(request_context_getter, config); | 44 return new SafeBrowsingPingManager(request_context_getter, config); |
44 } | 45 } |
45 | 46 |
46 SafeBrowsingPingManager::SafeBrowsingPingManager( | 47 SafeBrowsingPingManager::SafeBrowsingPingManager( |
47 net::URLRequestContextGetter* request_context_getter, | 48 net::URLRequestContextGetter* request_context_getter, |
48 const SafeBrowsingProtocolConfig& config) | 49 const SafeBrowsingProtocolConfig& config) |
49 : client_name_(config.client_name), | 50 : client_name_(config.client_name), |
50 request_context_getter_(request_context_getter), | 51 request_context_getter_(request_context_getter), |
51 url_prefix_(config.url_prefix) { | 52 url_prefix_(config.url_prefix) { |
52 DCHECK(!url_prefix_.empty()); | 53 DCHECK(!url_prefix_.empty()); |
53 | 54 |
54 if (request_context_getter) { | 55 if (request_context_getter) { |
55 // Set the upload URL and whether or not to send cookies with | 56 // Set the upload URL and whether or not to send cookies with |
56 // certificate reports sent to Safe Browsing servers. | 57 // certificate reports sent to Safe Browsing servers. |
57 bool use_insecure_certificate_upload_url = | 58 bool use_insecure_certificate_upload_url = |
58 CertificateErrorReporter::IsHttpUploadUrlSupported() && | 59 CertificateErrorReporter::IsHttpUploadUrlSupported(); |
59 strlen(kExtendedReportingUploadUrlInsecure) > 0; | |
60 | 60 |
61 CertificateErrorReporter::CookiesPreference cookies_preference; | 61 CertificateErrorReporter::CookiesPreference cookies_preference; |
62 GURL certificate_upload_url; | 62 GURL certificate_upload_url; |
63 if (use_insecure_certificate_upload_url) { | 63 if (use_insecure_certificate_upload_url) { |
64 cookies_preference = CertificateErrorReporter::DO_NOT_SEND_COOKIES; | 64 cookies_preference = CertificateErrorReporter::DO_NOT_SEND_COOKIES; |
65 certificate_upload_url = GURL(kExtendedReportingUploadUrlInsecure); | 65 certificate_upload_url = GURL(kExtendedReportingUploadUrlInsecure); |
66 } else { | 66 } else { |
67 cookies_preference = CertificateErrorReporter::SEND_COOKIES; | 67 cookies_preference = CertificateErrorReporter::SEND_COOKIES; |
68 certificate_upload_url = GURL(kExtendedReportingUploadUrlSecure); | 68 certificate_upload_url = GURL(kExtendedReportingUploadUrlSecure); |
69 } | 69 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 url_prefix_.c_str(), | 195 url_prefix_.c_str(), |
196 client_name_.c_str(), | 196 client_name_.c_str(), |
197 version_.c_str()); | 197 version_.c_str()); |
198 std::string api_key = google_apis::GetAPIKey(); | 198 std::string api_key = google_apis::GetAPIKey(); |
199 if (!api_key.empty()) { | 199 if (!api_key.empty()) { |
200 base::StringAppendF(&url, "&key=%s", | 200 base::StringAppendF(&url, "&key=%s", |
201 net::EscapeQueryParamValue(api_key, true).c_str()); | 201 net::EscapeQueryParamValue(api_key, true).c_str()); |
202 } | 202 } |
203 return GURL(url); | 203 return GURL(url); |
204 } | 204 } |
OLD | NEW |