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 #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 Loading... |
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 Loading... |
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // are considered to be trusted. The two methods below let you lookup the | 153 // are considered to be trusted. The two methods below let you lookup the |
152 // whitelist either for a URL or an arbitrary string. These methods will | 154 // whitelist either for a URL or an arbitrary string. These methods will |
153 // return false if no match is found and true otherwise. This function is safe | 155 // return false if no match is found and true otherwise. This function is safe |
154 // to call from any thread. | 156 // to call from any thread. |
155 virtual bool ContainsDownloadWhitelistedUrl(const GURL& url) = 0; | 157 virtual bool ContainsDownloadWhitelistedUrl(const GURL& url) = 0; |
156 virtual bool ContainsDownloadWhitelistedString(const std::string& str) = 0; | 158 virtual bool ContainsDownloadWhitelistedString(const std::string& str) = 0; |
157 | 159 |
158 // Returns true if |url| is on the off-domain inclusion whitelist. | 160 // Returns true if |url| is on the off-domain inclusion whitelist. |
159 virtual bool ContainsInclusionWhitelistedUrl(const GURL& url) = 0; | 161 virtual bool ContainsInclusionWhitelistedUrl(const GURL& url) = 0; |
160 | 162 |
| 163 // Returns true if the given module is on the module whitelist. |
| 164 virtual bool ContainsModuleWhitelistedString(const std::string& str) = 0; |
| 165 |
161 // Populates |prefix_hits| with any prefixes in |prefixes| that have matches | 166 // Populates |prefix_hits| with any prefixes in |prefixes| that have matches |
162 // in the database, returning true if there were any matches. | 167 // in the database, returning true if there were any matches. |
163 // | 168 // |
164 // This function can ONLY be accessed from the creation thread. | 169 // This function can ONLY be accessed from the creation thread. |
165 virtual bool ContainsExtensionPrefixes( | 170 virtual bool ContainsExtensionPrefixes( |
166 const std::vector<SBPrefix>& prefixes, | 171 const std::vector<SBPrefix>& prefixes, |
167 std::vector<SBPrefix>* prefix_hits) = 0; | 172 std::vector<SBPrefix>* prefix_hits) = 0; |
168 | 173 |
169 // Returns true iff the given IP is currently on the csd malware IP blacklist. | 174 // Returns true iff the given IP is currently on the csd malware IP blacklist. |
170 // This function is safe to call from any thread. | 175 // This function is safe to call from any thread. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 const base::FilePath& side_effect_free_whitelist_base_filename); | 259 const base::FilePath& side_effect_free_whitelist_base_filename); |
255 | 260 |
256 // Filename for the csd malware IP blacklist database. | 261 // Filename for the csd malware IP blacklist database. |
257 static base::FilePath IpBlacklistDBFilename( | 262 static base::FilePath IpBlacklistDBFilename( |
258 const base::FilePath& ip_blacklist_base_filename); | 263 const base::FilePath& ip_blacklist_base_filename); |
259 | 264 |
260 // Filename for the unwanted software blacklist database. | 265 // Filename for the unwanted software blacklist database. |
261 static base::FilePath UnwantedSoftwareDBFilename( | 266 static base::FilePath UnwantedSoftwareDBFilename( |
262 const base::FilePath& db_filename); | 267 const base::FilePath& db_filename); |
263 | 268 |
| 269 // Filename for the module whitelist database. |
| 270 static base::FilePath ModuleWhitelistDBFilename( |
| 271 const base::FilePath& db_filename); |
| 272 |
264 // Get the prefixes matching the download |urls|. | 273 // Get the prefixes matching the download |urls|. |
265 static void GetDownloadUrlPrefixes(const std::vector<GURL>& urls, | 274 static void GetDownloadUrlPrefixes(const std::vector<GURL>& urls, |
266 std::vector<SBPrefix>* prefixes); | 275 std::vector<SBPrefix>* prefixes); |
267 | 276 |
268 // SafeBrowsing Database failure types for histogramming purposes. Explicitly | 277 // SafeBrowsing Database failure types for histogramming purposes. Explicitly |
269 // label new values and do not re-use old values. Also make sure to reflect | 278 // label new values and do not re-use old values. Also make sure to reflect |
270 // modifications made below in the SB2DatabaseFailure histogram enum. | 279 // modifications made below in the SB2DatabaseFailure histogram enum. |
271 enum FailureType { | 280 enum FailureType { |
272 FAILURE_DATABASE_CORRUPT = 0, | 281 FAILURE_DATABASE_CORRUPT = 0, |
273 FAILURE_DATABASE_CORRUPT_HANDLER = 1, | 282 FAILURE_DATABASE_CORRUPT_HANDLER = 1, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 // for which the store is initialized to NULL. | 335 // for which the store is initialized to NULL. |
327 SafeBrowsingDatabaseNew( | 336 SafeBrowsingDatabaseNew( |
328 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 337 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
329 SafeBrowsingStore* browse_store, | 338 SafeBrowsingStore* browse_store, |
330 SafeBrowsingStore* download_store, | 339 SafeBrowsingStore* download_store, |
331 SafeBrowsingStore* csd_whitelist_store, | 340 SafeBrowsingStore* csd_whitelist_store, |
332 SafeBrowsingStore* download_whitelist_store, | 341 SafeBrowsingStore* download_whitelist_store, |
333 SafeBrowsingStore* inclusion_whitelist_store, | 342 SafeBrowsingStore* inclusion_whitelist_store, |
334 SafeBrowsingStore* extension_blacklist_store, | 343 SafeBrowsingStore* extension_blacklist_store, |
335 SafeBrowsingStore* ip_blacklist_store, | 344 SafeBrowsingStore* ip_blacklist_store, |
336 SafeBrowsingStore* unwanted_software_store); | 345 SafeBrowsingStore* unwanted_software_store, |
| 346 SafeBrowsingStore* module_whitelist_store); |
337 | 347 |
338 ~SafeBrowsingDatabaseNew() override; | 348 ~SafeBrowsingDatabaseNew() override; |
339 | 349 |
340 // Implement SafeBrowsingDatabase interface. | 350 // Implement SafeBrowsingDatabase interface. |
341 void Init(const base::FilePath& filename) override; | 351 void Init(const base::FilePath& filename) override; |
342 bool ResetDatabase() override; | 352 bool ResetDatabase() override; |
343 bool ContainsBrowseUrl(const GURL& url, | 353 bool ContainsBrowseUrl(const GURL& url, |
344 std::vector<SBPrefix>* prefix_hits, | 354 std::vector<SBPrefix>* prefix_hits, |
345 std::vector<SBFullHashResult>* cache_hits) override; | 355 std::vector<SBFullHashResult>* cache_hits) override; |
346 bool ContainsBrowseHashes(const std::vector<SBFullHash>& full_hashes, | 356 bool ContainsBrowseHashes(const std::vector<SBFullHash>& full_hashes, |
347 std::vector<SBPrefix>* prefix_hits, | 357 std::vector<SBPrefix>* prefix_hits, |
348 std::vector<SBFullHashResult>* cache_hits) override; | 358 std::vector<SBFullHashResult>* cache_hits) override; |
349 bool ContainsUnwantedSoftwareUrl( | 359 bool ContainsUnwantedSoftwareUrl( |
350 const GURL& url, | 360 const GURL& url, |
351 std::vector<SBPrefix>* prefix_hits, | 361 std::vector<SBPrefix>* prefix_hits, |
352 std::vector<SBFullHashResult>* cache_hits) override; | 362 std::vector<SBFullHashResult>* cache_hits) override; |
353 bool ContainsUnwantedSoftwareHashes( | 363 bool ContainsUnwantedSoftwareHashes( |
354 const std::vector<SBFullHash>& full_hashes, | 364 const std::vector<SBFullHash>& full_hashes, |
355 std::vector<SBPrefix>* prefix_hits, | 365 std::vector<SBPrefix>* prefix_hits, |
356 std::vector<SBFullHashResult>* cache_hits) override; | 366 std::vector<SBFullHashResult>* cache_hits) override; |
357 bool ContainsDownloadUrlPrefixes(const std::vector<SBPrefix>& prefixes, | 367 bool ContainsDownloadUrlPrefixes(const std::vector<SBPrefix>& prefixes, |
358 std::vector<SBPrefix>* prefix_hits) override; | 368 std::vector<SBPrefix>* prefix_hits) override; |
359 bool ContainsCsdWhitelistedUrl(const GURL& url) override; | 369 bool ContainsCsdWhitelistedUrl(const GURL& url) override; |
360 bool ContainsDownloadWhitelistedUrl(const GURL& url) override; | 370 bool ContainsDownloadWhitelistedUrl(const GURL& url) override; |
361 bool ContainsDownloadWhitelistedString(const std::string& str) override; | 371 bool ContainsDownloadWhitelistedString(const std::string& str) override; |
362 bool ContainsInclusionWhitelistedUrl(const GURL& url) override; | 372 bool ContainsInclusionWhitelistedUrl(const GURL& url) override; |
| 373 bool ContainsModuleWhitelistedString(const std::string& str) override; |
363 bool ContainsExtensionPrefixes(const std::vector<SBPrefix>& prefixes, | 374 bool ContainsExtensionPrefixes(const std::vector<SBPrefix>& prefixes, |
364 std::vector<SBPrefix>* prefix_hits) override; | 375 std::vector<SBPrefix>* prefix_hits) override; |
365 bool ContainsMalwareIP(const std::string& ip_address) override; | 376 bool ContainsMalwareIP(const std::string& ip_address) override; |
366 bool UpdateStarted(std::vector<SBListChunkRanges>* lists) override; | 377 bool UpdateStarted(std::vector<SBListChunkRanges>* lists) override; |
367 void InsertChunks( | 378 void InsertChunks( |
368 const std::string& list_name, | 379 const std::string& list_name, |
369 const std::vector<scoped_ptr<SBChunkData>>& chunks) override; | 380 const std::vector<scoped_ptr<SBChunkData>>& chunks) override; |
370 void DeleteChunks(const std::vector<SBChunkDelete>& chunk_deletes) override; | 381 void DeleteChunks(const std::vector<SBChunkDelete>& chunk_deletes) override; |
371 void UpdateFinished(bool update_succeeded) override; | 382 void UpdateFinished(bool update_succeeded) override; |
372 void CacheHashResults(const std::vector<SBPrefix>& prefixes, | 383 void CacheHashResults(const std::vector<SBPrefix>& prefixes, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 class ThreadSafeStateManager { | 422 class ThreadSafeStateManager { |
412 public: | 423 public: |
413 // Identifiers for stores held by the ThreadSafeStateManager. Allows helper | 424 // Identifiers for stores held by the ThreadSafeStateManager. Allows helper |
414 // methods to start a transaction themselves and keep it as short as | 425 // 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 | 426 // possible rather than force callers to start the transaction early to pass |
416 // a store pointer to the said helper methods. | 427 // a store pointer to the said helper methods. |
417 enum class SBWhitelistId { | 428 enum class SBWhitelistId { |
418 CSD, | 429 CSD, |
419 DOWNLOAD, | 430 DOWNLOAD, |
420 INCLUSION, | 431 INCLUSION, |
| 432 MODULE, |
421 }; | 433 }; |
422 enum class PrefixSetId { | 434 enum class PrefixSetId { |
423 BROWSE, | 435 BROWSE, |
424 UNWANTED_SOFTWARE, | 436 UNWANTED_SOFTWARE, |
425 }; | 437 }; |
426 | 438 |
427 // Obtained through BeginReadTransaction(NoLockOnMainTaskRunner)?(): a | 439 // Obtained through BeginReadTransaction(NoLockOnMainTaskRunner)?(): a |
428 // ReadTransaction allows read-only observations of the | 440 // ReadTransaction allows read-only observations of the |
429 // ThreadSafeStateManager's state. The |prefix_gethash_cache_| has a special | 441 // ThreadSafeStateManager's state. The |prefix_gethash_cache_| has a special |
430 // allowance to be writable from a ReadTransaction but can't benefit from | 442 // allowance to be writable from a ReadTransaction but can't benefit from |
(...skipping 20 matching lines...) Expand all Loading... |
451 // The sequenced task runner for this object, used to verify that its state | 463 // The sequenced task runner for this object, used to verify that its state |
452 // is only ever accessed from the runner. | 464 // is only ever accessed from the runner. |
453 scoped_refptr<const base::SequencedTaskRunner> db_task_runner_; | 465 scoped_refptr<const base::SequencedTaskRunner> db_task_runner_; |
454 | 466 |
455 // Lock for protecting access to this class' state. | 467 // Lock for protecting access to this class' state. |
456 mutable base::Lock lock_; | 468 mutable base::Lock lock_; |
457 | 469 |
458 SBWhitelist csd_whitelist_; | 470 SBWhitelist csd_whitelist_; |
459 SBWhitelist download_whitelist_; | 471 SBWhitelist download_whitelist_; |
460 SBWhitelist inclusion_whitelist_; | 472 SBWhitelist inclusion_whitelist_; |
| 473 SBWhitelist module_whitelist_; |
461 | 474 |
462 // The IP blacklist should be small. At most a couple hundred IPs. | 475 // The IP blacklist should be small. At most a couple hundred IPs. |
463 IPBlacklist ip_blacklist_; | 476 IPBlacklist ip_blacklist_; |
464 | 477 |
465 // PrefixSets to speed up lookups for particularly large lists. The | 478 // PrefixSets to speed up lookups for particularly large lists. The |
466 // PrefixSet themselves are never modified, instead a new one is swapped in | 479 // PrefixSet themselves are never modified, instead a new one is swapped in |
467 // on update. | 480 // on update. |
468 scoped_ptr<const PrefixSet> browse_prefix_set_; | 481 scoped_ptr<const PrefixSet> browse_prefix_set_; |
469 scoped_ptr<const PrefixSet> unwanted_software_prefix_set_; | 482 scoped_ptr<const PrefixSet> unwanted_software_prefix_set_; |
470 | 483 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 // whitelist chunks and full-length hashes. This list only contains 256 | 687 // whitelist chunks and full-length hashes. This list only contains 256 |
675 // bit hashes. | 688 // bit hashes. |
676 // - |download_whitelist_store_|: For the download whitelist chunks and | 689 // - |download_whitelist_store_|: For the download whitelist chunks and |
677 // full-length hashes. This list only contains 256 bit hashes. | 690 // full-length hashes. This list only contains 256 bit hashes. |
678 // - |inclusion_whitelist_store_|: For the inclusion whitelist. Same format | 691 // - |inclusion_whitelist_store_|: For the inclusion whitelist. Same format |
679 // as |download_whitelist_store_|. | 692 // as |download_whitelist_store_|. |
680 // - |extension_blacklist_store_|: For extension IDs. | 693 // - |extension_blacklist_store_|: For extension IDs. |
681 // - |ip_blacklist_store_|: For IP blacklist. | 694 // - |ip_blacklist_store_|: For IP blacklist. |
682 // - |unwanted_software_store_|: For unwanted software list (format | 695 // - |unwanted_software_store_|: For unwanted software list (format |
683 // identical to browsing lists). | 696 // identical to browsing lists). |
| 697 // - |module_whitelist_store_|: For module whitelist. This list only |
| 698 // contains 256 bit hashes. |
684 // | 699 // |
685 // The stores themselves will be modified throughout the existence of this | 700 // 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 -- | 701 // 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). | 702 // 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 | 703 // They are NonThreadSafe and should thus only be accessed on the database's |
689 // main thread as enforced by SafeBrowsingStoreFile's implementation. | 704 // main thread as enforced by SafeBrowsingStoreFile's implementation. |
690 const scoped_ptr<SafeBrowsingStore> browse_store_; | 705 const scoped_ptr<SafeBrowsingStore> browse_store_; |
691 const scoped_ptr<SafeBrowsingStore> download_store_; | 706 const scoped_ptr<SafeBrowsingStore> download_store_; |
692 const scoped_ptr<SafeBrowsingStore> csd_whitelist_store_; | 707 const scoped_ptr<SafeBrowsingStore> csd_whitelist_store_; |
693 const scoped_ptr<SafeBrowsingStore> download_whitelist_store_; | 708 const scoped_ptr<SafeBrowsingStore> download_whitelist_store_; |
694 const scoped_ptr<SafeBrowsingStore> inclusion_whitelist_store_; | 709 const scoped_ptr<SafeBrowsingStore> inclusion_whitelist_store_; |
695 const scoped_ptr<SafeBrowsingStore> extension_blacklist_store_; | 710 const scoped_ptr<SafeBrowsingStore> extension_blacklist_store_; |
696 const scoped_ptr<SafeBrowsingStore> ip_blacklist_store_; | 711 const scoped_ptr<SafeBrowsingStore> ip_blacklist_store_; |
697 const scoped_ptr<SafeBrowsingStore> unwanted_software_store_; | 712 const scoped_ptr<SafeBrowsingStore> unwanted_software_store_; |
| 713 const scoped_ptr<SafeBrowsingStore> module_whitelist_store_; |
698 | 714 |
699 // Used to schedule resetting the database because of corruption. This factory | 715 // 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 | 716 // and the WeakPtrs it issues should only be used on the database's main |
701 // thread. | 717 // thread. |
702 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_; | 718 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_; |
703 }; | 719 }; |
704 | 720 |
705 } // namespace safe_browsing | 721 } // namespace safe_browsing |
706 | 722 |
707 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ | 723 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ |
OLD | NEW |