| 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 class SafeBrowsingDatabaseFactory { | 35 class SafeBrowsingDatabaseFactory { |
| 36 public: | 36 public: |
| 37 SafeBrowsingDatabaseFactory() { } | 37 SafeBrowsingDatabaseFactory() { } |
| 38 virtual ~SafeBrowsingDatabaseFactory() { } | 38 virtual ~SafeBrowsingDatabaseFactory() { } |
| 39 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase( | 39 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase( |
| 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_side_effect_free_whitelist, | 44 bool enable_side_effect_free_whitelist, |
| 45 bool enable_ip_blacklist) = 0; | 45 bool enable_ip_blacklist, |
| 46 bool enable_unwanted_software_list) = 0; |
| 47 |
| 46 private: | 48 private: |
| 47 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactory); | 49 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactory); |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 // Encapsulates on-disk databases that for safebrowsing. There are | 52 // Encapsulates on-disk databases that for safebrowsing. There are |
| 51 // four databases: browse, download, download whitelist and | 53 // four databases: browse, download, download whitelist and |
| 52 // client-side detection (csd) whitelist databases. The browse database contains | 54 // client-side detection (csd) whitelist databases. The browse database contains |
| 53 // information about phishing and malware urls. The download database contains | 55 // information about phishing and malware urls. The download database contains |
| 54 // 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 |
| 55 // these downloaded contents. The download whitelist contains whitelisted | 57 // these downloaded contents. The download whitelist contains whitelisted |
| 56 // download hosting sites as well as whitelisted binary signing certificates | 58 // download hosting sites as well as whitelisted binary signing certificates |
| 57 // etc. The csd whitelist database contains URLs that will never be considered | 59 // etc. The csd whitelist database contains URLs that will never be considered |
| 58 // as phishing by the client-side phishing detection. These on-disk databases | 60 // as phishing by the client-side phishing detection. These on-disk databases |
| 59 // are shared among all profiles, as it doesn't contain user-specific data. This | 61 // are shared among all profiles, as it doesn't contain user-specific data. This |
| 60 // object is not thread-safe, i.e. all its methods should be used on the same | 62 // object is not thread-safe, i.e. all its methods should be used on the same |
| 61 // thread that it was created on. | 63 // thread that it was created on. |
| 62 class SafeBrowsingDatabase { | 64 class SafeBrowsingDatabase { |
| 63 public: | 65 public: |
| 64 // Factory method for obtaining a SafeBrowsingDatabase implementation. | 66 // Factory method for obtaining a SafeBrowsingDatabase implementation. |
| 65 // It is not thread safe. | 67 // It is not thread safe. |
| 66 // |enable_download_protection| is used to control the download database | 68 // |enable_download_protection| is used to control the download database |
| 67 // feature. | 69 // feature. |
| 68 // |enable_client_side_whitelist| is used to control the csd whitelist | 70 // |enable_client_side_whitelist| is used to control the csd whitelist |
| 69 // database feature. | 71 // database feature. |
| 70 // |enable_download_whitelist| is used to control the download whitelist | 72 // |enable_download_whitelist| is used to control the download whitelist |
| 71 // database feature. | 73 // database feature. |
| 72 // |enable_ip_blacklist| is used to control the csd malware IP blacklist | 74 // |enable_ip_blacklist| is used to control the csd malware IP blacklist |
| 73 // database feature. | 75 // database feature. |
| 76 // |enable_unwanted_software_list| is used to control the unwanted software |
| 77 // list database feature. |
| 74 static SafeBrowsingDatabase* Create(bool enable_download_protection, | 78 static SafeBrowsingDatabase* Create(bool enable_download_protection, |
| 75 bool enable_client_side_whitelist, | 79 bool enable_client_side_whitelist, |
| 76 bool enable_download_whitelist, | 80 bool enable_download_whitelist, |
| 77 bool enable_extension_blacklist, | 81 bool enable_extension_blacklist, |
| 78 bool side_effect_free_whitelist, | 82 bool side_effect_free_whitelist, |
| 79 bool enable_ip_blacklist); | 83 bool enable_ip_blacklist, |
| 84 bool enable_unwanted_software_list); |
| 80 | 85 |
| 81 // Makes the passed |factory| the factory used to instantiate | 86 // Makes the passed |factory| the factory used to instantiate |
| 82 // a SafeBrowsingDatabase. This is used for tests. | 87 // a SafeBrowsingDatabase. This is used for tests. |
| 83 static void RegisterFactory(SafeBrowsingDatabaseFactory* factory) { | 88 static void RegisterFactory(SafeBrowsingDatabaseFactory* factory) { |
| 84 factory_ = factory; | 89 factory_ = factory; |
| 85 } | 90 } |
| 86 | 91 |
| 87 virtual ~SafeBrowsingDatabase(); | 92 virtual ~SafeBrowsingDatabase(); |
| 88 | 93 |
| 89 // Initializes the database with the given filename. | 94 // Initializes the database with the given filename. |
| 90 virtual void Init(const base::FilePath& filename) = 0; | 95 virtual void Init(const base::FilePath& filename) = 0; |
| 91 | 96 |
| 92 // Deletes the current database and creates a new one. | 97 // Deletes the current database and creates a new one. |
| 93 virtual bool ResetDatabase() = 0; | 98 virtual bool ResetDatabase() = 0; |
| 94 | 99 |
| 95 // Returns false if |url| is not in the browse database or already was cached | 100 // Returns false if |url| is not in the browse database or already was cached |
| 96 // as a miss. If it returns true, |prefix_hits| contains matching hash | 101 // as a miss. If it returns true, |prefix_hits| contains sorted unique |
| 97 // prefixes which had no cached results and |cache_hits| contains any matching | 102 // matching hash prefixes which had no cached results and |cache_hits| |
| 98 // cached gethash results. This function is safe to call from any thread. | 103 // contains any matching cached gethash results. This function is safe to |
| 104 // call from any thread. |
| 99 virtual bool ContainsBrowseUrl( | 105 virtual bool ContainsBrowseUrl( |
| 100 const GURL& url, | 106 const GURL& url, |
| 101 std::vector<SBPrefix>* prefix_hits, | 107 std::vector<SBPrefix>* prefix_hits, |
| 102 std::vector<SBFullHashResult>* cache_hits) = 0; | 108 std::vector<SBFullHashResult>* cache_hits) = 0; |
| 103 | 109 |
| 110 // Returns true iff the given url is on the unwanted software blacklist. |
| 111 // Returns false if |url| is not in the browse database or already was cached |
| 112 // as a miss. If it returns true, |prefix_hits| contains sorted unique |
| 113 // matching hash prefixes which had no cached results and |cache_hits| |
| 114 // contains any matching cached gethash results. This function is safe to |
| 115 // call from any thread. |
| 116 virtual bool ContainsUnwantedSoftwareUrl( |
| 117 const GURL& url, |
| 118 std::vector<SBPrefix>* prefix_hits, |
| 119 std::vector<SBFullHashResult>* cache_hits) = 0; |
| 120 |
| 104 // Returns false if none of |urls| are in Download database. If it returns | 121 // Returns false if none of |urls| are in Download database. If it returns |
| 105 // true, |prefix_hits| should contain the prefixes for the URLs that were in | 122 // true, |prefix_hits| should contain the prefixes for the URLs that were in |
| 106 // the database. This function could ONLY be accessed from creation thread. | 123 // the database. This function could ONLY be accessed from creation thread. |
| 107 virtual bool ContainsDownloadUrl(const std::vector<GURL>& urls, | 124 virtual bool ContainsDownloadUrl(const std::vector<GURL>& urls, |
| 108 std::vector<SBPrefix>* prefix_hits) = 0; | 125 std::vector<SBPrefix>* prefix_hits) = 0; |
| 109 | 126 |
| 110 // Returns false if |url| is not on the client-side phishing detection | 127 // Returns false if |url| is not on the client-side phishing detection |
| 111 // whitelist. Otherwise, this function returns true. Note: the whitelist | 128 // whitelist. Otherwise, this function returns true. Note: the whitelist |
| 112 // only contains full-length hashes so we don't return any prefix hit. | 129 // only contains full-length hashes so we don't return any prefix hit. |
| 113 // This function should only be called from the IO thread. | 130 // This function should only be called from the IO thread. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 const base::FilePath& extension_blacklist_base_filename); | 228 const base::FilePath& extension_blacklist_base_filename); |
| 212 | 229 |
| 213 // Filename for side-effect free whitelist database. | 230 // Filename for side-effect free whitelist database. |
| 214 static base::FilePath SideEffectFreeWhitelistDBFilename( | 231 static base::FilePath SideEffectFreeWhitelistDBFilename( |
| 215 const base::FilePath& side_effect_free_whitelist_base_filename); | 232 const base::FilePath& side_effect_free_whitelist_base_filename); |
| 216 | 233 |
| 217 // Filename for the csd malware IP blacklist database. | 234 // Filename for the csd malware IP blacklist database. |
| 218 static base::FilePath IpBlacklistDBFilename( | 235 static base::FilePath IpBlacklistDBFilename( |
| 219 const base::FilePath& ip_blacklist_base_filename); | 236 const base::FilePath& ip_blacklist_base_filename); |
| 220 | 237 |
| 238 // Filename for the unwanted software blacklist database. |
| 239 static base::FilePath UnwantedSoftwareDBFilename( |
| 240 const base::FilePath& db_filename); |
| 241 |
| 221 // Enumerate failures for histogramming purposes. DO NOT CHANGE THE | 242 // Enumerate failures for histogramming purposes. DO NOT CHANGE THE |
| 222 // ORDERING OF THESE VALUES. | 243 // ORDERING OF THESE VALUES. |
| 223 enum FailureType { | 244 enum FailureType { |
| 224 FAILURE_DATABASE_CORRUPT, | 245 FAILURE_DATABASE_CORRUPT, |
| 225 FAILURE_DATABASE_CORRUPT_HANDLER, | 246 FAILURE_DATABASE_CORRUPT_HANDLER, |
| 226 FAILURE_BROWSE_DATABASE_UPDATE_BEGIN, | 247 FAILURE_BROWSE_DATABASE_UPDATE_BEGIN, |
| 227 FAILURE_BROWSE_DATABASE_UPDATE_FINISH, | 248 FAILURE_BROWSE_DATABASE_UPDATE_FINISH, |
| 228 FAILURE_DATABASE_FILTER_MISSING_OBSOLETE, | 249 FAILURE_DATABASE_FILTER_MISSING_OBSOLETE, |
| 229 FAILURE_DATABASE_FILTER_READ_OBSOLETE, | 250 FAILURE_DATABASE_FILTER_READ_OBSOLETE, |
| 230 FAILURE_DATABASE_FILTER_WRITE_OBSOLETE, | 251 FAILURE_DATABASE_FILTER_WRITE_OBSOLETE, |
| 231 FAILURE_DATABASE_FILTER_DELETE, | 252 FAILURE_DATABASE_FILTER_DELETE, |
| 232 FAILURE_DATABASE_STORE_MISSING, | 253 FAILURE_DATABASE_STORE_MISSING, |
| 233 FAILURE_DATABASE_STORE_DELETE, | 254 FAILURE_DATABASE_STORE_DELETE, |
| 234 FAILURE_DOWNLOAD_DATABASE_UPDATE_BEGIN, | 255 FAILURE_DOWNLOAD_DATABASE_UPDATE_BEGIN, |
| 235 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH, | 256 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH, |
| 236 FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN, | 257 FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN, |
| 237 FAILURE_WHITELIST_DATABASE_UPDATE_FINISH, | 258 FAILURE_WHITELIST_DATABASE_UPDATE_FINISH, |
| 238 FAILURE_BROWSE_PREFIX_SET_MISSING, | |
| 239 FAILURE_BROWSE_PREFIX_SET_READ, | 259 FAILURE_BROWSE_PREFIX_SET_READ, |
| 240 FAILURE_BROWSE_PREFIX_SET_WRITE, | 260 FAILURE_BROWSE_PREFIX_SET_WRITE, |
| 241 FAILURE_BROWSE_PREFIX_SET_DELETE, | 261 FAILURE_BROWSE_PREFIX_SET_DELETE, |
| 242 FAILURE_EXTENSION_BLACKLIST_UPDATE_BEGIN, | 262 FAILURE_EXTENSION_BLACKLIST_UPDATE_BEGIN, |
| 243 FAILURE_EXTENSION_BLACKLIST_UPDATE_FINISH, | 263 FAILURE_EXTENSION_BLACKLIST_UPDATE_FINISH, |
| 244 FAILURE_EXTENSION_BLACKLIST_DELETE, | 264 FAILURE_EXTENSION_BLACKLIST_DELETE, |
| 245 FAILURE_SIDE_EFFECT_FREE_WHITELIST_UPDATE_BEGIN, | 265 FAILURE_SIDE_EFFECT_FREE_WHITELIST_UPDATE_BEGIN, |
| 246 FAILURE_SIDE_EFFECT_FREE_WHITELIST_UPDATE_FINISH, | 266 FAILURE_SIDE_EFFECT_FREE_WHITELIST_UPDATE_FINISH, |
| 247 FAILURE_SIDE_EFFECT_FREE_WHITELIST_DELETE, | 267 FAILURE_SIDE_EFFECT_FREE_WHITELIST_DELETE, |
| 248 FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_READ, | 268 FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_READ, |
| 249 FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_WRITE, | 269 FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_WRITE, |
| 250 FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_DELETE, | 270 FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_DELETE, |
| 251 FAILURE_IP_BLACKLIST_UPDATE_BEGIN, | 271 FAILURE_IP_BLACKLIST_UPDATE_BEGIN, |
| 252 FAILURE_IP_BLACKLIST_UPDATE_FINISH, | 272 FAILURE_IP_BLACKLIST_UPDATE_FINISH, |
| 253 FAILURE_IP_BLACKLIST_UPDATE_INVALID, | 273 FAILURE_IP_BLACKLIST_UPDATE_INVALID, |
| 254 FAILURE_IP_BLACKLIST_DELETE, | 274 FAILURE_IP_BLACKLIST_DELETE, |
| 275 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN, |
| 276 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH, |
| 277 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_READ, |
| 278 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, |
| 279 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE, |
| 255 | 280 |
| 256 // Memory space for histograms is determined by the max. ALWAYS | 281 // Memory space for histograms is determined by the max. ALWAYS |
| 257 // ADD NEW VALUES BEFORE THIS ONE. | 282 // ADD NEW VALUES BEFORE THIS ONE. |
| 258 FAILURE_DATABASE_MAX | 283 FAILURE_DATABASE_MAX |
| 259 }; | 284 }; |
| 260 | 285 |
| 261 static void RecordFailure(FailureType failure_type); | 286 static void RecordFailure(FailureType failure_type); |
| 262 | 287 |
| 263 private: | 288 private: |
| 264 // The factory used to instantiate a SafeBrowsingDatabase object. | 289 // The factory used to instantiate a SafeBrowsingDatabase object. |
| 265 // Useful for tests, so they can provide their own implementation of | 290 // Useful for tests, so they can provide their own implementation of |
| 266 // SafeBrowsingDatabase. | 291 // SafeBrowsingDatabase. |
| 267 static SafeBrowsingDatabaseFactory* factory_; | 292 static SafeBrowsingDatabaseFactory* factory_; |
| 268 }; | 293 }; |
| 269 | 294 |
| 270 class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase { | 295 class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase { |
| 271 public: | 296 public: |
| 272 // Create a database with a browse, download, download whitelist and | 297 // Create a database with a browse, download, download whitelist and |
| 273 // csd whitelist store objects. Takes ownership of all the store objects. | 298 // csd whitelist store objects. Takes ownership of all the store objects. |
| 274 // When |download_store| is NULL, the database will ignore any operations | 299 // When |download_store| is NULL, the database will ignore any operations |
| 275 // related download (url hashes and binary hashes). The same is true for | 300 // related download (url hashes and binary hashes). The same is true for |
| 276 // the |csd_whitelist_store|, |download_whitelist_store| and | 301 // the |csd_whitelist_store|, |download_whitelist_store| and |
| 277 // |ip_blacklist_store|. | 302 // |ip_blacklist_store|. |
| 278 SafeBrowsingDatabaseNew(SafeBrowsingStore* browse_store, | 303 SafeBrowsingDatabaseNew(SafeBrowsingStore* browse_store, |
| 279 SafeBrowsingStore* download_store, | 304 SafeBrowsingStore* download_store, |
| 280 SafeBrowsingStore* csd_whitelist_store, | 305 SafeBrowsingStore* csd_whitelist_store, |
| 281 SafeBrowsingStore* download_whitelist_store, | 306 SafeBrowsingStore* download_whitelist_store, |
| 282 SafeBrowsingStore* extension_blacklist_store, | 307 SafeBrowsingStore* extension_blacklist_store, |
| 283 SafeBrowsingStore* side_effect_free_whitelist_store, | 308 SafeBrowsingStore* side_effect_free_whitelist_store, |
| 284 SafeBrowsingStore* ip_blacklist_store); | 309 SafeBrowsingStore* ip_blacklist_store, |
| 310 SafeBrowsingStore* unwanted_software_store); |
| 285 | 311 |
| 286 // Create a database with a browse store. This is a legacy interface that | 312 // Create a database with a browse store. This is a legacy interface that |
| 287 // useds Sqlite. | 313 // useds Sqlite. |
| 288 SafeBrowsingDatabaseNew(); | 314 SafeBrowsingDatabaseNew(); |
| 289 | 315 |
| 290 ~SafeBrowsingDatabaseNew() override; | 316 ~SafeBrowsingDatabaseNew() override; |
| 291 | 317 |
| 292 // Implement SafeBrowsingDatabase interface. | 318 // Implement SafeBrowsingDatabase interface. |
| 293 void Init(const base::FilePath& filename) override; | 319 void Init(const base::FilePath& filename) override; |
| 294 bool ResetDatabase() override; | 320 bool ResetDatabase() override; |
| 295 bool ContainsBrowseUrl(const GURL& url, | 321 bool ContainsBrowseUrl(const GURL& url, |
| 296 std::vector<SBPrefix>* prefix_hits, | 322 std::vector<SBPrefix>* prefix_hits, |
| 297 std::vector<SBFullHashResult>* cache_hits) override; | 323 std::vector<SBFullHashResult>* cache_hits) override; |
| 324 bool ContainsUnwantedSoftwareUrl( |
| 325 const GURL& url, |
| 326 std::vector<SBPrefix>* prefix_hits, |
| 327 std::vector<SBFullHashResult>* cache_hits) override; |
| 298 bool ContainsDownloadUrl(const std::vector<GURL>& urls, | 328 bool ContainsDownloadUrl(const std::vector<GURL>& urls, |
| 299 std::vector<SBPrefix>* prefix_hits) override; | 329 std::vector<SBPrefix>* prefix_hits) override; |
| 300 bool ContainsCsdWhitelistedUrl(const GURL& url) override; | 330 bool ContainsCsdWhitelistedUrl(const GURL& url) override; |
| 301 bool ContainsDownloadWhitelistedUrl(const GURL& url) override; | 331 bool ContainsDownloadWhitelistedUrl(const GURL& url) override; |
| 302 bool ContainsDownloadWhitelistedString(const std::string& str) override; | 332 bool ContainsDownloadWhitelistedString(const std::string& str) override; |
| 303 bool ContainsExtensionPrefixes(const std::vector<SBPrefix>& prefixes, | 333 bool ContainsExtensionPrefixes(const std::vector<SBPrefix>& prefixes, |
| 304 std::vector<SBPrefix>* prefix_hits) override; | 334 std::vector<SBPrefix>* prefix_hits) override; |
| 305 bool ContainsSideEffectFreeWhitelistUrl(const GURL& url) override; | 335 bool ContainsSideEffectFreeWhitelistUrl(const GURL& url) override; |
| 306 bool ContainsMalwareIP(const std::string& ip_address) override; | 336 bool ContainsMalwareIP(const std::string& ip_address) override; |
| 307 bool UpdateStarted(std::vector<SBListChunkRanges>* lists) override; | 337 bool UpdateStarted(std::vector<SBListChunkRanges>* lists) override; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 331 // A SafeBrowsing whitelist contains a list of whitelisted full-hashes (stored | 361 // A SafeBrowsing whitelist contains a list of whitelisted full-hashes (stored |
| 332 // in a sorted vector) as well as a boolean flag indicating whether all | 362 // in a sorted vector) as well as a boolean flag indicating whether all |
| 333 // lookups in the whitelist should be considered matches for safety. | 363 // lookups in the whitelist should be considered matches for safety. |
| 334 typedef std::pair<std::vector<SBFullHash>, bool> SBWhitelist; | 364 typedef std::pair<std::vector<SBFullHash>, bool> SBWhitelist; |
| 335 | 365 |
| 336 // This map holds a csd malware IP blacklist which maps a prefix mask | 366 // This map holds a csd malware IP blacklist which maps a prefix mask |
| 337 // to a set of hashed blacklisted IP prefixes. Each IP prefix is a hashed | 367 // to a set of hashed blacklisted IP prefixes. Each IP prefix is a hashed |
| 338 // IPv6 IP prefix using SHA-1. | 368 // IPv6 IP prefix using SHA-1. |
| 339 typedef std::map<std::string, base::hash_set<std::string> > IPBlacklist; | 369 typedef std::map<std::string, base::hash_set<std::string> > IPBlacklist; |
| 340 | 370 |
| 341 // Helper for ContainsBrowseUrl, exposed for testing. | 371 bool PrefixSetContainsUrl( |
| 342 bool ContainsBrowseUrlHashes(const std::vector<SBFullHash>& full_hashes, | 372 const GURL& url, |
| 343 std::vector<SBPrefix>* prefix_hits, | 373 scoped_ptr<safe_browsing::PrefixSet>* prefix_set_getter, |
| 344 std::vector<SBFullHashResult>* cache_hits); | 374 std::vector<SBPrefix>* prefix_hits, |
| 375 std::vector<SBFullHashResult>* cache_hits); |
| 376 |
| 377 // Exposed for testing of PrefixSetContainsUrlHashes() on the |
| 378 // PrefixSet backing kMalwareList. |
| 379 bool ContainsBrowseUrlHashesForTesting( |
| 380 const std::vector<SBFullHash>& full_hashes, |
| 381 std::vector<SBPrefix>* prefix_hits, |
| 382 std::vector<SBFullHashResult>* cache_hits); |
| 383 |
| 384 bool PrefixSetContainsUrlHashes( |
| 385 const std::vector<SBFullHash>& full_hashes, |
| 386 scoped_ptr<safe_browsing::PrefixSet>* prefix_set_getter, |
| 387 std::vector<SBPrefix>* prefix_hits, |
| 388 std::vector<SBFullHashResult>* cache_hits); |
| 345 | 389 |
| 346 // Returns true if the whitelist is disabled or if any of the given hashes | 390 // Returns true if the whitelist is disabled or if any of the given hashes |
| 347 // matches the whitelist. | 391 // matches the whitelist. |
| 348 bool ContainsWhitelistedHashes(const SBWhitelist& whitelist, | 392 bool ContainsWhitelistedHashes(const SBWhitelist& whitelist, |
| 349 const std::vector<SBFullHash>& hashes); | 393 const std::vector<SBFullHash>& hashes); |
| 350 | 394 |
| 351 // Return the browse_store_, download_store_, download_whitelist_store or | 395 // Return the browse_store_, download_store_, download_whitelist_store or |
| 352 // csd_whitelist_store_ based on list_id. | 396 // csd_whitelist_store_ based on list_id. |
| 353 SafeBrowsingStore* GetStore(int list_id); | 397 SafeBrowsingStore* GetStore(int list_id); |
| 354 | 398 |
| 355 // Deletes the files on disk. | 399 // Deletes the files on disk. |
| 356 bool Delete(); | 400 bool Delete(); |
| 357 | 401 |
| 358 // Load the prefix set off disk, if available. | 402 // Load the prefix set in "|db_filename| Prefix Set" off disk, if available, |
| 359 void LoadPrefixSet(); | 403 // and stores it in |prefix_set|. |read_failure_type| provides a |
| 404 // caller-specific error code to be used on failure. |
| 405 void LoadPrefixSet(const base::FilePath& db_filename, |
| 406 scoped_ptr<safe_browsing::PrefixSet>* prefix_set, |
| 407 FailureType read_failure_type); |
| 360 | 408 |
| 361 // Writes the current prefix set to disk. | 409 // Writes the current prefix set "|db_filename| Prefix Set" on disk. |
| 362 void WritePrefixSet(); | 410 // |write_failure_type| provides a caller-specific error code to be used on |
| 411 // failure. |
| 412 void WritePrefixSet(const base::FilePath& db_filename, |
| 413 safe_browsing::PrefixSet* prefix_set, |
| 414 FailureType write_failure_type); |
| 363 | 415 |
| 364 // Loads the given full-length hashes to the given whitelist. If the number | 416 // Loads the given full-length hashes to the given whitelist. If the number |
| 365 // of hashes is too large or if the kill switch URL is on the whitelist | 417 // of hashes is too large or if the kill switch URL is on the whitelist |
| 366 // we will whitelist everything. | 418 // we will whitelist everything. |
| 367 void LoadWhitelist(const std::vector<SBAddFullHash>& full_hashes, | 419 void LoadWhitelist(const std::vector<SBAddFullHash>& full_hashes, |
| 368 SBWhitelist* whitelist); | 420 SBWhitelist* whitelist); |
| 369 | 421 |
| 370 // Call this method if an error occured with the given whitelist. This will | 422 // Call this method if an error occured with the given whitelist. This will |
| 371 // result in all lookups to the whitelist to return true. | 423 // result in all lookups to the whitelist to return true. |
| 372 void WhitelistEverything(SBWhitelist* whitelist); | 424 void WhitelistEverything(SBWhitelist* whitelist); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 389 safe_browsing_util::ListType list_id, | 441 safe_browsing_util::ListType list_id, |
| 390 const SBChunkData& chunk); | 442 const SBChunkData& chunk); |
| 391 void InsertSubChunk(SafeBrowsingStore* store, | 443 void InsertSubChunk(SafeBrowsingStore* store, |
| 392 safe_browsing_util::ListType list_id, | 444 safe_browsing_util::ListType list_id, |
| 393 const SBChunkData& chunk); | 445 const SBChunkData& chunk); |
| 394 | 446 |
| 395 // Returns the size in bytes of the store after the update. | 447 // Returns the size in bytes of the store after the update. |
| 396 int64 UpdateHashPrefixStore(const base::FilePath& store_filename, | 448 int64 UpdateHashPrefixStore(const base::FilePath& store_filename, |
| 397 SafeBrowsingStore* store, | 449 SafeBrowsingStore* store, |
| 398 FailureType failure_type); | 450 FailureType failure_type); |
| 399 void UpdateBrowseStore(); | 451 |
| 452 // Updates a PrefixStore store for URLs (|url_store|) which is backed on disk |
| 453 // by a "|db_filename| Prefix Set" file. Specific failure types are provided |
| 454 // to highlight the specific store who made the initial request on failure. |
| 455 void UpdatePrefixSetUrlStore(const base::FilePath& db_filename, |
| 456 SafeBrowsingStore* url_store, |
| 457 scoped_ptr<safe_browsing::PrefixSet>* prefix_set, |
| 458 FailureType finish_failure_type, |
| 459 FailureType write_failure_type); |
| 460 |
| 461 void UpdateUrlStore(SafeBrowsingStore* url_store, |
| 462 scoped_ptr<safe_browsing::PrefixSet>* prefix_set, |
| 463 FailureType failure_type); |
| 464 |
| 400 void UpdateSideEffectFreeWhitelistStore(); | 465 void UpdateSideEffectFreeWhitelistStore(); |
| 401 void UpdateWhitelistStore(const base::FilePath& store_filename, | 466 void UpdateWhitelistStore(const base::FilePath& store_filename, |
| 402 SafeBrowsingStore* store, | 467 SafeBrowsingStore* store, |
| 403 SBWhitelist* whitelist); | 468 SBWhitelist* whitelist); |
| 404 void UpdateIpBlacklistStore(); | 469 void UpdateIpBlacklistStore(); |
| 405 | 470 |
| 406 // Used to verify that various calls are made from the thread the | 471 // Used to verify that various calls are made from the thread the |
| 407 // object was created on. | 472 // object was created on. |
| 408 base::MessageLoop* creation_loop_; | 473 base::MessageLoop* creation_loop_; |
| 409 | 474 |
| 410 // Lock for protecting access to variables that may be used on the IO thread. | |
| 411 // This includes |prefix_set_|, |browse_gethash_cache_|, |csd_whitelist_|. | |
| 412 base::Lock lookup_lock_; | |
| 413 | |
| 414 // The base filename passed to Init(), used to generate the store and prefix | 475 // The base filename passed to Init(), used to generate the store and prefix |
| 415 // set filenames used to store data on disk. | 476 // set filenames used to store data on disk. |
| 416 base::FilePath filename_base_; | 477 base::FilePath filename_base_; |
| 417 | 478 |
| 418 // Underlying persistent store for chunk data. | 479 // Underlying persistent store for chunk data. |
| 419 // For browsing related (phishing and malware URLs) chunks and prefixes. | 480 // For browsing related (phishing and malware URLs) chunks and prefixes. |
| 420 scoped_ptr<SafeBrowsingStore> browse_store_; | 481 scoped_ptr<SafeBrowsingStore> browse_store_; |
| 421 | 482 |
| 422 // For download related (download URL and binary hash) chunks and prefixes. | 483 // For download related (download URL and binary hash) chunks and prefixes. |
| 423 scoped_ptr<SafeBrowsingStore> download_store_; | 484 scoped_ptr<SafeBrowsingStore> download_store_; |
| 424 | 485 |
| 425 // For the client-side phishing detection whitelist chunks and full-length | 486 // For the client-side phishing detection whitelist chunks and full-length |
| 426 // hashes. This list only contains 256 bit hashes. | 487 // hashes. This list only contains 256 bit hashes. |
| 427 scoped_ptr<SafeBrowsingStore> csd_whitelist_store_; | 488 scoped_ptr<SafeBrowsingStore> csd_whitelist_store_; |
| 428 | 489 |
| 429 // For the download whitelist chunks and full-length hashes. This list only | 490 // For the download whitelist chunks and full-length hashes. This list only |
| 430 // contains 256 bit hashes. | 491 // contains 256 bit hashes. |
| 431 scoped_ptr<SafeBrowsingStore> download_whitelist_store_; | 492 scoped_ptr<SafeBrowsingStore> download_whitelist_store_; |
| 432 | 493 |
| 433 // For extension IDs. | 494 // For extension IDs. |
| 434 scoped_ptr<SafeBrowsingStore> extension_blacklist_store_; | 495 scoped_ptr<SafeBrowsingStore> extension_blacklist_store_; |
| 435 | 496 |
| 436 // For side-effect free whitelist. | 497 // For side-effect free whitelist. |
| 437 scoped_ptr<SafeBrowsingStore> side_effect_free_whitelist_store_; | 498 scoped_ptr<SafeBrowsingStore> side_effect_free_whitelist_store_; |
| 438 | 499 |
| 439 // For IP blacklist. | 500 // For IP blacklist. |
| 440 scoped_ptr<SafeBrowsingStore> ip_blacklist_store_; | 501 scoped_ptr<SafeBrowsingStore> ip_blacklist_store_; |
| 441 | 502 |
| 503 // For unwanted software list. |
| 504 scoped_ptr<SafeBrowsingStore> unwanted_software_store_; |
| 505 |
| 506 // Lock for protecting access to variables that may be used on the IO thread. |
| 507 // This includes |(browse|unwanted_software)_prefix_set_|, |
| 508 // |prefix_gethash_cache_|, |csd_whitelist_|. |
| 509 base::Lock lookup_lock_; |
| 510 |
| 442 SBWhitelist csd_whitelist_; | 511 SBWhitelist csd_whitelist_; |
| 443 SBWhitelist download_whitelist_; | 512 SBWhitelist download_whitelist_; |
| 444 SBWhitelist extension_blacklist_; | 513 SBWhitelist extension_blacklist_; |
| 445 | 514 |
| 446 // The IP blacklist should be small. At most a couple hundred IPs. | 515 // The IP blacklist should be small. At most a couple hundred IPs. |
| 447 IPBlacklist ip_blacklist_; | 516 IPBlacklist ip_blacklist_; |
| 448 | 517 |
| 449 // Cache of gethash results for browse store. Entries should not be used if | 518 // Cache of gethash results for prefix stores. Entries should not be used if |
| 450 // they are older than their expire_after field. Cached misses will have | 519 // they are older than their expire_after field. Cached misses will have |
| 451 // empty full_hashes field. Cleared on each update. | 520 // empty full_hashes field. Cleared on each update. |
| 452 std::map<SBPrefix, SBCachedFullHashResult> browse_gethash_cache_; | 521 std::map<SBPrefix, SBCachedFullHashResult> prefix_gethash_cache_; |
| 453 | 522 |
| 454 // Set if corruption is detected during the course of an update. | 523 // Set if corruption is detected during the course of an update. |
| 455 // Causes the update functions to fail with no side effects, until | 524 // Causes the update functions to fail with no side effects, until |
| 456 // the next call to |UpdateStarted()|. | 525 // the next call to |UpdateStarted()|. |
| 457 bool corruption_detected_; | 526 bool corruption_detected_; |
| 458 | 527 |
| 459 // Set to true if any chunks are added or deleted during an update. | 528 // Set to true if any chunks are added or deleted during an update. |
| 460 // Used to optimize away database update. | 529 // Used to optimize away database update. |
| 461 bool change_detected_; | 530 bool change_detected_; |
| 462 | 531 |
| 463 // Used to check if a prefix was in the browse database. | 532 // Used to check if a prefix was in the browse database. |
| 464 scoped_ptr<safe_browsing::PrefixSet> browse_prefix_set_; | 533 scoped_ptr<safe_browsing::PrefixSet> browse_prefix_set_; |
| 465 | 534 |
| 466 // Used to check if a prefix was in the browse database. | 535 // Used to check if a prefix was in the side-effect free whitelist database. |
| 467 scoped_ptr<safe_browsing::PrefixSet> side_effect_free_whitelist_prefix_set_; | 536 scoped_ptr<safe_browsing::PrefixSet> side_effect_free_whitelist_prefix_set_; |
| 468 | 537 |
| 538 // Used to check if a prexfix was in the unwanted software database. |
| 539 scoped_ptr<safe_browsing::PrefixSet> unwanted_software_prefix_set_; |
| 540 |
| 469 // Used to schedule resetting the database because of corruption. | 541 // Used to schedule resetting the database because of corruption. |
| 470 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_; | 542 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_; |
| 471 }; | 543 }; |
| 472 | 544 |
| 473 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ | 545 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ |
| OLD | NEW |