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

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

Issue 14999008: Add a killswitch for CSD malware IP match and report feature. Use a new killswitch whitelist URL wh… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review comment and add unittest Created 7 years, 7 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 const std::vector<SBChunkDelete>& chunk_deletes) = 0; 157 const std::vector<SBChunkDelete>& chunk_deletes) = 0;
158 virtual void UpdateFinished(bool update_succeeded) = 0; 158 virtual void UpdateFinished(bool update_succeeded) = 0;
159 159
160 // Store the results of a GetHash response. In the case of empty results, we 160 // Store the results of a GetHash response. In the case of empty results, we
161 // cache the prefixes until the next update so that we don't have to issue 161 // cache the prefixes until the next update so that we don't have to issue
162 // further GetHash requests we know will be empty. 162 // further GetHash requests we know will be empty.
163 virtual void CacheHashResults( 163 virtual void CacheHashResults(
164 const std::vector<SBPrefix>& prefixes, 164 const std::vector<SBPrefix>& prefixes,
165 const std::vector<SBFullHashResult>& full_hits) = 0; 165 const std::vector<SBFullHashResult>& full_hits) = 0;
166 166
167 virtual bool MalwareIPMatchKillSwitchOn() = 0;
168
167 // The name of the bloom-filter file for the given database file. 169 // The name of the bloom-filter file for the given database file.
168 // NOTE(shess): OBSOLETE. Present for deleting stale files. 170 // NOTE(shess): OBSOLETE. Present for deleting stale files.
169 static base::FilePath BloomFilterForFilename( 171 static base::FilePath BloomFilterForFilename(
170 const base::FilePath& db_filename); 172 const base::FilePath& db_filename);
171 173
172 // The name of the prefix set file for the given database file. 174 // The name of the prefix set file for the given database file.
173 static base::FilePath PrefixSetForFilename(const base::FilePath& db_filename); 175 static base::FilePath PrefixSetForFilename(const base::FilePath& db_filename);
174 176
175 // Filename for malware and phishing URL database. 177 // Filename for malware and phishing URL database.
176 static base::FilePath BrowseDBFilename( 178 static base::FilePath BrowseDBFilename(
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 virtual bool UpdateStarted(std::vector<SBListChunkRanges>* lists) OVERRIDE; 273 virtual bool UpdateStarted(std::vector<SBListChunkRanges>* lists) OVERRIDE;
272 virtual void InsertChunks(const std::string& list_name, 274 virtual void InsertChunks(const std::string& list_name,
273 const SBChunkList& chunks) OVERRIDE; 275 const SBChunkList& chunks) OVERRIDE;
274 virtual void DeleteChunks( 276 virtual void DeleteChunks(
275 const std::vector<SBChunkDelete>& chunk_deletes) OVERRIDE; 277 const std::vector<SBChunkDelete>& chunk_deletes) OVERRIDE;
276 virtual void UpdateFinished(bool update_succeeded) OVERRIDE; 278 virtual void UpdateFinished(bool update_succeeded) OVERRIDE;
277 virtual void CacheHashResults( 279 virtual void CacheHashResults(
278 const std::vector<SBPrefix>& prefixes, 280 const std::vector<SBPrefix>& prefixes,
279 const std::vector<SBFullHashResult>& full_hits) OVERRIDE; 281 const std::vector<SBFullHashResult>& full_hits) OVERRIDE;
280 282
283 // Returns the value of malware_kill_switch_;
284 virtual bool MalwareIPMatchKillSwitchOn() OVERRIDE;
285
281 private: 286 private:
282 friend class SafeBrowsingDatabaseTest; 287 friend class SafeBrowsingDatabaseTest;
283 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseTest, HashCaching); 288 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseTest, HashCaching);
284 289
285 // A SafeBrowsing whitelist contains a list of whitelisted full-hashes (stored 290 // A SafeBrowsing whitelist contains a list of whitelisted full-hashes (stored
286 // in a sorted vector) as well as a boolean flag indicating whether all 291 // in a sorted vector) as well as a boolean flag indicating whether all
287 // lookups in the whitelist should be considered matches for safety. 292 // lookups in the whitelist should be considered matches for safety.
288 typedef std::pair<std::vector<SBFullHash>, bool> SBWhitelist; 293 typedef std::pair<std::vector<SBFullHash>, bool> SBWhitelist;
289 294
290 // Returns true if the whitelist is disabled or if any of the given hashes 295 // Returns true if the whitelist is disabled or if any of the given hashes
(...skipping 11 matching lines...) Expand all
302 // Load the prefix set off disk, if available. 307 // Load the prefix set off disk, if available.
303 void LoadPrefixSet(); 308 void LoadPrefixSet();
304 309
305 // Writes the current prefix set to disk. 310 // Writes the current prefix set to disk.
306 void WritePrefixSet(); 311 void WritePrefixSet();
307 312
308 // Loads the given full-length hashes to the given whitelist. If the number 313 // Loads the given full-length hashes to the given whitelist. If the number
309 // of hashes is too large or if the kill switch URL is on the whitelist 314 // of hashes is too large or if the kill switch URL is on the whitelist
310 // we will whitelist everything. 315 // we will whitelist everything.
311 void LoadWhitelist(const std::vector<SBAddFullHash>& full_hashes, 316 void LoadWhitelist(const std::vector<SBAddFullHash>& full_hashes,
312 SBWhitelist* whitelist); 317 SBWhitelist* whitelist,
318 bool check_malware_killswitch);
313 319
314 // Call this method if an error occured with the given whitelist. This will 320 // Call this method if an error occured with the given whitelist. This will
315 // result in all lookups to the whitelist to return true. 321 // result in all lookups to the whitelist to return true.
316 void WhitelistEverything(SBWhitelist* whitelist); 322 void WhitelistEverything(SBWhitelist* whitelist);
317 323
318 // Helpers for handling database corruption. 324 // Helpers for handling database corruption.
319 // |OnHandleCorruptDatabase()| runs |ResetDatabase()| and sets 325 // |OnHandleCorruptDatabase()| runs |ResetDatabase()| and sets
320 // |corruption_detected_|, |HandleCorruptDatabase()| posts 326 // |corruption_detected_|, |HandleCorruptDatabase()| posts
321 // |OnHandleCorruptDatabase()| to the current thread, to be run 327 // |OnHandleCorruptDatabase()| to the current thread, to be run
322 // after the current task completes. 328 // after the current task completes.
(...skipping 10 matching lines...) Expand all
333 void InsertSubChunks(safe_browsing_util::ListType list_id, 339 void InsertSubChunks(safe_browsing_util::ListType list_id,
334 const SBChunkList& chunks); 340 const SBChunkList& chunks);
335 341
336 // Returns the size in bytes of the store after the update. 342 // Returns the size in bytes of the store after the update.
337 int64 UpdateHashPrefixStore(const base::FilePath& store_filename, 343 int64 UpdateHashPrefixStore(const base::FilePath& store_filename,
338 SafeBrowsingStore* store, 344 SafeBrowsingStore* store,
339 FailureType failure_type); 345 FailureType failure_type);
340 void UpdateBrowseStore(); 346 void UpdateBrowseStore();
341 void UpdateWhitelistStore(const base::FilePath& store_filename, 347 void UpdateWhitelistStore(const base::FilePath& store_filename,
342 SafeBrowsingStore* store, 348 SafeBrowsingStore* store,
343 SBWhitelist* whitelist); 349 SBWhitelist* whitelist,
350 bool check_malware_killswitch);
344 351
345 // Used to verify that various calls are made from the thread the 352 // Used to verify that various calls are made from the thread the
346 // object was created on. 353 // object was created on.
347 base::MessageLoop* creation_loop_; 354 base::MessageLoop* creation_loop_;
348 355
349 // Lock for protecting access to variables that may be used on the 356 // Lock for protecting access to variables that may be used on the
350 // IO thread. This includes |prefix_set_|, |full_browse_hashes_|, 357 // IO thread. This includes |prefix_set_|, |full_browse_hashes_|,
351 // |pending_browse_hashes_|, |prefix_miss_cache_|, |csd_whitelist_|, 358 // |pending_browse_hashes_|, |prefix_miss_cache_|, |csd_whitelist_|,
352 // and |csd_whitelist_all_urls_|. 359 // and |malware_kill_switch_|.
353 base::Lock lookup_lock_; 360 base::Lock lookup_lock_;
354 361
355 // Underlying persistent store for chunk data. 362 // Underlying persistent store for chunk data.
356 // For browsing related (phishing and malware URLs) chunks and prefixes. 363 // For browsing related (phishing and malware URLs) chunks and prefixes.
357 base::FilePath browse_filename_; 364 base::FilePath browse_filename_;
358 scoped_ptr<SafeBrowsingStore> browse_store_; 365 scoped_ptr<SafeBrowsingStore> browse_store_;
359 366
360 // For download related (download URL and binary hash) chunks and prefixes. 367 // For download related (download URL and binary hash) chunks and prefixes.
361 base::FilePath download_filename_; 368 base::FilePath download_filename_;
362 scoped_ptr<SafeBrowsingStore> download_store_; 369 scoped_ptr<SafeBrowsingStore> download_store_;
363 370
364 // For the client-side phishing detection whitelist chunks and full-length 371 // For the client-side phishing detection whitelist chunks and full-length
365 // hashes. This list only contains 256 bit hashes. 372 // hashes. This list only contains 256 bit hashes.
366 base::FilePath csd_whitelist_filename_; 373 base::FilePath csd_whitelist_filename_;
367 scoped_ptr<SafeBrowsingStore> csd_whitelist_store_; 374 scoped_ptr<SafeBrowsingStore> csd_whitelist_store_;
368 375
369 // For the download whitelist chunks and full-length hashes. This list only 376 // For the download whitelist chunks and full-length hashes. This list only
370 // contains 256 bit hashes. 377 // contains 256 bit hashes.
371 base::FilePath download_whitelist_filename_; 378 base::FilePath download_whitelist_filename_;
372 scoped_ptr<SafeBrowsingStore> download_whitelist_store_; 379 scoped_ptr<SafeBrowsingStore> download_whitelist_store_;
373 380
374 // For extension IDs. 381 // For extension IDs.
375 base::FilePath extension_blacklist_filename_; 382 base::FilePath extension_blacklist_filename_;
376 scoped_ptr<SafeBrowsingStore> extension_blacklist_store_; 383 scoped_ptr<SafeBrowsingStore> extension_blacklist_store_;
377 384
378 SBWhitelist csd_whitelist_; 385 SBWhitelist csd_whitelist_;
379 SBWhitelist download_whitelist_; 386 SBWhitelist download_whitelist_;
380 SBWhitelist extension_blacklist_; 387 SBWhitelist extension_blacklist_;
388 bool csd_malware_ipmatch_killswitch_on_;
381 389
382 // Cached browse store related full-hash items, ordered by prefix for 390 // Cached browse store related full-hash items, ordered by prefix for
383 // efficient scanning. 391 // efficient scanning.
384 // |full_browse_hashes_| are items from |browse_store_|, 392 // |full_browse_hashes_| are items from |browse_store_|,
385 // |pending_browse_hashes_| are items from |CacheHashResults()|, which 393 // |pending_browse_hashes_| are items from |CacheHashResults()|, which
386 // will be pushed to the store on the next update. 394 // will be pushed to the store on the next update.
387 std::vector<SBAddFullHash> full_browse_hashes_; 395 std::vector<SBAddFullHash> full_browse_hashes_;
388 std::vector<SBAddFullHash> pending_browse_hashes_; 396 std::vector<SBAddFullHash> pending_browse_hashes_;
389 397
390 // Cache of prefixes that returned empty results (no full hash 398 // Cache of prefixes that returned empty results (no full hash
(...skipping 12 matching lines...) Expand all
403 // Set to true if any chunks are added or deleted during an update. 411 // Set to true if any chunks are added or deleted during an update.
404 // Used to optimize away database update. 412 // Used to optimize away database update.
405 bool change_detected_; 413 bool change_detected_;
406 414
407 // Used to check if a prefix was in the database. 415 // Used to check if a prefix was in the database.
408 base::FilePath prefix_set_filename_; 416 base::FilePath prefix_set_filename_;
409 scoped_ptr<safe_browsing::PrefixSet> prefix_set_; 417 scoped_ptr<safe_browsing::PrefixSet> prefix_set_;
410 }; 418 };
411 419
412 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 420 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698