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