| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 // A class that implements Chrome's interface with the SafeBrowsing protocol. | 9 // A class that implements Chrome's interface with the SafeBrowsing protocol. |
| 10 // The SafeBrowsingProtocolManager handles formatting and making requests of, | 10 // The SafeBrowsingProtocolManager handles formatting and making requests of, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 class SafeBrowsingProtocolManager : public URLFetcher::Delegate { | 45 class SafeBrowsingProtocolManager : public URLFetcher::Delegate { |
| 46 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestBackOffTimes); | 46 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestBackOffTimes); |
| 47 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestChunkStrings); | 47 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestChunkStrings); |
| 48 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestGetHashUrl); | 48 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestGetHashUrl); |
| 49 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, | 49 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, |
| 50 TestGetHashBackOffTimes); | 50 TestGetHashBackOffTimes); |
| 51 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestMacKeyUrl); | 51 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestMacKeyUrl); |
| 52 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, | 52 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, |
| 53 TestSafeBrowsingReportUrl); | 53 TestSafeBrowsingHitUrl); |
| 54 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, |
| 55 TestMalwareDetailsUrl); |
| 54 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestNextChunkUrl); | 56 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestNextChunkUrl); |
| 55 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestUpdateUrl); | 57 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestUpdateUrl); |
| 56 friend class SafeBrowsingServiceTest; | 58 friend class SafeBrowsingServiceTest; |
| 57 | 59 |
| 58 public: | 60 public: |
| 59 // Constructs a SafeBrowsingProtocolManager for |sb_service| that issues | 61 // Constructs a SafeBrowsingProtocolManager for |sb_service| that issues |
| 60 // network requests using |request_context_getter|. When |disable_auto_update| | 62 // network requests using |request_context_getter|. When |disable_auto_update| |
| 61 // is true, protocol manager won't schedule next update until | 63 // is true, protocol manager won't schedule next update until |
| 62 // ForceScheduleNextUpdate is called. | 64 // ForceScheduleNextUpdate is called. |
| 63 SafeBrowsingProtocolManager(SafeBrowsingService* sb_service, | 65 SafeBrowsingProtocolManager(SafeBrowsingService* sb_service, |
| 64 const std::string& client_name, | 66 const std::string& client_name, |
| 65 const std::string& client_key, | 67 const std::string& client_key, |
| 66 const std::string& wrapped_key, | 68 const std::string& wrapped_key, |
| 67 URLRequestContextGetter* request_context_getter, | 69 URLRequestContextGetter* request_context_getter, |
| 68 const std::string& info_url_prefix, | 70 const std::string& http_url_prefix, |
| 69 const std::string& mackey_url_prefix, | 71 const std::string& https_url_prefix, |
| 70 bool disable_auto_update); | 72 bool disable_auto_update); |
| 71 virtual ~SafeBrowsingProtocolManager(); | 73 virtual ~SafeBrowsingProtocolManager(); |
| 72 | 74 |
| 73 // Sets up the update schedule and internal state for making periodic requests | 75 // Sets up the update schedule and internal state for making periodic requests |
| 74 // of the SafeBrowsing service. | 76 // of the SafeBrowsing service. |
| 75 void Initialize(); | 77 void Initialize(); |
| 76 | 78 |
| 77 // URLFetcher::Delegate interface. | 79 // URLFetcher::Delegate interface. |
| 78 virtual void OnURLFetchComplete(const URLFetcher* source, | 80 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 79 const GURL& url, | 81 const GURL& url, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 110 | 112 |
| 111 // For UMA users we report to Google when a SafeBrowsing interstitial is shown | 113 // For UMA users we report to Google when a SafeBrowsing interstitial is shown |
| 112 // to the user. We assume that the threat type is either URL_MALWARE or | 114 // to the user. We assume that the threat type is either URL_MALWARE or |
| 113 // URL_PHISHING. | 115 // URL_PHISHING. |
| 114 void ReportSafeBrowsingHit(const GURL& malicious_url, | 116 void ReportSafeBrowsingHit(const GURL& malicious_url, |
| 115 const GURL& page_url, | 117 const GURL& page_url, |
| 116 const GURL& referrer_url, | 118 const GURL& referrer_url, |
| 117 bool is_subresource, | 119 bool is_subresource, |
| 118 SafeBrowsingService::UrlCheckResult threat_type); | 120 SafeBrowsingService::UrlCheckResult threat_type); |
| 119 | 121 |
| 122 // Users can opt-in on the SafeBrowsing interstitial to send detailed |
| 123 // malware reports. |report| is the serialized report. |
| 124 void ReportMalwareDetails(const std::string& report); |
| 120 | 125 |
| 121 // Setter for additional_query_. To make sure the additional_query_ won't | 126 // Setter for additional_query_. To make sure the additional_query_ won't |
| 122 // be changed in the middle of an update, caller (e.g.: SafeBrowsingService) | 127 // be changed in the middle of an update, caller (e.g.: SafeBrowsingService) |
| 123 // should call this after callbacks triggered in UpdateFinished() or before | 128 // should call this after callbacks triggered in UpdateFinished() or before |
| 124 // IssueUpdateRequest(). | 129 // IssueUpdateRequest(). |
| 125 void set_additional_query(const std::string& query) { | 130 void set_additional_query(const std::string& query) { |
| 126 additional_query_ = query; | 131 additional_query_ = query; |
| 127 } | 132 } |
| 128 const std::string& additional_query() const { | 133 const std::string& additional_query() const { |
| 129 return additional_query_; | 134 return additional_query_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 151 const std::string& additional_query); | 156 const std::string& additional_query); |
| 152 | 157 |
| 153 // Generates Update URL for querying about the latest set of chunk updates. | 158 // Generates Update URL for querying about the latest set of chunk updates. |
| 154 // Append "wrkey=xxx" to the URL when |use_mac| is true. | 159 // Append "wrkey=xxx" to the URL when |use_mac| is true. |
| 155 GURL UpdateUrl(bool use_mac) const; | 160 GURL UpdateUrl(bool use_mac) const; |
| 156 // Generates GetHash request URL for retrieving full hashes. | 161 // Generates GetHash request URL for retrieving full hashes. |
| 157 // Append "wrkey=xxx" to the URL when |use_mac| is true. | 162 // Append "wrkey=xxx" to the URL when |use_mac| is true. |
| 158 GURL GetHashUrl(bool use_mac) const; | 163 GURL GetHashUrl(bool use_mac) const; |
| 159 // Generates new MAC client key request URL. | 164 // Generates new MAC client key request URL. |
| 160 GURL MacKeyUrl() const; | 165 GURL MacKeyUrl() const; |
| 161 // Generates URL for reporting malicious pages. | 166 // Generates URL for reporting safe browsing hits for UMA users. |
| 162 GURL SafeBrowsingReportUrl( | 167 GURL SafeBrowsingHitUrl( |
| 163 const GURL& malicious_url, const GURL& page_url, const GURL& referrer_url, | 168 const GURL& malicious_url, const GURL& page_url, const GURL& referrer_url, |
| 164 bool is_subresource, | 169 bool is_subresource, |
| 165 SafeBrowsingService::UrlCheckResult threat_type) const; | 170 SafeBrowsingService::UrlCheckResult threat_type) const; |
| 171 // Generates URL for reporting malware details for users who opt-in. |
| 172 GURL MalwareDetailsUrl() const; |
| 173 |
| 166 // Composes a ChunkUrl based on input string. | 174 // Composes a ChunkUrl based on input string. |
| 167 GURL NextChunkUrl(const std::string& input) const; | 175 GURL NextChunkUrl(const std::string& input) const; |
| 168 | 176 |
| 169 // Returns the time (in milliseconds) for the next update request. If | 177 // Returns the time (in milliseconds) for the next update request. If |
| 170 // 'back_off' is true, the time returned will increment an error count and | 178 // 'back_off' is true, the time returned will increment an error count and |
| 171 // return the appriate next time (see ScheduleNextUpdate below). | 179 // return the appriate next time (see ScheduleNextUpdate below). |
| 172 int GetNextUpdateTime(bool back_off); | 180 int GetNextUpdateTime(bool back_off); |
| 173 | 181 |
| 174 // Worker function for calculating GetHash and Update backoff times (in | 182 // Worker function for calculating GetHash and Update backoff times (in |
| 175 // seconds). 'Multiplier' is doubled for each consecutive error between the | 183 // seconds). 'Multiplier' is doubled for each consecutive error between the |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 // Current product version sent in each request. | 298 // Current product version sent in each request. |
| 291 std::string version_; | 299 std::string version_; |
| 292 | 300 |
| 293 // Used for measuring chunk request latency. | 301 // Used for measuring chunk request latency. |
| 294 base::Time chunk_request_start_; | 302 base::Time chunk_request_start_; |
| 295 | 303 |
| 296 // Tracks the size of each update (in bytes). | 304 // Tracks the size of each update (in bytes). |
| 297 int update_size_; | 305 int update_size_; |
| 298 | 306 |
| 299 // Track outstanding SafeBrowsing report fetchers for clean up. | 307 // Track outstanding SafeBrowsing report fetchers for clean up. |
| 308 // We add both "hit" and "detail" fetchers in this set. |
| 300 std::set<const URLFetcher*> safebrowsing_reports_; | 309 std::set<const URLFetcher*> safebrowsing_reports_; |
| 301 | 310 |
| 302 // The safe browsing client name sent in each request. | 311 // The safe browsing client name sent in each request. |
| 303 std::string client_name_; | 312 std::string client_name_; |
| 304 | 313 |
| 305 // A string that is appended to the end of URLs for download, gethash, | 314 // A string that is appended to the end of URLs for download, gethash, |
| 306 // newkey, malware report and chunk update requests. | 315 // newkey, safebrowsing hits and chunk update requests. |
| 307 std::string additional_query_; | 316 std::string additional_query_; |
| 308 | 317 |
| 309 // The context we use to issue network requests. | 318 // The context we use to issue network requests. |
| 310 scoped_refptr<URLRequestContextGetter> request_context_getter_; | 319 scoped_refptr<URLRequestContextGetter> request_context_getter_; |
| 311 | 320 |
| 312 // URL prefix where browser fetches safebrowsing chunk updates, hashes, and | 321 // URL prefix where browser fetches safebrowsing chunk updates, hashes, and |
| 313 // reports malware. | 322 // reports hits to the safebrowsing list for UMA users. |
| 314 std::string info_url_prefix_; | 323 std::string http_url_prefix_; |
| 315 | 324 |
| 316 // URL prefix where browser fetches MAC client key. | 325 // URL prefix where browser fetches MAC client key, and reports detailed |
| 317 std::string mackey_url_prefix_; | 326 // malware reports for users who opt-in. |
| 327 std::string https_url_prefix_; |
| 318 | 328 |
| 319 // When true, protocol manager will not start an update unless | 329 // When true, protocol manager will not start an update unless |
| 320 // ForceScheduleNextUpdate() is called. This is set for testing purpose. | 330 // ForceScheduleNextUpdate() is called. This is set for testing purpose. |
| 321 bool disable_auto_update_; | 331 bool disable_auto_update_; |
| 322 | 332 |
| 323 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager); | 333 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager); |
| 324 }; | 334 }; |
| 325 | 335 |
| 326 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 336 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
| OLD | NEW |