Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/safe_browsing/client_side_detection_service.h

Issue 7635010: Add support for client-side phishing detection for non-UMA users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 18 matching lines...) Expand all
29 #include "base/memory/scoped_ptr.h" 29 #include "base/memory/scoped_ptr.h"
30 #include "base/task.h" 30 #include "base/task.h"
31 #include "base/time.h" 31 #include "base/time.h"
32 #include "content/common/notification_observer.h" 32 #include "content/common/notification_observer.h"
33 #include "content/common/notification_registrar.h" 33 #include "content/common/notification_registrar.h"
34 #include "content/common/url_fetcher.h" 34 #include "content/common/url_fetcher.h"
35 #include "googleurl/src/gurl.h" 35 #include "googleurl/src/gurl.h"
36 #include "net/base/net_util.h" 36 #include "net/base/net_util.h"
37 37
38 class RenderProcessHost; 38 class RenderProcessHost;
39 class SafeBrowsingService;
39 40
40 namespace base { 41 namespace base {
41 class TimeDelta; 42 class TimeDelta;
42 } 43 }
43 44
44 namespace net { 45 namespace net {
45 class URLRequestContextGetter; 46 class URLRequestContextGetter;
46 class URLRequestStatus; 47 class URLRequestStatus;
47 } // namespace net 48 } // namespace net
48 49
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // validating the model. 145 // validating the model.
145 virtual void EndFetchModel(ClientModelStatus status); // Virtual for testing. 146 virtual void EndFetchModel(ClientModelStatus status); // Virtual for testing.
146 147
147 private: 148 private:
148 friend class ClientSideDetectionServiceTest; 149 friend class ClientSideDetectionServiceTest;
149 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, FetchModelTest); 150 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, FetchModelTest);
150 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetBadSubnets); 151 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetBadSubnets);
151 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, IsBadIpAddress); 152 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, IsBadIpAddress);
152 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, 153 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest,
153 ModelHasValidHashIds); 154 ModelHasValidHashIds);
155 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest,
156 SanitizeRequestForPingback);
154 157
155 // CacheState holds all information necessary to respond to a caller without 158 // CacheState holds all information necessary to respond to a caller without
156 // actually making a HTTP request. 159 // actually making a HTTP request.
157 struct CacheState { 160 struct CacheState {
158 bool is_phishing; 161 bool is_phishing;
159 base::Time timestamp; 162 base::Time timestamp;
160 163
161 CacheState(bool phish, base::Time time); 164 CacheState(bool phish, base::Time time);
162 }; 165 };
163 typedef std::map<GURL, linked_ptr<CacheState> > PhishingCache; 166 typedef std::map<GURL, linked_ptr<CacheState> > PhishingCache;
(...skipping 10 matching lines...) Expand all
174 static const char kClientReportPhishingUrl[]; 177 static const char kClientReportPhishingUrl[];
175 static const char kClientModelUrl[]; 178 static const char kClientModelUrl[];
176 static const size_t kMaxModelSizeBytes; 179 static const size_t kMaxModelSizeBytes;
177 static const int kMaxReportsPerInterval; 180 static const int kMaxReportsPerInterval;
178 static const int kClientModelFetchIntervalMs; 181 static const int kClientModelFetchIntervalMs;
179 static const int kInitialClientModelFetchDelayMs; 182 static const int kInitialClientModelFetchDelayMs;
180 static const base::TimeDelta kReportsInterval; 183 static const base::TimeDelta kReportsInterval;
181 static const base::TimeDelta kNegativeCacheInterval; 184 static const base::TimeDelta kNegativeCacheInterval;
182 static const base::TimeDelta kPositiveCacheInterval; 185 static const base::TimeDelta kPositiveCacheInterval;
183 186
187 // Given a ClientSidePhishingRequest populated by the renderer and browser
188 // feature extractors, sanitizes it so that no data specifically identifying
189 // the URL or page content is included. This is used when sending a pingback
190 // if the user is not opted in to UMA.
191 static void SanitizeRequestForPingback(
192 const ClientPhishingRequest& original_request,
193 ClientPhishingRequest* sanitized_request);
194
184 // Starts sending the request to the client-side detection frontends. 195 // Starts sending the request to the client-side detection frontends.
185 // This method takes ownership of both pointers. 196 // This method takes ownership of both pointers.
186 void StartClientReportPhishingRequest( 197 void StartClientReportPhishingRequest(
187 ClientPhishingRequest* verdict, 198 ClientPhishingRequest* verdict,
188 ClientReportPhishingRequestCallback* callback); 199 ClientReportPhishingRequestCallback* callback);
189 200
190 // Called by OnURLFetchComplete to handle the response from fetching the 201 // Called by OnURLFetchComplete to handle the response from fetching the
191 // model. 202 // model.
192 void HandleModelResponse(const URLFetcher* source, 203 void HandleModelResponse(const URLFetcher* source,
193 const GURL& url, 204 const GURL& url,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 241
231 // Returns true iff all the hash id's in the client-side model point to 242 // Returns true iff all the hash id's in the client-side model point to
232 // valid hashes in the model. 243 // valid hashes in the model.
233 static bool ModelHasValidHashIds(const ClientSideModel& model); 244 static bool ModelHasValidHashIds(const ClientSideModel& model);
234 245
235 std::string model_str_; 246 std::string model_str_;
236 scoped_ptr<ClientSideModel> model_; 247 scoped_ptr<ClientSideModel> model_;
237 scoped_ptr<base::TimeDelta> model_max_age_; 248 scoped_ptr<base::TimeDelta> model_max_age_;
238 scoped_ptr<URLFetcher> model_fetcher_; 249 scoped_ptr<URLFetcher> model_fetcher_;
239 250
251 // This pointer may be NULL if SafeBrowsing is disabled.
252 scoped_refptr<SafeBrowsingService> sb_service_;
253
240 // Map of client report phishing request to the corresponding callback that 254 // Map of client report phishing request to the corresponding callback that
241 // has to be invoked when the request is done. 255 // has to be invoked when the request is done.
242 struct ClientReportInfo; 256 struct ClientReportInfo;
243 std::map<const URLFetcher*, ClientReportInfo*> client_phishing_reports_; 257 std::map<const URLFetcher*, ClientReportInfo*> client_phishing_reports_;
244 258
245 // Cache of completed requests. Used to satisfy requests for the same urls 259 // Cache of completed requests. Used to satisfy requests for the same urls
246 // as long as the next request falls within our caching window (which is 260 // as long as the next request falls within our caching window (which is
247 // determined by kNegativeCacheInterval and kPositiveCacheInterval). The 261 // determined by kNegativeCacheInterval and kPositiveCacheInterval). The
248 // size of this cache is limited by kMaxReportsPerDay * 262 // size of this cache is limited by kMaxReportsPerDay *
249 // ceil(InDays(max(kNegativeCacheInterval, kPositiveCacheInterval))). 263 // ceil(InDays(max(kNegativeCacheInterval, kPositiveCacheInterval))).
(...skipping 19 matching lines...) Expand all
269 // this map to speed up lookups. 283 // this map to speed up lookups.
270 BadSubnetMap bad_subnets_; 284 BadSubnetMap bad_subnets_;
271 285
272 NotificationRegistrar registrar_; 286 NotificationRegistrar registrar_;
273 287
274 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); 288 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService);
275 }; 289 };
276 } // namepsace safe_browsing 290 } // namepsace safe_browsing
277 291
278 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ 292 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698