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

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

Issue 835523002: Add support for goog-csdinclusionwhite-sha256 in SafeBrowsingDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@##python_fix
Patch Set: fix tests post merge Created 5 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // four databases: browse, download, download whitelist and 50 // four databases: browse, download, download whitelist and
51 // client-side detection (csd) whitelist databases. The browse database contains 51 // client-side detection (csd) whitelist databases. The browse database contains
52 // information about phishing and malware urls. The download database contains 52 // information about phishing and malware urls. The download database contains
53 // URLs for bad binaries (e.g: those containing virus) and hash of 53 // URLs for bad binaries (e.g: those containing virus) and hash of
54 // these downloaded contents. The download whitelist contains whitelisted 54 // these downloaded contents. The download whitelist contains whitelisted
55 // download hosting sites as well as whitelisted binary signing certificates 55 // download hosting sites as well as whitelisted binary signing certificates
56 // etc. The csd whitelist database contains URLs that will never be considered 56 // etc. The csd whitelist database contains URLs that will never be considered
57 // as phishing by the client-side phishing detection. These on-disk databases 57 // as phishing by the client-side phishing detection. These on-disk databases
58 // are shared among all profiles, as it doesn't contain user-specific data. This 58 // are shared among all profiles, as it doesn't contain user-specific data. This
59 // object is not thread-safe, i.e. all its methods should be used on the same 59 // object is not thread-safe, i.e. all its methods should be used on the same
60 // thread that it was created on. 60 // thread that it was created on, unless specified otherwise.
61 class SafeBrowsingDatabase { 61 class SafeBrowsingDatabase {
62 public: 62 public:
63 // Factory method for obtaining a SafeBrowsingDatabase implementation. 63 // Factory method for obtaining a SafeBrowsingDatabase implementation.
64 // It is not thread safe. 64 // It is not thread safe.
65 // |enable_download_protection| is used to control the download database 65 // The browse list and off-domain inclusion whitelist are always on;
66 // feature. 66 // availability of other lists is controlled by the flags on this method.
67 // |enable_client_side_whitelist| is used to control the csd whitelist
68 // database feature.
69 // |enable_download_whitelist| is used to control the download whitelist
70 // database feature.
71 // |enable_ip_blacklist| is used to control the csd malware IP blacklist
72 // database feature.
73 // |enable_unwanted_software_list| is used to control the unwanted software
74 // list database feature.
75 static SafeBrowsingDatabase* Create(bool enable_download_protection, 67 static SafeBrowsingDatabase* Create(bool enable_download_protection,
76 bool enable_client_side_whitelist, 68 bool enable_client_side_whitelist,
77 bool enable_download_whitelist, 69 bool enable_download_whitelist,
78 bool enable_extension_blacklist, 70 bool enable_extension_blacklist,
79 bool side_effect_free_whitelist, 71 bool side_effect_free_whitelist,
80 bool enable_ip_blacklist, 72 bool enable_ip_blacklist,
81 bool enable_unwanted_software_list); 73 bool enable_unwanted_software_list);
82 74
83 // Makes the passed |factory| the factory used to instantiate 75 // Makes the passed |factory| the factory used to instantiate
84 // a SafeBrowsingDatabase. This is used for tests. 76 // a SafeBrowsingDatabase. This is used for tests.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // The download whitelist is used for two purposes: a white-domain list of 122 // The download whitelist is used for two purposes: a white-domain list of
131 // sites that are considered to host only harmless binaries as well as a 123 // sites that are considered to host only harmless binaries as well as a
132 // whitelist of arbitrary strings such as hashed certificate authorities that 124 // whitelist of arbitrary strings such as hashed certificate authorities that
133 // are considered to be trusted. The two methods below let you lookup the 125 // are considered to be trusted. The two methods below let you lookup the
134 // whitelist either for a URL or an arbitrary string. These methods will 126 // whitelist either for a URL or an arbitrary string. These methods will
135 // return false if no match is found and true otherwise. This function is safe 127 // return false if no match is found and true otherwise. This function is safe
136 // to call from any thread. 128 // to call from any thread.
137 virtual bool ContainsDownloadWhitelistedUrl(const GURL& url) = 0; 129 virtual bool ContainsDownloadWhitelistedUrl(const GURL& url) = 0;
138 virtual bool ContainsDownloadWhitelistedString(const std::string& str) = 0; 130 virtual bool ContainsDownloadWhitelistedString(const std::string& str) = 0;
139 131
132 // Returns true if |url| is on the off-domain inclusion whitelist.
133 virtual bool ContainsInclusionWhitelistedUrl(const GURL& url) = 0;
134
140 // Populates |prefix_hits| with any prefixes in |prefixes| that have matches 135 // Populates |prefix_hits| with any prefixes in |prefixes| that have matches
141 // in the database. 136 // in the database.
142 // 137 //
143 // This function can ONLY be accessed from the creation thread. 138 // This function can ONLY be accessed from the creation thread.
144 virtual bool ContainsExtensionPrefixes( 139 virtual bool ContainsExtensionPrefixes(
145 const std::vector<SBPrefix>& prefixes, 140 const std::vector<SBPrefix>& prefixes,
146 std::vector<SBPrefix>* prefix_hits) = 0; 141 std::vector<SBPrefix>* prefix_hits) = 0;
147 142
148 // Returns false unless the hash of |url| is on the side-effect free 143 // Returns false unless the hash of |url| is on the side-effect free
149 // whitelist. This function is safe to call from any thread. 144 // whitelist. This function is safe to call from any thread.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 const base::FilePath& db_base_filename); 210 const base::FilePath& db_base_filename);
216 211
217 // Filename for client-side phishing detection whitelist databsae. 212 // Filename for client-side phishing detection whitelist databsae.
218 static base::FilePath CsdWhitelistDBFilename( 213 static base::FilePath CsdWhitelistDBFilename(
219 const base::FilePath& csd_whitelist_base_filename); 214 const base::FilePath& csd_whitelist_base_filename);
220 215
221 // Filename for download whitelist databsae. 216 // Filename for download whitelist databsae.
222 static base::FilePath DownloadWhitelistDBFilename( 217 static base::FilePath DownloadWhitelistDBFilename(
223 const base::FilePath& download_whitelist_base_filename); 218 const base::FilePath& download_whitelist_base_filename);
224 219
220 // Filename for the off-domain inclusion whitelist databsae.
221 static base::FilePath InclusionWhitelistDBFilename(
222 const base::FilePath& inclusion_whitelist_base_filename);
223
225 // Filename for extension blacklist database. 224 // Filename for extension blacklist database.
226 static base::FilePath ExtensionBlacklistDBFilename( 225 static base::FilePath ExtensionBlacklistDBFilename(
227 const base::FilePath& extension_blacklist_base_filename); 226 const base::FilePath& extension_blacklist_base_filename);
228 227
229 // Filename for side-effect free whitelist database. 228 // Filename for side-effect free whitelist database.
230 static base::FilePath SideEffectFreeWhitelistDBFilename( 229 static base::FilePath SideEffectFreeWhitelistDBFilename(
231 const base::FilePath& side_effect_free_whitelist_base_filename); 230 const base::FilePath& side_effect_free_whitelist_base_filename);
232 231
233 // Filename for the csd malware IP blacklist database. 232 // Filename for the csd malware IP blacklist database.
234 static base::FilePath IpBlacklistDBFilename( 233 static base::FilePath IpBlacklistDBFilename(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 285
287 private: 286 private:
288 // The factory used to instantiate a SafeBrowsingDatabase object. 287 // The factory used to instantiate a SafeBrowsingDatabase object.
289 // Useful for tests, so they can provide their own implementation of 288 // Useful for tests, so they can provide their own implementation of
290 // SafeBrowsingDatabase. 289 // SafeBrowsingDatabase.
291 static SafeBrowsingDatabaseFactory* factory_; 290 static SafeBrowsingDatabaseFactory* factory_;
292 }; 291 };
293 292
294 class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase { 293 class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase {
295 public: 294 public:
296 // Create a database with a browse, download, download whitelist and 295 // Create a database with the stores below. Takes ownership of all store
297 // csd whitelist store objects. Takes ownership of all the store objects. 296 // objects handed to this constructor. Ignores all future operations on lists
298 // When |download_store| is NULL, the database will ignore any operations 297 // for which the store is initialized to NULL.
299 // related download (url hashes and binary hashes). The same is true for
300 // the |csd_whitelist_store|, |download_whitelist_store| and
301 // |ip_blacklist_store|.
302 SafeBrowsingDatabaseNew(SafeBrowsingStore* browse_store, 298 SafeBrowsingDatabaseNew(SafeBrowsingStore* browse_store,
303 SafeBrowsingStore* download_store, 299 SafeBrowsingStore* download_store,
304 SafeBrowsingStore* csd_whitelist_store, 300 SafeBrowsingStore* csd_whitelist_store,
305 SafeBrowsingStore* download_whitelist_store, 301 SafeBrowsingStore* download_whitelist_store,
302 SafeBrowsingStore* inclusion_whitelist_store,
306 SafeBrowsingStore* extension_blacklist_store, 303 SafeBrowsingStore* extension_blacklist_store,
307 SafeBrowsingStore* side_effect_free_whitelist_store, 304 SafeBrowsingStore* side_effect_free_whitelist_store,
308 SafeBrowsingStore* ip_blacklist_store, 305 SafeBrowsingStore* ip_blacklist_store,
309 SafeBrowsingStore* unwanted_software_store); 306 SafeBrowsingStore* unwanted_software_store);
310 307
311 // Create a database with a browse store. This is a legacy interface that 308 // Create a database with a browse store. This is a legacy interface that
312 // useds Sqlite. 309 // useds Sqlite.
313 SafeBrowsingDatabaseNew(); 310 SafeBrowsingDatabaseNew();
314 311
315 ~SafeBrowsingDatabaseNew() override; 312 ~SafeBrowsingDatabaseNew() override;
316 313
317 // Implement SafeBrowsingDatabase interface. 314 // Implement SafeBrowsingDatabase interface.
318 void Init(const base::FilePath& filename) override; 315 void Init(const base::FilePath& filename) override;
319 bool ResetDatabase() override; 316 bool ResetDatabase() override;
320 bool ContainsBrowseUrl(const GURL& url, 317 bool ContainsBrowseUrl(const GURL& url,
321 std::vector<SBPrefix>* prefix_hits, 318 std::vector<SBPrefix>* prefix_hits,
322 std::vector<SBFullHashResult>* cache_hits) override; 319 std::vector<SBFullHashResult>* cache_hits) override;
323 bool ContainsUnwantedSoftwareUrl( 320 bool ContainsUnwantedSoftwareUrl(
324 const GURL& url, 321 const GURL& url,
325 std::vector<SBPrefix>* prefix_hits, 322 std::vector<SBPrefix>* prefix_hits,
326 std::vector<SBFullHashResult>* cache_hits) override; 323 std::vector<SBFullHashResult>* cache_hits) override;
327 bool ContainsDownloadUrl(const std::vector<GURL>& urls, 324 bool ContainsDownloadUrl(const std::vector<GURL>& urls,
328 std::vector<SBPrefix>* prefix_hits) override; 325 std::vector<SBPrefix>* prefix_hits) override;
329 bool ContainsCsdWhitelistedUrl(const GURL& url) override; 326 bool ContainsCsdWhitelistedUrl(const GURL& url) override;
330 bool ContainsDownloadWhitelistedUrl(const GURL& url) override; 327 bool ContainsDownloadWhitelistedUrl(const GURL& url) override;
331 bool ContainsDownloadWhitelistedString(const std::string& str) override; 328 bool ContainsDownloadWhitelistedString(const std::string& str) override;
329 bool ContainsInclusionWhitelistedUrl(const GURL& url) override;
332 bool ContainsExtensionPrefixes(const std::vector<SBPrefix>& prefixes, 330 bool ContainsExtensionPrefixes(const std::vector<SBPrefix>& prefixes,
333 std::vector<SBPrefix>* prefix_hits) override; 331 std::vector<SBPrefix>* prefix_hits) override;
334 bool ContainsSideEffectFreeWhitelistUrl(const GURL& url) override; 332 bool ContainsSideEffectFreeWhitelistUrl(const GURL& url) override;
335 bool ContainsMalwareIP(const std::string& ip_address) override; 333 bool ContainsMalwareIP(const std::string& ip_address) override;
336 bool UpdateStarted(std::vector<SBListChunkRanges>* lists) override; 334 bool UpdateStarted(std::vector<SBListChunkRanges>* lists) override;
337 void InsertChunks(const std::string& list_name, 335 void InsertChunks(const std::string& list_name,
338 const std::vector<SBChunkData*>& chunks) override; 336 const std::vector<SBChunkData*>& chunks) override;
339 void DeleteChunks(const std::vector<SBChunkDelete>& chunk_deletes) override; 337 void DeleteChunks(const std::vector<SBChunkDelete>& chunk_deletes) override;
340 void UpdateFinished(bool update_succeeded) override; 338 void UpdateFinished(bool update_succeeded) override;
341 void CacheHashResults(const std::vector<SBPrefix>& prefixes, 339 void CacheHashResults(const std::vector<SBPrefix>& prefixes,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // will automatically handle thread-safety. 377 // will automatically handle thread-safety.
380 class ThreadSafeStateManager { 378 class ThreadSafeStateManager {
381 public: 379 public:
382 // Identifiers for stores held by the ThreadSafeStateManager. Allows helper 380 // Identifiers for stores held by the ThreadSafeStateManager. Allows helper
383 // methods to start a transaction themselves and keep it as short as 381 // methods to start a transaction themselves and keep it as short as
384 // possible rather than force callers to start the transaction early to pass 382 // possible rather than force callers to start the transaction early to pass
385 // a store pointer to the said helper methods. 383 // a store pointer to the said helper methods.
386 enum class SBWhitelistId { 384 enum class SBWhitelistId {
387 CSD, 385 CSD,
388 DOWNLOAD, 386 DOWNLOAD,
387 INCLUSION,
389 }; 388 };
390 enum class PrefixSetId { 389 enum class PrefixSetId {
391 BROWSE, 390 BROWSE,
392 SIDE_EFFECT_FREE_WHITELIST, 391 SIDE_EFFECT_FREE_WHITELIST,
393 UNWANTED_SOFTWARE, 392 UNWANTED_SOFTWARE,
394 }; 393 };
395 394
396 // Obtained through BeginReadTransaction(NoLockOnMainThread)?(): a 395 // Obtained through BeginReadTransaction(NoLockOnMainThread)?(): a
397 // ReadTransaction allows read-only observations of the 396 // ReadTransaction allows read-only observations of the
398 // ThreadSafeStateManager's state. The |prefix_gethash_cache_| has a special 397 // ThreadSafeStateManager's state. The |prefix_gethash_cache_| has a special
(...skipping 20 matching lines...) Expand all
419 // The SafeBrowsingDatabase's ThreadChecker, used to verify that writes are 418 // The SafeBrowsingDatabase's ThreadChecker, used to verify that writes are
420 // only made on its main thread. This is important as it allows reading from 419 // only made on its main thread. This is important as it allows reading from
421 // the main thread without holding the lock. 420 // the main thread without holding the lock.
422 const base::ThreadChecker& thread_checker_; 421 const base::ThreadChecker& thread_checker_;
423 422
424 // Lock for protecting access to this class' state. 423 // Lock for protecting access to this class' state.
425 mutable base::Lock lock_; 424 mutable base::Lock lock_;
426 425
427 SBWhitelist csd_whitelist_; 426 SBWhitelist csd_whitelist_;
428 SBWhitelist download_whitelist_; 427 SBWhitelist download_whitelist_;
428 SBWhitelist inclusion_whitelist_;
429 429
430 // The IP blacklist should be small. At most a couple hundred IPs. 430 // The IP blacklist should be small. At most a couple hundred IPs.
431 IPBlacklist ip_blacklist_; 431 IPBlacklist ip_blacklist_;
432 432
433 // PrefixSets to speed up lookups for particularly large lists. The 433 // PrefixSets to speed up lookups for particularly large lists. The
434 // PrefixSet themselves are never modified, instead a new one is swapped in 434 // PrefixSet themselves are never modified, instead a new one is swapped in
435 // on update. 435 // on update.
436 scoped_ptr<const safe_browsing::PrefixSet> browse_prefix_set_; 436 scoped_ptr<const safe_browsing::PrefixSet> browse_prefix_set_;
437 scoped_ptr<const safe_browsing::PrefixSet> 437 scoped_ptr<const safe_browsing::PrefixSet>
438 side_effect_free_whitelist_prefix_set_; 438 side_effect_free_whitelist_prefix_set_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 bool PrefixSetContainsUrlHashes(const std::vector<SBFullHash>& full_hashes, 470 bool PrefixSetContainsUrlHashes(const std::vector<SBFullHash>& full_hashes,
471 PrefixSetId prefix_set_id, 471 PrefixSetId prefix_set_id,
472 std::vector<SBPrefix>* prefix_hits, 472 std::vector<SBPrefix>* prefix_hits,
473 std::vector<SBFullHashResult>* cache_hits); 473 std::vector<SBFullHashResult>* cache_hits);
474 474
475 // Returns true if the whitelist is disabled or if any of the given hashes 475 // Returns true if the whitelist is disabled or if any of the given hashes
476 // matches the whitelist. 476 // matches the whitelist.
477 bool ContainsWhitelistedHashes(SBWhitelistId whitelist_id, 477 bool ContainsWhitelistedHashes(SBWhitelistId whitelist_id,
478 const std::vector<SBFullHash>& hashes); 478 const std::vector<SBFullHash>& hashes);
479 479
480 // Return the browse_store_, download_store_, download_whitelist_store or 480 // Return the store matching |list_id|.
481 // csd_whitelist_store_ based on list_id.
482 SafeBrowsingStore* GetStore(int list_id); 481 SafeBrowsingStore* GetStore(int list_id);
483 482
484 // Deletes the files on disk. 483 // Deletes the files on disk.
485 bool Delete(); 484 bool Delete();
486 485
487 // Load the prefix set in "|db_filename| Prefix Set" off disk, if available, 486 // Load the prefix set in "|db_filename| Prefix Set" off disk, if available,
488 // and stores it in the PrefixSet identified by |prefix_set_id|. 487 // and stores it in the PrefixSet identified by |prefix_set_id|.
489 // |read_failure_type| provides a caller-specific error code to be used on 488 // |read_failure_type| provides a caller-specific error code to be used on
490 // failure. This method should only ever be called during initialization as 489 // failure. This method should only ever be called during initialization as
491 // it performs some disk IO while holding a transaction (for the sake of 490 // it performs some disk IO while holding a transaction (for the sake of
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 scoped_ptr<SafeBrowsingStore> download_store_; 580 scoped_ptr<SafeBrowsingStore> download_store_;
582 581
583 // For the client-side phishing detection whitelist chunks and full-length 582 // For the client-side phishing detection whitelist chunks and full-length
584 // hashes. This list only contains 256 bit hashes. 583 // hashes. This list only contains 256 bit hashes.
585 scoped_ptr<SafeBrowsingStore> csd_whitelist_store_; 584 scoped_ptr<SafeBrowsingStore> csd_whitelist_store_;
586 585
587 // For the download whitelist chunks and full-length hashes. This list only 586 // For the download whitelist chunks and full-length hashes. This list only
588 // contains 256 bit hashes. 587 // contains 256 bit hashes.
589 scoped_ptr<SafeBrowsingStore> download_whitelist_store_; 588 scoped_ptr<SafeBrowsingStore> download_whitelist_store_;
590 589
590 // For the off-domain inclusion whitelist chunks and full-length hashes. This
591 // list only contains 256 bit hashes.
592 scoped_ptr<SafeBrowsingStore> inclusion_whitelist_store_;
593
591 // For extension IDs. 594 // For extension IDs.
592 scoped_ptr<SafeBrowsingStore> extension_blacklist_store_; 595 scoped_ptr<SafeBrowsingStore> extension_blacklist_store_;
593 596
594 // For side-effect free whitelist. 597 // For side-effect free whitelist.
595 scoped_ptr<SafeBrowsingStore> side_effect_free_whitelist_store_; 598 scoped_ptr<SafeBrowsingStore> side_effect_free_whitelist_store_;
596 599
597 // For IP blacklist. 600 // For IP blacklist.
598 scoped_ptr<SafeBrowsingStore> ip_blacklist_store_; 601 scoped_ptr<SafeBrowsingStore> ip_blacklist_store_;
599 602
600 // For unwanted software list. 603 // For unwanted software list.
601 scoped_ptr<SafeBrowsingStore> unwanted_software_store_; 604 scoped_ptr<SafeBrowsingStore> unwanted_software_store_;
602 605
603 // Set if corruption is detected during the course of an update. 606 // Set if corruption is detected during the course of an update.
604 // Causes the update functions to fail with no side effects, until 607 // Causes the update functions to fail with no side effects, until
605 // the next call to |UpdateStarted()|. 608 // the next call to |UpdateStarted()|.
606 bool corruption_detected_; 609 bool corruption_detected_;
607 610
608 // Set to true if any chunks are added or deleted during an update. 611 // Set to true if any chunks are added or deleted during an update.
609 // Used to optimize away database update. 612 // Used to optimize away database update.
610 bool change_detected_; 613 bool change_detected_;
611 614
612 // Used to schedule resetting the database because of corruption. 615 // Used to schedule resetting the database because of corruption.
613 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_; 616 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_;
614 }; 617 };
615 618
616 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 619 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/database_manager.cc ('k') | chrome/browser/safe_browsing/safe_browsing_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698