| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Helper class which handles communication with the SafeBrowsing backends for | 5 // Helper class which handles communication with the SafeBrowsing backends for |
| 6 // client-side phishing detection. This class is used to fetch the client-side | 6 // client-side phishing detection. This class is used to fetch the client-side |
| 7 // model and send it to all renderers. This class is also used to send a ping | 7 // model and send it to all renderers. This class is also used to send a ping |
| 8 // back to Google to verify if a particular site is really phishing or not. | 8 // back to Google to verify if a particular site is really phishing or not. |
| 9 // | 9 // |
| 10 // This class is not thread-safe and expects all calls to be made on the UI | 10 // This class is not thread-safe and expects all calls to be made on the UI |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 class TimeDelta; | 43 class TimeDelta; |
| 44 } | 44 } |
| 45 | 45 |
| 46 namespace net { | 46 namespace net { |
| 47 class URLRequestContextGetter; | 47 class URLRequestContextGetter; |
| 48 class URLRequestStatus; | 48 class URLRequestStatus; |
| 49 } // namespace net | 49 } // namespace net |
| 50 | 50 |
| 51 namespace safe_browsing { | 51 namespace safe_browsing { |
| 52 class ClientPhishingRequest; | 52 class ClientPhishingRequest; |
| 53 class ClientPhishingResponse; |
| 53 class ClientSideModel; | 54 class ClientSideModel; |
| 54 | 55 |
| 55 class ClientSideDetectionService : public URLFetcher::Delegate, | 56 class ClientSideDetectionService : public URLFetcher::Delegate, |
| 56 public NotificationObserver { | 57 public NotificationObserver { |
| 57 public: | 58 public: |
| 58 typedef Callback2<GURL /* phishing URL */, bool /* is phishing */>::Type | 59 typedef Callback2<GURL /* phishing URL */, bool /* is phishing */>::Type |
| 59 ClientReportPhishingRequestCallback; | 60 ClientReportPhishingRequestCallback; |
| 60 | 61 |
| 61 virtual ~ClientSideDetectionService(); | 62 virtual ~ClientSideDetectionService(); |
| 62 | 63 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 // validating the model. | 161 // validating the model. |
| 161 virtual void EndFetchModel(ClientModelStatus status); // Virtual for testing. | 162 virtual void EndFetchModel(ClientModelStatus status); // Virtual for testing. |
| 162 | 163 |
| 163 private: | 164 private: |
| 164 friend class ClientSideDetectionServiceTest; | 165 friend class ClientSideDetectionServiceTest; |
| 165 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, FetchModelTest); | 166 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, FetchModelTest); |
| 166 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetBadSubnets); | 167 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetBadSubnets); |
| 167 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetEnabled); | 168 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetEnabled); |
| 168 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, IsBadIpAddress); | 169 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, IsBadIpAddress); |
| 169 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, | 170 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, |
| 171 IsFalsePositiveResponse); |
| 172 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, |
| 170 ModelHasValidHashIds); | 173 ModelHasValidHashIds); |
| 171 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, | 174 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, |
| 172 SanitizeRequestForPingback); | 175 SanitizeRequestForPingback); |
| 173 | 176 |
| 174 // CacheState holds all information necessary to respond to a caller without | 177 // CacheState holds all information necessary to respond to a caller without |
| 175 // actually making a HTTP request. | 178 // actually making a HTTP request. |
| 176 struct CacheState { | 179 struct CacheState { |
| 177 bool is_phishing; | 180 bool is_phishing; |
| 178 base::Time timestamp; | 181 base::Time timestamp; |
| 179 | 182 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // |bad_subnets| for faster lookups. This method is static to simplify | 259 // |bad_subnets| for faster lookups. This method is static to simplify |
| 257 // testing. | 260 // testing. |
| 258 static void SetBadSubnets(const ClientSideModel& model, | 261 static void SetBadSubnets(const ClientSideModel& model, |
| 259 BadSubnetMap* bad_subnets); | 262 BadSubnetMap* bad_subnets); |
| 260 | 263 |
| 261 | 264 |
| 262 // Returns true iff all the hash id's in the client-side model point to | 265 // Returns true iff all the hash id's in the client-side model point to |
| 263 // valid hashes in the model. | 266 // valid hashes in the model. |
| 264 static bool ModelHasValidHashIds(const ClientSideModel& model); | 267 static bool ModelHasValidHashIds(const ClientSideModel& model); |
| 265 | 268 |
| 269 // Returns true iff the response is phishing (phishy() is true) and if the |
| 270 // given URL matches one of the whitelisted expressions in the given |
| 271 // ClientPhishingResponse. |
| 272 static bool IsFalsePositiveResponse(const GURL& url, |
| 273 const ClientPhishingResponse& response); |
| 274 |
| 266 // Whether the service is running or not. When the service is not running, | 275 // Whether the service is running or not. When the service is not running, |
| 267 // it won't download the model nor report detected phishing URLs. | 276 // it won't download the model nor report detected phishing URLs. |
| 268 bool enabled_; | 277 bool enabled_; |
| 269 | 278 |
| 270 std::string model_str_; | 279 std::string model_str_; |
| 271 scoped_ptr<ClientSideModel> model_; | 280 scoped_ptr<ClientSideModel> model_; |
| 272 scoped_ptr<base::TimeDelta> model_max_age_; | 281 scoped_ptr<base::TimeDelta> model_max_age_; |
| 273 scoped_ptr<URLFetcher> model_fetcher_; | 282 scoped_ptr<URLFetcher> model_fetcher_; |
| 274 | 283 |
| 275 // This pointer may be NULL if SafeBrowsing is disabled. | 284 // This pointer may be NULL if SafeBrowsing is disabled. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // this map to speed up lookups. | 319 // this map to speed up lookups. |
| 311 BadSubnetMap bad_subnets_; | 320 BadSubnetMap bad_subnets_; |
| 312 | 321 |
| 313 NotificationRegistrar registrar_; | 322 NotificationRegistrar registrar_; |
| 314 | 323 |
| 315 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); | 324 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); |
| 316 }; | 325 }; |
| 317 } // namepsace safe_browsing | 326 } // namepsace safe_browsing |
| 318 | 327 |
| 319 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ | 328 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ |
| OLD | NEW |