OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 FILE_PATH_LITERAL(" Extension Blacklist"); | 63 FILE_PATH_LITERAL(" Extension Blacklist"); |
64 // Filename suffix for the side-effect free whitelist store. | 64 // Filename suffix for the side-effect free whitelist store. |
65 const base::FilePath::CharType kSideEffectFreeWhitelistDBFile[] = | 65 const base::FilePath::CharType kSideEffectFreeWhitelistDBFile[] = |
66 FILE_PATH_LITERAL(" Side-Effect Free Whitelist"); | 66 FILE_PATH_LITERAL(" Side-Effect Free Whitelist"); |
67 // Filename suffix for the csd malware IP blacklist store. | 67 // Filename suffix for the csd malware IP blacklist store. |
68 const base::FilePath::CharType kIPBlacklistDBFile[] = | 68 const base::FilePath::CharType kIPBlacklistDBFile[] = |
69 FILE_PATH_LITERAL(" IP Blacklist"); | 69 FILE_PATH_LITERAL(" IP Blacklist"); |
70 // Filename suffix for the unwanted software blacklist store. | 70 // Filename suffix for the unwanted software blacklist store. |
71 const base::FilePath::CharType kUnwantedSoftwareDBFile[] = | 71 const base::FilePath::CharType kUnwantedSoftwareDBFile[] = |
72 FILE_PATH_LITERAL(" UwS List"); | 72 FILE_PATH_LITERAL(" UwS List"); |
| 73 const base::FilePath::CharType kModuleWhitelistDBFile[] = |
| 74 FILE_PATH_LITERAL(" Module Whitelist"); |
73 | 75 |
74 // Filename suffix for browse store. | 76 // Filename suffix for browse store. |
75 // TODO(shess): "Safe Browsing Bloom Prefix Set" is full of win. | 77 // TODO(shess): "Safe Browsing Bloom Prefix Set" is full of win. |
76 // Unfortunately, to change the name implies lots of transition code | 78 // Unfortunately, to change the name implies lots of transition code |
77 // for little benefit. If/when file formats change (say to put all | 79 // for little benefit. If/when file formats change (say to put all |
78 // the data in one file), that would be a convenient point to rectify | 80 // the data in one file), that would be a convenient point to rectify |
79 // this. | 81 // this. |
80 const base::FilePath::CharType kBrowseDBFile[] = FILE_PATH_LITERAL(" Bloom"); | 82 const base::FilePath::CharType kBrowseDBFile[] = FILE_PATH_LITERAL(" Bloom"); |
81 | 83 |
82 // Maximum number of entries we allow in any of the whitelists. | 84 // Maximum number of entries we allow in any of the whitelists, excluding the |
| 85 // module whitelist. |
83 // If a whitelist on disk contains more entries then all lookups to | 86 // If a whitelist on disk contains more entries then all lookups to |
84 // the whitelist will be considered a match. | 87 // the whitelist will be considered a match. |
85 const size_t kMaxWhitelistSize = 5000; | 88 const size_t kMaxWhitelistSize = 5000; |
86 | 89 |
87 // If the hash of this exact expression is on a whitelist then all | 90 // If the hash of this exact expression is on a whitelist then all |
88 // lookups to this whitelist will be considered a match. | 91 // lookups to this whitelist will be considered a match. |
89 const char kWhitelistKillSwitchUrl[] = | 92 const char kWhitelistKillSwitchUrl[] = |
90 "sb-ssl.google.com/safebrowsing/csd/killswitch"; // Don't change this! | 93 "sb-ssl.google.com/safebrowsing/csd/killswitch"; // Don't change this! |
91 | 94 |
92 // If the hash of this exact expression is on a whitelist then the | 95 // If the hash of this exact expression is on a whitelist then the |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 // The default SafeBrowsingDatabaseFactory. | 275 // The default SafeBrowsingDatabaseFactory. |
273 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { | 276 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { |
274 public: | 277 public: |
275 SafeBrowsingDatabase* CreateSafeBrowsingDatabase( | 278 SafeBrowsingDatabase* CreateSafeBrowsingDatabase( |
276 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 279 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
277 bool enable_download_protection, | 280 bool enable_download_protection, |
278 bool enable_client_side_whitelist, | 281 bool enable_client_side_whitelist, |
279 bool enable_download_whitelist, | 282 bool enable_download_whitelist, |
280 bool enable_extension_blacklist, | 283 bool enable_extension_blacklist, |
281 bool enable_ip_blacklist, | 284 bool enable_ip_blacklist, |
282 bool enable_unwanted_software_list) override { | 285 bool enable_unwanted_software_list, |
| 286 bool enable_module_whitelist) override { |
283 return new SafeBrowsingDatabaseNew( | 287 return new SafeBrowsingDatabaseNew( |
284 db_task_runner, CreateStore(true, db_task_runner), // browse_store | 288 db_task_runner, CreateStore(true, db_task_runner), // browse_store |
285 CreateStore(enable_download_protection, db_task_runner), | 289 CreateStore(enable_download_protection, db_task_runner), |
286 CreateStore(enable_client_side_whitelist, db_task_runner), | 290 CreateStore(enable_client_side_whitelist, db_task_runner), |
287 CreateStore(enable_download_whitelist, db_task_runner), | 291 CreateStore(enable_download_whitelist, db_task_runner), |
288 CreateStore(true, db_task_runner), // inclusion_whitelist_store | 292 CreateStore(true, db_task_runner), // inclusion_whitelist_store |
289 CreateStore(enable_extension_blacklist, db_task_runner), | 293 CreateStore(enable_extension_blacklist, db_task_runner), |
290 CreateStore(enable_ip_blacklist, db_task_runner), | 294 CreateStore(enable_ip_blacklist, db_task_runner), |
291 CreateStore(enable_unwanted_software_list, db_task_runner)); | 295 CreateStore(enable_unwanted_software_list, db_task_runner), |
| 296 CreateStore(enable_module_whitelist, db_task_runner)); |
292 } | 297 } |
293 | 298 |
294 SafeBrowsingDatabaseFactoryImpl() {} | 299 SafeBrowsingDatabaseFactoryImpl() {} |
295 | 300 |
296 private: | 301 private: |
297 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); | 302 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); |
298 }; | 303 }; |
299 | 304 |
300 // static | 305 // static |
301 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL; | 306 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL; |
302 | 307 |
303 // Factory method, should be called on the Safe Browsing sequenced task runner, | 308 // Factory method, should be called on the Safe Browsing sequenced task runner, |
304 // which is also passed to the function as |current_task_runner|. | 309 // which is also passed to the function as |current_task_runner|. |
305 // TODO(shess): There's no need for a factory any longer. Convert | 310 // TODO(shess): There's no need for a factory any longer. Convert |
306 // SafeBrowsingDatabaseNew to SafeBrowsingDatabase, and have Create() | 311 // SafeBrowsingDatabaseNew to SafeBrowsingDatabase, and have Create() |
307 // callers just construct things directly. | 312 // callers just construct things directly. |
308 SafeBrowsingDatabase* SafeBrowsingDatabase::Create( | 313 SafeBrowsingDatabase* SafeBrowsingDatabase::Create( |
309 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner, | 314 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner, |
310 bool enable_download_protection, | 315 bool enable_download_protection, |
311 bool enable_client_side_whitelist, | 316 bool enable_client_side_whitelist, |
312 bool enable_download_whitelist, | 317 bool enable_download_whitelist, |
313 bool enable_extension_blacklist, | 318 bool enable_extension_blacklist, |
314 bool enable_ip_blacklist, | 319 bool enable_ip_blacklist, |
315 bool enable_unwanted_software_list) { | 320 bool enable_unwanted_software_list, |
| 321 bool enable_module_whitelist) { |
316 DCHECK(current_task_runner->RunsTasksOnCurrentThread()); | 322 DCHECK(current_task_runner->RunsTasksOnCurrentThread()); |
317 if (!factory_) | 323 if (!factory_) |
318 factory_ = new SafeBrowsingDatabaseFactoryImpl(); | 324 factory_ = new SafeBrowsingDatabaseFactoryImpl(); |
319 return factory_->CreateSafeBrowsingDatabase( | 325 return factory_->CreateSafeBrowsingDatabase( |
320 current_task_runner, enable_download_protection, | 326 current_task_runner, enable_download_protection, |
321 enable_client_side_whitelist, enable_download_whitelist, | 327 enable_client_side_whitelist, enable_download_whitelist, |
322 enable_extension_blacklist, enable_ip_blacklist, | 328 enable_extension_blacklist, enable_ip_blacklist, |
323 enable_unwanted_software_list); | 329 enable_unwanted_software_list, enable_module_whitelist); |
324 } | 330 } |
325 | 331 |
326 SafeBrowsingDatabase::~SafeBrowsingDatabase() {} | 332 SafeBrowsingDatabase::~SafeBrowsingDatabase() {} |
327 | 333 |
328 // static | 334 // static |
329 base::FilePath SafeBrowsingDatabase::BrowseDBFilename( | 335 base::FilePath SafeBrowsingDatabase::BrowseDBFilename( |
330 const base::FilePath& db_base_filename) { | 336 const base::FilePath& db_base_filename) { |
331 return base::FilePath(db_base_filename.value() + kBrowseDBFile); | 337 return base::FilePath(db_base_filename.value() + kBrowseDBFile); |
332 } | 338 } |
333 | 339 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return base::FilePath(db_filename.value() + kIPBlacklistDBFile); | 391 return base::FilePath(db_filename.value() + kIPBlacklistDBFile); |
386 } | 392 } |
387 | 393 |
388 // static | 394 // static |
389 base::FilePath SafeBrowsingDatabase::UnwantedSoftwareDBFilename( | 395 base::FilePath SafeBrowsingDatabase::UnwantedSoftwareDBFilename( |
390 const base::FilePath& db_filename) { | 396 const base::FilePath& db_filename) { |
391 return base::FilePath(db_filename.value() + kUnwantedSoftwareDBFile); | 397 return base::FilePath(db_filename.value() + kUnwantedSoftwareDBFile); |
392 } | 398 } |
393 | 399 |
394 // static | 400 // static |
| 401 base::FilePath SafeBrowsingDatabase::ModuleWhitelistDBFilename( |
| 402 const base::FilePath& db_filename) { |
| 403 return base::FilePath(db_filename.value() + kModuleWhitelistDBFile); |
| 404 } |
| 405 |
| 406 // static |
395 void SafeBrowsingDatabase::GetDownloadUrlPrefixes( | 407 void SafeBrowsingDatabase::GetDownloadUrlPrefixes( |
396 const std::vector<GURL>& urls, | 408 const std::vector<GURL>& urls, |
397 std::vector<SBPrefix>* prefixes) { | 409 std::vector<SBPrefix>* prefixes) { |
398 std::vector<SBFullHash> full_hashes; | 410 std::vector<SBFullHash> full_hashes; |
399 for (size_t i = 0; i < urls.size(); ++i) | 411 for (size_t i = 0; i < urls.size(); ++i) |
400 UrlToFullHashes(urls[i], false, &full_hashes); | 412 UrlToFullHashes(urls[i], false, &full_hashes); |
401 | 413 |
402 for (size_t i = 0; i < full_hashes.size(); ++i) | 414 for (size_t i = 0; i < full_hashes.size(); ++i) |
403 prefixes->push_back(full_hashes[i].prefix); | 415 prefixes->push_back(full_hashes[i].prefix); |
404 } | 416 } |
(...skipping 11 matching lines...) Expand all Loading... |
416 } else if (list_id == DOWNLOADWHITELIST) { | 428 } else if (list_id == DOWNLOADWHITELIST) { |
417 return download_whitelist_store_.get(); | 429 return download_whitelist_store_.get(); |
418 } else if (list_id == INCLUSIONWHITELIST) { | 430 } else if (list_id == INCLUSIONWHITELIST) { |
419 return inclusion_whitelist_store_.get(); | 431 return inclusion_whitelist_store_.get(); |
420 } else if (list_id == EXTENSIONBLACKLIST) { | 432 } else if (list_id == EXTENSIONBLACKLIST) { |
421 return extension_blacklist_store_.get(); | 433 return extension_blacklist_store_.get(); |
422 } else if (list_id == IPBLACKLIST) { | 434 } else if (list_id == IPBLACKLIST) { |
423 return ip_blacklist_store_.get(); | 435 return ip_blacklist_store_.get(); |
424 } else if (list_id == UNWANTEDURL) { | 436 } else if (list_id == UNWANTEDURL) { |
425 return unwanted_software_store_.get(); | 437 return unwanted_software_store_.get(); |
| 438 } else if (list_id == MODULEWHITELIST) { |
| 439 return module_whitelist_store_.get(); |
426 } | 440 } |
427 return NULL; | 441 return NULL; |
428 } | 442 } |
429 | 443 |
430 // static | 444 // static |
431 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { | 445 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { |
432 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, | 446 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, |
433 FAILURE_DATABASE_MAX); | 447 FAILURE_DATABASE_MAX); |
434 } | 448 } |
435 | 449 |
436 class SafeBrowsingDatabaseNew::ThreadSafeStateManager::ReadTransaction { | 450 class SafeBrowsingDatabaseNew::ThreadSafeStateManager::ReadTransaction { |
437 public: | 451 public: |
438 const SBWhitelist* GetSBWhitelist(SBWhitelistId id) { | 452 const SBWhitelist* GetSBWhitelist(SBWhitelistId id) { |
439 switch (id) { | 453 switch (id) { |
440 case SBWhitelistId::CSD: | 454 case SBWhitelistId::CSD: |
441 return &outer_->csd_whitelist_; | 455 return &outer_->csd_whitelist_; |
442 case SBWhitelistId::DOWNLOAD: | 456 case SBWhitelistId::DOWNLOAD: |
443 return &outer_->download_whitelist_; | 457 return &outer_->download_whitelist_; |
444 case SBWhitelistId::INCLUSION: | 458 case SBWhitelistId::INCLUSION: |
445 return &outer_->inclusion_whitelist_; | 459 return &outer_->inclusion_whitelist_; |
| 460 case SBWhitelistId::MODULE: |
| 461 return &outer_->module_whitelist_; |
446 } | 462 } |
447 NOTREACHED(); | 463 NOTREACHED(); |
448 return nullptr; | 464 return nullptr; |
449 } | 465 } |
450 | 466 |
451 const IPBlacklist* ip_blacklist() { return &outer_->ip_blacklist_; } | 467 const IPBlacklist* ip_blacklist() { return &outer_->ip_blacklist_; } |
452 | 468 |
453 const PrefixSet* GetPrefixSet(PrefixSetId id) { | 469 const PrefixSet* GetPrefixSet(PrefixSetId id) { |
454 switch (id) { | 470 switch (id) { |
455 case PrefixSetId::BROWSE: | 471 case PrefixSetId::BROWSE: |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 } | 562 } |
547 | 563 |
548 SBWhitelist* SBWhitelistForId(SBWhitelistId id) { | 564 SBWhitelist* SBWhitelistForId(SBWhitelistId id) { |
549 switch (id) { | 565 switch (id) { |
550 case SBWhitelistId::CSD: | 566 case SBWhitelistId::CSD: |
551 return &outer_->csd_whitelist_; | 567 return &outer_->csd_whitelist_; |
552 case SBWhitelistId::DOWNLOAD: | 568 case SBWhitelistId::DOWNLOAD: |
553 return &outer_->download_whitelist_; | 569 return &outer_->download_whitelist_; |
554 case SBWhitelistId::INCLUSION: | 570 case SBWhitelistId::INCLUSION: |
555 return &outer_->inclusion_whitelist_; | 571 return &outer_->inclusion_whitelist_; |
| 572 case SBWhitelistId::MODULE: |
| 573 return &outer_->module_whitelist_; |
556 } | 574 } |
557 NOTREACHED(); | 575 NOTREACHED(); |
558 return nullptr; | 576 return nullptr; |
559 } | 577 } |
560 | 578 |
561 ThreadSafeStateManager* outer_; | 579 ThreadSafeStateManager* outer_; |
562 base::AutoLock transaction_lock_; | 580 base::AutoLock transaction_lock_; |
563 | 581 |
564 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); | 582 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); |
565 }; | 583 }; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 616 |
599 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( | 617 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( |
600 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 618 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
601 SafeBrowsingStore* browse_store, | 619 SafeBrowsingStore* browse_store, |
602 SafeBrowsingStore* download_store, | 620 SafeBrowsingStore* download_store, |
603 SafeBrowsingStore* csd_whitelist_store, | 621 SafeBrowsingStore* csd_whitelist_store, |
604 SafeBrowsingStore* download_whitelist_store, | 622 SafeBrowsingStore* download_whitelist_store, |
605 SafeBrowsingStore* inclusion_whitelist_store, | 623 SafeBrowsingStore* inclusion_whitelist_store, |
606 SafeBrowsingStore* extension_blacklist_store, | 624 SafeBrowsingStore* extension_blacklist_store, |
607 SafeBrowsingStore* ip_blacklist_store, | 625 SafeBrowsingStore* ip_blacklist_store, |
608 SafeBrowsingStore* unwanted_software_store) | 626 SafeBrowsingStore* unwanted_software_store, |
| 627 SafeBrowsingStore* module_whitelist_store) |
609 : db_task_runner_(db_task_runner), | 628 : db_task_runner_(db_task_runner), |
610 state_manager_(db_task_runner_), | 629 state_manager_(db_task_runner_), |
611 db_state_manager_(db_task_runner_), | 630 db_state_manager_(db_task_runner_), |
612 browse_store_(browse_store), | 631 browse_store_(browse_store), |
613 download_store_(download_store), | 632 download_store_(download_store), |
614 csd_whitelist_store_(csd_whitelist_store), | 633 csd_whitelist_store_(csd_whitelist_store), |
615 download_whitelist_store_(download_whitelist_store), | 634 download_whitelist_store_(download_whitelist_store), |
616 inclusion_whitelist_store_(inclusion_whitelist_store), | 635 inclusion_whitelist_store_(inclusion_whitelist_store), |
617 extension_blacklist_store_(extension_blacklist_store), | 636 extension_blacklist_store_(extension_blacklist_store), |
618 ip_blacklist_store_(ip_blacklist_store), | 637 ip_blacklist_store_(ip_blacklist_store), |
619 unwanted_software_store_(unwanted_software_store), | 638 unwanted_software_store_(unwanted_software_store), |
| 639 module_whitelist_store_(module_whitelist_store), |
620 reset_factory_(this) { | 640 reset_factory_(this) { |
621 DCHECK(browse_store_.get()); | 641 DCHECK(browse_store_.get()); |
622 } | 642 } |
623 | 643 |
624 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { | 644 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { |
625 // The DCHECK is disabled due to crbug.com/338486 . | 645 // The DCHECK is disabled due to crbug.com/338486 . |
626 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 646 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
627 } | 647 } |
628 | 648 |
629 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) { | 649 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, | 776 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
757 base::Unretained(this))); | 777 base::Unretained(this))); |
758 | 778 |
759 std::vector<SBAddFullHash> full_hashes; | 779 std::vector<SBAddFullHash> full_hashes; |
760 if (ip_blacklist_store_->GetAddFullHashes(&full_hashes)) { | 780 if (ip_blacklist_store_->GetAddFullHashes(&full_hashes)) { |
761 LoadIpBlacklist(full_hashes); | 781 LoadIpBlacklist(full_hashes); |
762 } else { | 782 } else { |
763 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list. | 783 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list. |
764 } | 784 } |
765 } | 785 } |
| 786 |
| 787 if (module_whitelist_store_.get()) { |
| 788 module_whitelist_store_->Init( |
| 789 ModuleWhitelistDBFilename(db_state_manager_.filename_base()), |
| 790 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
| 791 base::Unretained(this))); |
| 792 |
| 793 std::vector<SBAddFullHash> full_hashes; |
| 794 if (module_whitelist_store_->GetAddFullHashes(&full_hashes)) { |
| 795 LoadWhitelist(full_hashes, SBWhitelistId::MODULE); |
| 796 } else { |
| 797 state_manager_.BeginWriteTransaction()->WhitelistEverything( |
| 798 SBWhitelistId::MODULE); |
| 799 } |
| 800 } else { |
| 801 state_manager_.BeginWriteTransaction()->WhitelistEverything( |
| 802 SBWhitelistId::MODULE); // Just to be safe. |
| 803 } |
766 } | 804 } |
767 | 805 |
768 bool SafeBrowsingDatabaseNew::ResetDatabase() { | 806 bool SafeBrowsingDatabaseNew::ResetDatabase() { |
769 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 807 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
770 | 808 |
771 // Delete files on disk. | 809 // Delete files on disk. |
772 // TODO(shess): Hard to see where one might want to delete without a | 810 // TODO(shess): Hard to see where one might want to delete without a |
773 // reset. Perhaps inline |Delete()|? | 811 // reset. Perhaps inline |Delete()|? |
774 if (!Delete()) | 812 if (!Delete()) |
775 return false; | 813 return false; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 return false; | 983 return false; |
946 } | 984 } |
947 | 985 |
948 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedString( | 986 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedString( |
949 const std::string& str) { | 987 const std::string& str) { |
950 std::vector<SBFullHash> hashes; | 988 std::vector<SBFullHash> hashes; |
951 hashes.push_back(SBFullHashForString(str)); | 989 hashes.push_back(SBFullHashForString(str)); |
952 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, hashes); | 990 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, hashes); |
953 } | 991 } |
954 | 992 |
| 993 bool SafeBrowsingDatabaseNew::ContainsModuleWhitelistedString( |
| 994 const std::string& str) { |
| 995 std::vector<SBFullHash> hashes; |
| 996 hashes.push_back(SBFullHashForString(str)); |
| 997 return ContainsWhitelistedHashes(SBWhitelistId::MODULE, hashes); |
| 998 } |
| 999 |
955 bool SafeBrowsingDatabaseNew::ContainsWhitelistedHashes( | 1000 bool SafeBrowsingDatabaseNew::ContainsWhitelistedHashes( |
956 SBWhitelistId whitelist_id, | 1001 SBWhitelistId whitelist_id, |
957 const std::vector<SBFullHash>& hashes) { | 1002 const std::vector<SBFullHash>& hashes) { |
958 scoped_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction(); | 1003 scoped_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction(); |
959 const SBWhitelist* whitelist = txn->GetSBWhitelist(whitelist_id); | 1004 const SBWhitelist* whitelist = txn->GetSBWhitelist(whitelist_id); |
960 if (whitelist->second) | 1005 if (whitelist->second) |
961 return true; | 1006 return true; |
962 for (std::vector<SBFullHash>::const_iterator it = hashes.begin(); | 1007 for (std::vector<SBFullHash>::const_iterator it = hashes.begin(); |
963 it != hashes.end(); ++it) { | 1008 it != hashes.end(); ++it) { |
964 if (std::binary_search(whitelist->first.begin(), whitelist->first.end(), | 1009 if (std::binary_search(whitelist->first.begin(), whitelist->first.end(), |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 HandleCorruptDatabase(); | 1213 HandleCorruptDatabase(); |
1169 return false; | 1214 return false; |
1170 } | 1215 } |
1171 | 1216 |
1172 if (unwanted_software_store_ && !unwanted_software_store_->BeginUpdate()) { | 1217 if (unwanted_software_store_ && !unwanted_software_store_->BeginUpdate()) { |
1173 RecordFailure(FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN); | 1218 RecordFailure(FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN); |
1174 HandleCorruptDatabase(); | 1219 HandleCorruptDatabase(); |
1175 return false; | 1220 return false; |
1176 } | 1221 } |
1177 | 1222 |
| 1223 if (module_whitelist_store_.get() && |
| 1224 !module_whitelist_store_->BeginUpdate()) { |
| 1225 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN); |
| 1226 HandleCorruptDatabase(); |
| 1227 return false; |
| 1228 } |
| 1229 |
1178 // Cached fullhash results must be cleared on every database update (whether | 1230 // Cached fullhash results must be cleared on every database update (whether |
1179 // successful or not). | 1231 // successful or not). |
1180 state_manager_.BeginWriteTransaction()->clear_prefix_gethash_cache(); | 1232 state_manager_.BeginWriteTransaction()->clear_prefix_gethash_cache(); |
1181 | 1233 |
1182 UpdateChunkRangesForLists(browse_store_.get(), kMalwareList, kPhishingList, | 1234 UpdateChunkRangesForLists(browse_store_.get(), kMalwareList, kPhishingList, |
1183 lists); | 1235 lists); |
1184 | 1236 |
1185 // NOTE(shess): |download_store_| used to contain kBinHashList, which has been | 1237 // NOTE(shess): |download_store_| used to contain kBinHashList, which has been |
1186 // deprecated. Code to delete the list from the store shows ~15k hits/day as | 1238 // deprecated. Code to delete the list from the store shows ~15k hits/day as |
1187 // of Feb 2014, so it has been removed. Everything _should_ be resilient to | 1239 // of Feb 2014, so it has been removed. Everything _should_ be resilient to |
1188 // extra data of that sort. | 1240 // extra data of that sort. |
1189 UpdateChunkRangesForList(download_store_.get(), kBinUrlList, lists); | 1241 UpdateChunkRangesForList(download_store_.get(), kBinUrlList, lists); |
1190 | 1242 |
1191 UpdateChunkRangesForList(csd_whitelist_store_.get(), kCsdWhiteList, lists); | 1243 UpdateChunkRangesForList(csd_whitelist_store_.get(), kCsdWhiteList, lists); |
1192 | 1244 |
1193 UpdateChunkRangesForList(download_whitelist_store_.get(), kDownloadWhiteList, | 1245 UpdateChunkRangesForList(download_whitelist_store_.get(), kDownloadWhiteList, |
1194 lists); | 1246 lists); |
1195 | 1247 |
1196 UpdateChunkRangesForList(inclusion_whitelist_store_.get(), | 1248 UpdateChunkRangesForList(inclusion_whitelist_store_.get(), |
1197 kInclusionWhitelist, lists); | 1249 kInclusionWhitelist, lists); |
1198 | 1250 |
1199 UpdateChunkRangesForList(extension_blacklist_store_.get(), | 1251 UpdateChunkRangesForList(extension_blacklist_store_.get(), |
1200 kExtensionBlacklist, lists); | 1252 kExtensionBlacklist, lists); |
1201 | 1253 |
1202 UpdateChunkRangesForList(ip_blacklist_store_.get(), kIPBlacklist, lists); | 1254 UpdateChunkRangesForList(ip_blacklist_store_.get(), kIPBlacklist, lists); |
1203 | 1255 |
1204 UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList, | 1256 UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList, |
1205 lists); | 1257 lists); |
1206 | 1258 |
| 1259 UpdateChunkRangesForList(module_whitelist_store_.get(), kModuleWhitelist, |
| 1260 lists); |
| 1261 |
1207 db_state_manager_.reset_corruption_detected(); | 1262 db_state_manager_.reset_corruption_detected(); |
1208 db_state_manager_.reset_change_detected(); | 1263 db_state_manager_.reset_change_detected(); |
1209 return true; | 1264 return true; |
1210 } | 1265 } |
1211 | 1266 |
1212 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { | 1267 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { |
1213 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 1268 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
1214 | 1269 |
1215 // The update may have failed due to corrupt storage (for instance, | 1270 // The update may have failed due to corrupt storage (for instance, |
1216 // an excessive number of invalid add_chunks and sub_chunks). | 1271 // an excessive number of invalid add_chunks and sub_chunks). |
(...skipping 27 matching lines...) Expand all Loading... |
1244 } | 1299 } |
1245 | 1300 |
1246 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) { | 1301 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) { |
1247 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt."; | 1302 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt."; |
1248 } | 1303 } |
1249 | 1304 |
1250 if (unwanted_software_store_ && | 1305 if (unwanted_software_store_ && |
1251 !unwanted_software_store_->CheckValidity()) { | 1306 !unwanted_software_store_->CheckValidity()) { |
1252 DLOG(ERROR) << "Unwanted software url list database corrupt."; | 1307 DLOG(ERROR) << "Unwanted software url list database corrupt."; |
1253 } | 1308 } |
| 1309 |
| 1310 if (module_whitelist_store_ && !module_whitelist_store_->CheckValidity()) { |
| 1311 DLOG(ERROR) << "Module digest whitelist database corrupt."; |
| 1312 } |
1254 } | 1313 } |
1255 | 1314 |
1256 if (db_state_manager_.corruption_detected()) | 1315 if (db_state_manager_.corruption_detected()) |
1257 return; | 1316 return; |
1258 | 1317 |
1259 // Unroll the transaction if there was a protocol error or if the | 1318 // Unroll the transaction if there was a protocol error or if the |
1260 // transaction was empty. This will leave the prefix set, the | 1319 // transaction was empty. This will leave the prefix set, the |
1261 // pending hashes, and the prefix miss cache in place. | 1320 // pending hashes, and the prefix miss cache in place. |
1262 if (!update_succeeded || !db_state_manager_.change_detected()) { | 1321 if (!update_succeeded || !db_state_manager_.change_detected()) { |
1263 // Track empty updates to answer questions at http://crbug.com/72216 . | 1322 // Track empty updates to answer questions at http://crbug.com/72216 . |
1264 if (update_succeeded && !db_state_manager_.change_detected()) | 1323 if (update_succeeded && !db_state_manager_.change_detected()) |
1265 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); | 1324 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); |
1266 browse_store_->CancelUpdate(); | 1325 browse_store_->CancelUpdate(); |
1267 if (download_store_.get()) | 1326 if (download_store_.get()) |
1268 download_store_->CancelUpdate(); | 1327 download_store_->CancelUpdate(); |
1269 if (csd_whitelist_store_.get()) | 1328 if (csd_whitelist_store_.get()) |
1270 csd_whitelist_store_->CancelUpdate(); | 1329 csd_whitelist_store_->CancelUpdate(); |
1271 if (download_whitelist_store_.get()) | 1330 if (download_whitelist_store_.get()) |
1272 download_whitelist_store_->CancelUpdate(); | 1331 download_whitelist_store_->CancelUpdate(); |
1273 if (inclusion_whitelist_store_.get()) | 1332 if (inclusion_whitelist_store_.get()) |
1274 inclusion_whitelist_store_->CancelUpdate(); | 1333 inclusion_whitelist_store_->CancelUpdate(); |
1275 if (extension_blacklist_store_) | 1334 if (extension_blacklist_store_) |
1276 extension_blacklist_store_->CancelUpdate(); | 1335 extension_blacklist_store_->CancelUpdate(); |
1277 if (ip_blacklist_store_) | 1336 if (ip_blacklist_store_) |
1278 ip_blacklist_store_->CancelUpdate(); | 1337 ip_blacklist_store_->CancelUpdate(); |
1279 if (unwanted_software_store_) | 1338 if (unwanted_software_store_) |
1280 unwanted_software_store_->CancelUpdate(); | 1339 unwanted_software_store_->CancelUpdate(); |
| 1340 if (module_whitelist_store_) |
| 1341 module_whitelist_store_->CancelUpdate(); |
1281 return; | 1342 return; |
1282 } | 1343 } |
1283 | 1344 |
1284 if (download_store_) { | 1345 if (download_store_) { |
1285 UpdateHashPrefixStore(DownloadDBFilename(db_state_manager_.filename_base()), | 1346 UpdateHashPrefixStore(DownloadDBFilename(db_state_manager_.filename_base()), |
1286 download_store_.get(), | 1347 download_store_.get(), |
1287 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH); | 1348 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH); |
1288 } | 1349 } |
1289 | 1350 |
1290 UpdatePrefixSetUrlStore(BrowseDBFilename(db_state_manager_.filename_base()), | 1351 UpdatePrefixSetUrlStore(BrowseDBFilename(db_state_manager_.filename_base()), |
(...skipping 21 matching lines...) Expand all Loading... |
1312 if (ip_blacklist_store_) | 1373 if (ip_blacklist_store_) |
1313 UpdateIpBlacklistStore(); | 1374 UpdateIpBlacklistStore(); |
1314 | 1375 |
1315 if (unwanted_software_store_) { | 1376 if (unwanted_software_store_) { |
1316 UpdatePrefixSetUrlStore( | 1377 UpdatePrefixSetUrlStore( |
1317 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), | 1378 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), |
1318 unwanted_software_store_.get(), PrefixSetId::UNWANTED_SOFTWARE, | 1379 unwanted_software_store_.get(), PrefixSetId::UNWANTED_SOFTWARE, |
1319 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH, | 1380 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH, |
1320 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true); | 1381 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true); |
1321 } | 1382 } |
| 1383 |
| 1384 if (module_whitelist_store_) { |
| 1385 UpdateWhitelistStore( |
| 1386 ModuleWhitelistDBFilename(db_state_manager_.filename_base()), |
| 1387 module_whitelist_store_.get(), SBWhitelistId::MODULE); |
| 1388 } |
1322 } | 1389 } |
1323 | 1390 |
1324 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( | 1391 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( |
1325 const base::FilePath& store_filename, | 1392 const base::FilePath& store_filename, |
1326 SafeBrowsingStore* store, | 1393 SafeBrowsingStore* store, |
1327 SBWhitelistId whitelist_id) { | 1394 SBWhitelistId whitelist_id) { |
1328 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 1395 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
1329 | 1396 |
1330 if (!store) | 1397 if (!store) |
1331 return; | 1398 return; |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 #if defined(OS_MACOSX) | 1701 #if defined(OS_MACOSX) |
1635 base::mac::SetFileBackupExclusion(prefix_set_filename); | 1702 base::mac::SetFileBackupExclusion(prefix_set_filename); |
1636 #endif | 1703 #endif |
1637 } | 1704 } |
1638 | 1705 |
1639 void SafeBrowsingDatabaseNew::LoadWhitelist( | 1706 void SafeBrowsingDatabaseNew::LoadWhitelist( |
1640 const std::vector<SBAddFullHash>& full_hashes, | 1707 const std::vector<SBAddFullHash>& full_hashes, |
1641 SBWhitelistId whitelist_id) { | 1708 SBWhitelistId whitelist_id) { |
1642 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 1709 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
1643 | 1710 |
1644 if (full_hashes.size() > kMaxWhitelistSize) { | 1711 if (full_hashes.size() > kMaxWhitelistSize && |
| 1712 whitelist_id != SBWhitelistId::MODULE) { |
1645 state_manager_.BeginWriteTransaction()->WhitelistEverything(whitelist_id); | 1713 state_manager_.BeginWriteTransaction()->WhitelistEverything(whitelist_id); |
1646 return; | 1714 return; |
1647 } | 1715 } |
1648 | 1716 |
| 1717 if (full_hashes.empty() && whitelist_id == SBWhitelistId::MODULE) { |
| 1718 state_manager_.BeginWriteTransaction()->WhitelistEverything( |
| 1719 SBWhitelistId::MODULE); |
| 1720 return; |
| 1721 } |
| 1722 |
1649 std::vector<SBFullHash> new_whitelist; | 1723 std::vector<SBFullHash> new_whitelist; |
1650 new_whitelist.reserve(full_hashes.size()); | 1724 new_whitelist.reserve(full_hashes.size()); |
1651 for (std::vector<SBAddFullHash>::const_iterator it = full_hashes.begin(); | 1725 for (std::vector<SBAddFullHash>::const_iterator it = full_hashes.begin(); |
1652 it != full_hashes.end(); ++it) { | 1726 it != full_hashes.end(); ++it) { |
1653 new_whitelist.push_back(it->full_hash); | 1727 new_whitelist.push_back(it->full_hash); |
1654 } | 1728 } |
1655 std::sort(new_whitelist.begin(), new_whitelist.end(), SBFullHashLess); | 1729 std::sort(new_whitelist.begin(), new_whitelist.end(), SBFullHashLess); |
1656 | 1730 |
1657 SBFullHash kill_switch = SBFullHashForString(kWhitelistKillSwitchUrl); | 1731 SBFullHash kill_switch = SBFullHashForString(kWhitelistKillSwitchUrl); |
1658 if (std::binary_search(new_whitelist.begin(), new_whitelist.end(), | 1732 if (std::binary_search(new_whitelist.begin(), new_whitelist.end(), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 histogram_name.append(".InclusionWhitelist"); | 1835 histogram_name.append(".InclusionWhitelist"); |
1762 else if (base::EndsWith(filename, kExtensionBlacklistDBFile, | 1836 else if (base::EndsWith(filename, kExtensionBlacklistDBFile, |
1763 base::CompareCase::SENSITIVE)) | 1837 base::CompareCase::SENSITIVE)) |
1764 histogram_name.append(".ExtensionBlacklist"); | 1838 histogram_name.append(".ExtensionBlacklist"); |
1765 else if (base::EndsWith(filename, kIPBlacklistDBFile, | 1839 else if (base::EndsWith(filename, kIPBlacklistDBFile, |
1766 base::CompareCase::SENSITIVE)) | 1840 base::CompareCase::SENSITIVE)) |
1767 histogram_name.append(".IPBlacklist"); | 1841 histogram_name.append(".IPBlacklist"); |
1768 else if (base::EndsWith(filename, kUnwantedSoftwareDBFile, | 1842 else if (base::EndsWith(filename, kUnwantedSoftwareDBFile, |
1769 base::CompareCase::SENSITIVE)) | 1843 base::CompareCase::SENSITIVE)) |
1770 histogram_name.append(".UnwantedSoftware"); | 1844 histogram_name.append(".UnwantedSoftware"); |
| 1845 else if (base::EndsWith(filename, kModuleWhitelistDBFile, |
| 1846 base::CompareCase::SENSITIVE)) |
| 1847 histogram_name.append(".ModuleWhitelist"); |
1771 else | 1848 else |
1772 NOTREACHED(); // Add support for new lists above. | 1849 NOTREACHED(); // Add support for new lists above. |
1773 | 1850 |
1774 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. | 1851 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. |
1775 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( | 1852 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( |
1776 histogram_name, 1, 1000000, 50, | 1853 histogram_name, 1, 1000000, 50, |
1777 base::HistogramBase::kUmaTargetedHistogramFlag); | 1854 base::HistogramBase::kUmaTargetedHistogramFlag); |
1778 | 1855 |
1779 histogram_pointer->Add(file_size_kilobytes); | 1856 histogram_pointer->Add(file_size_kilobytes); |
1780 } | 1857 } |
1781 | 1858 |
1782 } // namespace safe_browsing | 1859 } // namespace safe_browsing |
OLD | NEW |