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

Unified Diff: chrome/browser/safe_browsing/safe_browsing_database.cc

Issue 835523002: Add support for goog-csdinclusionwhite-sha256 in SafeBrowsingDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@##python_fix
Patch Set: fix typo Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/safe_browsing_database.cc
diff --git a/chrome/browser/safe_browsing/safe_browsing_database.cc b/chrome/browser/safe_browsing/safe_browsing_database.cc
index 236a240200a1014a73dfa8f147ea761c0da8e2fc..f6b32aafaf62afe547cdce22f224893b21ccddc0 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database.cc
@@ -50,6 +50,9 @@ const base::FilePath::CharType kCsdWhitelistDBFile[] =
// Filename suffix for the download whitelist store.
const base::FilePath::CharType kDownloadWhitelistDBFile[] =
FILE_PATH_LITERAL(" Download Whitelist");
+// Filename suffix for the off-domain inclusion whitelist store.
+const base::FilePath::CharType kInclusionWhitelistDBFile[] =
+ FILE_PATH_LITERAL(" Inclusion Whitelist");
// Filename suffix for the extension blacklist store.
const base::FilePath::CharType kExtensionBlacklistDBFile[] =
FILE_PATH_LITERAL(" Extension Blacklist");
@@ -327,10 +330,11 @@ class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory {
bool enable_ip_blacklist,
bool enable_unwanted_software_list) override {
return new SafeBrowsingDatabaseNew(
- new SafeBrowsingStoreFile,
+ new SafeBrowsingStoreFile, // browse_store
enable_download_protection ? new SafeBrowsingStoreFile : NULL,
enable_client_side_whitelist ? new SafeBrowsingStoreFile : NULL,
enable_download_whitelist ? new SafeBrowsingStoreFile : NULL,
+ new SafeBrowsingStoreFile, // inclusion_whitelist_store
enable_extension_blacklist ? new SafeBrowsingStoreFile : NULL,
enable_side_effect_free_whitelist ? new SafeBrowsingStoreFile : NULL,
enable_ip_blacklist ? new SafeBrowsingStoreFile : NULL,
@@ -410,6 +414,12 @@ base::FilePath SafeBrowsingDatabase::DownloadWhitelistDBFilename(
}
// static
+base::FilePath SafeBrowsingDatabase::InclusionWhitelistDBFilename(
+ const base::FilePath& db_filename) {
+ return base::FilePath(db_filename.value() + kInclusionWhitelistDBFile);
+}
+
+// static
base::FilePath SafeBrowsingDatabase::ExtensionBlacklistDBFilename(
const base::FilePath& db_filename) {
return base::FilePath(db_filename.value() + kExtensionBlacklistDBFile);
@@ -446,6 +456,8 @@ SafeBrowsingStore* SafeBrowsingDatabaseNew::GetStore(const int list_id) {
return csd_whitelist_store_.get();
} else if (list_id == safe_browsing_util::DOWNLOADWHITELIST) {
return download_whitelist_store_.get();
+ } else if (list_id == safe_browsing_util::INCLUSIONWHITELIST) {
+ return inclusion_whitelist_store_.get();
} else if (list_id == safe_browsing_util::EXTENSIONBLACKLIST) {
return extension_blacklist_store_.get();
} else if (list_id == safe_browsing_util::SIDEEFFECTFREEWHITELIST) {
@@ -472,6 +484,8 @@ class SafeBrowsingDatabaseNew::ThreadSafeStateManager::ReadTransaction {
return &outer_->csd_whitelist_;
case SBWhitelistId::DOWNLOAD:
return &outer_->download_whitelist_;
+ case SBWhitelistId::INCLUSION:
+ return &outer_->inclusion_whitelist_;
}
NOTREACHED();
return nullptr;
@@ -585,6 +599,8 @@ class SafeBrowsingDatabaseNew::ThreadSafeStateManager::WriteTransaction {
return &outer_->csd_whitelist_;
case SBWhitelistId::DOWNLOAD:
return &outer_->download_whitelist_;
+ case SBWhitelistId::INCLUSION:
+ return &outer_->inclusion_whitelist_;
}
NOTREACHED();
return nullptr;
@@ -622,18 +638,20 @@ SafeBrowsingDatabaseNew::ThreadSafeStateManager::BeginWriteTransaction() {
}
SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew()
- : SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL) {
+ : SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile, // browse_store
+ NULL, // download_store
+ NULL, // csd_whitelist_store
+ NULL, // download_whitelist_store
+ NULL, // inclusion_whitelist_store
+ NULL, // extension_blacklist_store
+ NULL, // side_effect_free_whitelist_store
+ NULL, // ip_blacklist_store
+ NULL) { // unwanted_software_store
DCHECK(browse_store_.get());
DCHECK(!download_store_.get());
DCHECK(!csd_whitelist_store_.get());
DCHECK(!download_whitelist_store_.get());
+ DCHECK(!inclusion_whitelist_store_.get());
DCHECK(!extension_blacklist_store_.get());
DCHECK(!side_effect_free_whitelist_store_.get());
DCHECK(!ip_blacklist_store_.get());
@@ -645,6 +663,7 @@ SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew(
SafeBrowsingStore* download_store,
SafeBrowsingStore* csd_whitelist_store,
SafeBrowsingStore* download_whitelist_store,
+ SafeBrowsingStore* inclusion_whitelist_store,
SafeBrowsingStore* extension_blacklist_store,
SafeBrowsingStore* side_effect_free_whitelist_store,
SafeBrowsingStore* ip_blacklist_store,
@@ -654,6 +673,7 @@ SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew(
download_store_(download_store),
csd_whitelist_store_(csd_whitelist_store),
download_whitelist_store_(download_whitelist_store),
+ inclusion_whitelist_store_(inclusion_whitelist_store),
extension_blacklist_store_(extension_blacklist_store),
side_effect_free_whitelist_store_(side_effect_free_whitelist_store),
ip_blacklist_store_(ip_blacklist_store),
@@ -780,6 +800,24 @@ void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) {
SBWhitelistId::DOWNLOAD); // Just to be safe.
}
+ if (inclusion_whitelist_store_.get()) {
+ inclusion_whitelist_store_->Init(
+ InclusionWhitelistDBFilename(filename_base_),
+ base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase,
+ base::Unretained(this)));
+
+ std::vector<SBAddFullHash> full_hashes;
+ if (inclusion_whitelist_store_->GetAddFullHashes(&full_hashes)) {
+ LoadWhitelist(full_hashes, SBWhitelistId::INCLUSION);
+ } else {
+ state_manager_.BeginWriteTransaction()->WhitelistEverything(
+ SBWhitelistId::INCLUSION);
+ }
+ } else {
+ state_manager_.BeginWriteTransaction()->WhitelistEverything(
+ SBWhitelistId::INCLUSION); // Just to be safe.
+ }
+
if (extension_blacklist_store_.get()) {
extension_blacklist_store_->Init(
ExtensionBlacklistDBFilename(filename_base_),
@@ -929,6 +967,12 @@ bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedUrl(const GURL& url) {
return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, full_hashes);
}
+bool SafeBrowsingDatabaseNew::ContainsInclusionWhitelistedUrl(const GURL& url) {
+ std::vector<SBFullHash> full_hashes;
+ UrlToFullHashes(url, true, &full_hashes);
+ return ContainsWhitelistedHashes(SBWhitelistId::INCLUSION, full_hashes);
+}
+
bool SafeBrowsingDatabaseNew::ContainsExtensionPrefixes(
const std::vector<SBPrefix>& prefixes,
std::vector<SBPrefix>* prefix_hits) {
@@ -1210,6 +1254,13 @@ bool SafeBrowsingDatabaseNew::UpdateStarted(
return false;
}
+ if (inclusion_whitelist_store_.get() &&
+ !inclusion_whitelist_store_->BeginUpdate()) {
+ RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_BEGIN);
+ HandleCorruptDatabase();
+ return false;
+ }
+
if (extension_blacklist_store_ &&
!extension_blacklist_store_->BeginUpdate()) {
RecordFailure(FAILURE_EXTENSION_BLACKLIST_UPDATE_BEGIN);
@@ -1258,6 +1309,9 @@ bool SafeBrowsingDatabaseNew::UpdateStarted(
UpdateChunkRangesForList(download_whitelist_store_.get(),
safe_browsing_util::kDownloadWhiteList, lists);
+ UpdateChunkRangesForList(inclusion_whitelist_store_.get(),
+ safe_browsing_util::kInclusionWhitelist, lists);
+
UpdateChunkRangesForList(extension_blacklist_store_.get(),
safe_browsing_util::kExtensionBlacklist, lists);
@@ -1300,6 +1354,11 @@ void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) {
DLOG(ERROR) << "Safe-browsing download whitelist database corrupt.";
}
+ if (inclusion_whitelist_store_.get() &&
+ !inclusion_whitelist_store_->CheckValidity()) {
+ DLOG(ERROR) << "Safe-browsing inclusion whitelist database corrupt.";
+ }
+
if (extension_blacklist_store_ &&
!extension_blacklist_store_->CheckValidity()) {
DLOG(ERROR) << "Safe-browsing extension blacklist database corrupt.";
@@ -1338,6 +1397,8 @@ void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) {
csd_whitelist_store_->CancelUpdate();
if (download_whitelist_store_.get())
download_whitelist_store_->CancelUpdate();
+ if (inclusion_whitelist_store_.get())
+ inclusion_whitelist_store_->CancelUpdate();
if (extension_blacklist_store_)
extension_blacklist_store_->CancelUpdate();
if (side_effect_free_whitelist_store_)
@@ -1371,6 +1432,9 @@ void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) {
UpdateWhitelistStore(DownloadWhitelistDBFilename(filename_base_),
download_whitelist_store_.get(),
SBWhitelistId::DOWNLOAD);
+ UpdateWhitelistStore(InclusionWhitelistDBFilename(filename_base_),
+ inclusion_whitelist_store_.get(),
+ SBWhitelistId::INCLUSION);
if (extension_blacklist_store_) {
int64 size_bytes = UpdateHashPrefixStore(
@@ -1655,51 +1719,57 @@ bool SafeBrowsingDatabaseNew::Delete() {
if (!r4)
RecordFailure(FAILURE_DATABASE_STORE_DELETE);
+ const bool r5 = inclusion_whitelist_store_.get() ?
+ inclusion_whitelist_store_->Delete() : true;
+ if (!r5)
+ RecordFailure(FAILURE_DATABASE_STORE_DELETE);
mattm 2015/01/08 22:07:27 These don't seem to be sorted anyway, so why not j
gab 2015/01/09 13:51:29 I inserted the |inclusion_whitelist_store_| code r
mattm 2015/01/10 01:10:54 Since new lists keep getting added, would be nice.
gab 2015/01/10 06:34:12 Agreed, I think the most likely refactoring would
gab 2015/01/10 06:41:35 Err... Swipe typo on phone.. s/complementizing/com
+
const base::FilePath browse_filename = BrowseDBFilename(filename_base_);
const base::FilePath bloom_filter_filename =
BloomFilterForFilename(browse_filename);
- const bool r5 = base::DeleteFile(bloom_filter_filename, false);
- if (!r5)
+ const bool r6 = base::DeleteFile(bloom_filter_filename, false);
+ if (!r6)
RecordFailure(FAILURE_DATABASE_FILTER_DELETE);
const base::FilePath browse_prefix_set_filename =
PrefixSetForFilename(browse_filename);
- const bool r6 = base::DeleteFile(browse_prefix_set_filename, false);
- if (!r6)
+ const bool r7 = base::DeleteFile(browse_prefix_set_filename, false);
+ if (!r7)
RecordFailure(FAILURE_BROWSE_PREFIX_SET_DELETE);
const base::FilePath extension_blacklist_filename =
ExtensionBlacklistDBFilename(filename_base_);
- const bool r7 = base::DeleteFile(extension_blacklist_filename, false);
- if (!r7)
+ const bool r8 = base::DeleteFile(extension_blacklist_filename, false);
+ if (!r8)
RecordFailure(FAILURE_EXTENSION_BLACKLIST_DELETE);
const base::FilePath side_effect_free_whitelist_filename =
SideEffectFreeWhitelistDBFilename(filename_base_);
- const bool r8 = base::DeleteFile(side_effect_free_whitelist_filename,
+ const bool r9 = base::DeleteFile(side_effect_free_whitelist_filename,
false);
- if (!r8)
+ if (!r9)
RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_DELETE);
const base::FilePath side_effect_free_whitelist_prefix_set_filename =
PrefixSetForFilename(side_effect_free_whitelist_filename);
- const bool r9 = base::DeleteFile(
+ const bool r10 = base::DeleteFile(
side_effect_free_whitelist_prefix_set_filename,
false);
- if (!r9)
+ if (!r10)
RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_DELETE);
- const bool r10 = base::DeleteFile(IpBlacklistDBFilename(filename_base_),
+ const bool r11 = base::DeleteFile(IpBlacklistDBFilename(filename_base_),
false);
- if (!r10)
+ if (!r11)
RecordFailure(FAILURE_IP_BLACKLIST_DELETE);
- const bool r11 =
+ const bool r12 =
base::DeleteFile(UnwantedSoftwareDBFilename(filename_base_), false);
- if (!r11)
+ if (!r12)
RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE);
- return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11;
+ return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11 &&
+ r12;
}
void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename,

Powered by Google App Engine
This is Rietveld 408576698