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

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

Issue 1638223003: Add support for a module whitelist (goog-whitemodule-digest256) to the safe browsing db (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
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 <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 24 matching lines...) Expand all
35 public: 35 public:
36 SafeBrowsingDatabaseFactory() { } 36 SafeBrowsingDatabaseFactory() { }
37 virtual ~SafeBrowsingDatabaseFactory() { } 37 virtual ~SafeBrowsingDatabaseFactory() { }
38 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase( 38 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase(
39 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 39 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
40 bool enable_download_protection, 40 bool enable_download_protection,
41 bool enable_client_side_whitelist, 41 bool enable_client_side_whitelist,
42 bool enable_download_whitelist, 42 bool enable_download_whitelist,
43 bool enable_extension_blacklist, 43 bool enable_extension_blacklist,
44 bool enable_ip_blacklist, 44 bool enable_ip_blacklist,
45 bool enable_unwanted_software_list) = 0; 45 bool enable_unwanted_software_list,
46 bool enable_module_whitelist) = 0;
46 47
47 private: 48 private:
48 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactory); 49 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactory);
49 }; 50 };
50 51
51 // Encapsulates on-disk databases that for safebrowsing. There are 52 // Encapsulates on-disk databases that for safebrowsing. There are
52 // four databases: browse, download, download whitelist and 53 // four databases: browse, download, download whitelist and
53 // client-side detection (csd) whitelist databases. The browse database contains 54 // client-side detection (csd) whitelist databases. The browse database contains
54 // information about phishing and malware urls. The download database contains 55 // information about phishing and malware urls. The download database contains
55 // URLs for bad binaries (e.g: those containing virus) and hash of 56 // URLs for bad binaries (e.g: those containing virus) and hash of
(...skipping 10 matching lines...) Expand all
66 // It is not thread safe. 67 // It is not thread safe.
67 // The browse list and off-domain inclusion whitelist are always on; 68 // The browse list and off-domain inclusion whitelist are always on;
68 // availability of other lists is controlled by the flags on this method. 69 // availability of other lists is controlled by the flags on this method.
69 static SafeBrowsingDatabase* Create( 70 static SafeBrowsingDatabase* Create(
70 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 71 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
71 bool enable_download_protection, 72 bool enable_download_protection,
72 bool enable_client_side_whitelist, 73 bool enable_client_side_whitelist,
73 bool enable_download_whitelist, 74 bool enable_download_whitelist,
74 bool enable_extension_blacklist, 75 bool enable_extension_blacklist,
75 bool enable_ip_blacklist, 76 bool enable_ip_blacklist,
76 bool enable_unwanted_software_list); 77 bool enable_unwanted_software_list,
78 bool enable_module_whitelist);
77 79
78 // Makes the passed |factory| the factory used to instantiate 80 // Makes the passed |factory| the factory used to instantiate
79 // a SafeBrowsingDatabase. This is used for tests. 81 // a SafeBrowsingDatabase. This is used for tests.
80 static void RegisterFactory(SafeBrowsingDatabaseFactory* factory) { 82 static void RegisterFactory(SafeBrowsingDatabaseFactory* factory) {
81 factory_ = factory; 83 factory_ = factory;
82 } 84 }
83 85
84 virtual ~SafeBrowsingDatabase(); 86 virtual ~SafeBrowsingDatabase();
85 87
86 // Initializes the database with the given filename. 88 // Initializes the database with the given filename.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 const base::FilePath& side_effect_free_whitelist_base_filename); 256 const base::FilePath& side_effect_free_whitelist_base_filename);
255 257
256 // Filename for the csd malware IP blacklist database. 258 // Filename for the csd malware IP blacklist database.
257 static base::FilePath IpBlacklistDBFilename( 259 static base::FilePath IpBlacklistDBFilename(
258 const base::FilePath& ip_blacklist_base_filename); 260 const base::FilePath& ip_blacklist_base_filename);
259 261
260 // Filename for the unwanted software blacklist database. 262 // Filename for the unwanted software blacklist database.
261 static base::FilePath UnwantedSoftwareDBFilename( 263 static base::FilePath UnwantedSoftwareDBFilename(
262 const base::FilePath& db_filename); 264 const base::FilePath& db_filename);
263 265
266 // Filename for the module whitelist database.
267 static base::FilePath ModuleWhitelistDBFilename(
268 const base::FilePath& db_filename);
269
264 // Get the prefixes matching the download |urls|. 270 // Get the prefixes matching the download |urls|.
265 static void GetDownloadUrlPrefixes(const std::vector<GURL>& urls, 271 static void GetDownloadUrlPrefixes(const std::vector<GURL>& urls,
266 std::vector<SBPrefix>* prefixes); 272 std::vector<SBPrefix>* prefixes);
267 273
268 // SafeBrowsing Database failure types for histogramming purposes. Explicitly 274 // SafeBrowsing Database failure types for histogramming purposes. Explicitly
269 // label new values and do not re-use old values. Also make sure to reflect 275 // label new values and do not re-use old values. Also make sure to reflect
270 // modifications made below in the SB2DatabaseFailure histogram enum. 276 // modifications made below in the SB2DatabaseFailure histogram enum.
271 enum FailureType { 277 enum FailureType {
272 FAILURE_DATABASE_CORRUPT = 0, 278 FAILURE_DATABASE_CORRUPT = 0,
273 FAILURE_DATABASE_CORRUPT_HANDLER = 1, 279 FAILURE_DATABASE_CORRUPT_HANDLER = 1,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 // for which the store is initialized to NULL. 332 // for which the store is initialized to NULL.
327 SafeBrowsingDatabaseNew( 333 SafeBrowsingDatabaseNew(
328 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 334 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
329 SafeBrowsingStore* browse_store, 335 SafeBrowsingStore* browse_store,
330 SafeBrowsingStore* download_store, 336 SafeBrowsingStore* download_store,
331 SafeBrowsingStore* csd_whitelist_store, 337 SafeBrowsingStore* csd_whitelist_store,
332 SafeBrowsingStore* download_whitelist_store, 338 SafeBrowsingStore* download_whitelist_store,
333 SafeBrowsingStore* inclusion_whitelist_store, 339 SafeBrowsingStore* inclusion_whitelist_store,
334 SafeBrowsingStore* extension_blacklist_store, 340 SafeBrowsingStore* extension_blacklist_store,
335 SafeBrowsingStore* ip_blacklist_store, 341 SafeBrowsingStore* ip_blacklist_store,
336 SafeBrowsingStore* unwanted_software_store); 342 SafeBrowsingStore* unwanted_software_store,
343 SafeBrowsingStore* module_whitelist_store);
337 344
338 ~SafeBrowsingDatabaseNew() override; 345 ~SafeBrowsingDatabaseNew() override;
339 346
340 // Implement SafeBrowsingDatabase interface. 347 // Implement SafeBrowsingDatabase interface.
341 void Init(const base::FilePath& filename) override; 348 void Init(const base::FilePath& filename) override;
342 bool ResetDatabase() override; 349 bool ResetDatabase() override;
343 bool ContainsBrowseUrl(const GURL& url, 350 bool ContainsBrowseUrl(const GURL& url,
344 std::vector<SBPrefix>* prefix_hits, 351 std::vector<SBPrefix>* prefix_hits,
345 std::vector<SBFullHashResult>* cache_hits) override; 352 std::vector<SBFullHashResult>* cache_hits) override;
346 bool ContainsBrowseHashes(const std::vector<SBFullHash>& full_hashes, 353 bool ContainsBrowseHashes(const std::vector<SBFullHash>& full_hashes,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 class ThreadSafeStateManager { 418 class ThreadSafeStateManager {
412 public: 419 public:
413 // Identifiers for stores held by the ThreadSafeStateManager. Allows helper 420 // Identifiers for stores held by the ThreadSafeStateManager. Allows helper
414 // methods to start a transaction themselves and keep it as short as 421 // methods to start a transaction themselves and keep it as short as
415 // possible rather than force callers to start the transaction early to pass 422 // possible rather than force callers to start the transaction early to pass
416 // a store pointer to the said helper methods. 423 // a store pointer to the said helper methods.
417 enum class SBWhitelistId { 424 enum class SBWhitelistId {
418 CSD, 425 CSD,
419 DOWNLOAD, 426 DOWNLOAD,
420 INCLUSION, 427 INCLUSION,
428 MODULE,
421 }; 429 };
422 enum class PrefixSetId { 430 enum class PrefixSetId {
423 BROWSE, 431 BROWSE,
424 UNWANTED_SOFTWARE, 432 UNWANTED_SOFTWARE,
425 }; 433 };
426 434
427 // Obtained through BeginReadTransaction(NoLockOnMainTaskRunner)?(): a 435 // Obtained through BeginReadTransaction(NoLockOnMainTaskRunner)?(): a
428 // ReadTransaction allows read-only observations of the 436 // ReadTransaction allows read-only observations of the
429 // ThreadSafeStateManager's state. The |prefix_gethash_cache_| has a special 437 // ThreadSafeStateManager's state. The |prefix_gethash_cache_| has a special
430 // allowance to be writable from a ReadTransaction but can't benefit from 438 // allowance to be writable from a ReadTransaction but can't benefit from
(...skipping 20 matching lines...) Expand all
451 // The sequenced task runner for this object, used to verify that its state 459 // The sequenced task runner for this object, used to verify that its state
452 // is only ever accessed from the runner. 460 // is only ever accessed from the runner.
453 scoped_refptr<const base::SequencedTaskRunner> db_task_runner_; 461 scoped_refptr<const base::SequencedTaskRunner> db_task_runner_;
454 462
455 // Lock for protecting access to this class' state. 463 // Lock for protecting access to this class' state.
456 mutable base::Lock lock_; 464 mutable base::Lock lock_;
457 465
458 SBWhitelist csd_whitelist_; 466 SBWhitelist csd_whitelist_;
459 SBWhitelist download_whitelist_; 467 SBWhitelist download_whitelist_;
460 SBWhitelist inclusion_whitelist_; 468 SBWhitelist inclusion_whitelist_;
469 SBWhitelist module_whitelist_;
461 470
462 // The IP blacklist should be small. At most a couple hundred IPs. 471 // The IP blacklist should be small. At most a couple hundred IPs.
463 IPBlacklist ip_blacklist_; 472 IPBlacklist ip_blacklist_;
464 473
465 // PrefixSets to speed up lookups for particularly large lists. The 474 // PrefixSets to speed up lookups for particularly large lists. The
466 // PrefixSet themselves are never modified, instead a new one is swapped in 475 // PrefixSet themselves are never modified, instead a new one is swapped in
467 // on update. 476 // on update.
468 scoped_ptr<const PrefixSet> browse_prefix_set_; 477 scoped_ptr<const PrefixSet> browse_prefix_set_;
469 scoped_ptr<const PrefixSet> unwanted_software_prefix_set_; 478 scoped_ptr<const PrefixSet> unwanted_software_prefix_set_;
470 479
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 // whitelist chunks and full-length hashes. This list only contains 256 683 // whitelist chunks and full-length hashes. This list only contains 256
675 // bit hashes. 684 // bit hashes.
676 // - |download_whitelist_store_|: For the download whitelist chunks and 685 // - |download_whitelist_store_|: For the download whitelist chunks and
677 // full-length hashes. This list only contains 256 bit hashes. 686 // full-length hashes. This list only contains 256 bit hashes.
678 // - |inclusion_whitelist_store_|: For the inclusion whitelist. Same format 687 // - |inclusion_whitelist_store_|: For the inclusion whitelist. Same format
679 // as |download_whitelist_store_|. 688 // as |download_whitelist_store_|.
680 // - |extension_blacklist_store_|: For extension IDs. 689 // - |extension_blacklist_store_|: For extension IDs.
681 // - |ip_blacklist_store_|: For IP blacklist. 690 // - |ip_blacklist_store_|: For IP blacklist.
682 // - |unwanted_software_store_|: For unwanted software list (format 691 // - |unwanted_software_store_|: For unwanted software list (format
683 // identical to browsing lists). 692 // identical to browsing lists).
693 // - |module_whitelist_store_|: For module whitelist. This list only
694 // contains 256 bit hashes.
684 // 695 //
685 // The stores themselves will be modified throughout the existence of this 696 // The stores themselves will be modified throughout the existence of this
686 // database, but shouldn't ever be swapped out (hence the const scoped_ptr -- 697 // database, but shouldn't ever be swapped out (hence the const scoped_ptr --
687 // which could be swapped for C++11's std::optional when that's available). 698 // which could be swapped for C++11's std::optional when that's available).
688 // They are NonThreadSafe and should thus only be accessed on the database's 699 // They are NonThreadSafe and should thus only be accessed on the database's
689 // main thread as enforced by SafeBrowsingStoreFile's implementation. 700 // main thread as enforced by SafeBrowsingStoreFile's implementation.
690 const scoped_ptr<SafeBrowsingStore> browse_store_; 701 const scoped_ptr<SafeBrowsingStore> browse_store_;
691 const scoped_ptr<SafeBrowsingStore> download_store_; 702 const scoped_ptr<SafeBrowsingStore> download_store_;
692 const scoped_ptr<SafeBrowsingStore> csd_whitelist_store_; 703 const scoped_ptr<SafeBrowsingStore> csd_whitelist_store_;
693 const scoped_ptr<SafeBrowsingStore> download_whitelist_store_; 704 const scoped_ptr<SafeBrowsingStore> download_whitelist_store_;
694 const scoped_ptr<SafeBrowsingStore> inclusion_whitelist_store_; 705 const scoped_ptr<SafeBrowsingStore> inclusion_whitelist_store_;
695 const scoped_ptr<SafeBrowsingStore> extension_blacklist_store_; 706 const scoped_ptr<SafeBrowsingStore> extension_blacklist_store_;
696 const scoped_ptr<SafeBrowsingStore> ip_blacklist_store_; 707 const scoped_ptr<SafeBrowsingStore> ip_blacklist_store_;
697 const scoped_ptr<SafeBrowsingStore> unwanted_software_store_; 708 const scoped_ptr<SafeBrowsingStore> unwanted_software_store_;
709 const scoped_ptr<SafeBrowsingStore> module_whitelist_store_;
698 710
699 // Used to schedule resetting the database because of corruption. This factory 711 // Used to schedule resetting the database because of corruption. This factory
700 // and the WeakPtrs it issues should only be used on the database's main 712 // and the WeakPtrs it issues should only be used on the database's main
701 // thread. 713 // thread.
702 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_; 714 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_;
703 }; 715 };
704 716
705 } // namespace safe_browsing 717 } // namespace safe_browsing
706 718
707 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 719 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698