Skip to content

Commit

Permalink
Expose the presence of the safebrowsing CSD whitelist killswitch.
Browse files Browse the repository at this point in the history
BUG=none
R=mattm@chromium.org

Review URL: https://codereview.chromium.org/279123004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270217 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
grt@chromium.org committed May 13, 2014
1 parent 5ed2f81 commit ff17bbb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions chrome/browser/safe_browsing/database_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ bool SafeBrowsingDatabaseManager::IsMalwareKillSwitchOn() {
return database_->IsMalwareIPMatchKillSwitchOn();
}

bool SafeBrowsingDatabaseManager::IsCsdWhitelistKillSwitchOn() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!enabled_ || !MakeDatabaseAvailable()) {
return true;
}
return database_->IsCsdWhitelistKillSwitchOn();
}

bool SafeBrowsingDatabaseManager::CheckBrowseUrl(const GURL& url,
Client* client) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/safe_browsing/database_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class SafeBrowsingDatabaseManager
// Check if the CSD malware IP matching kill switch is turned on.
virtual bool IsMalwareKillSwitchOn();

// Check if the CSD whitelist kill switch is turned on.
virtual bool IsCsdWhitelistKillSwitchOn();

// Called on the IO thread to cancel a pending check if the result is no
// longer needed.
void CancelCheck(Client* client);
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/safe_browsing/safe_browsing_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1633,3 +1633,7 @@ bool SafeBrowsingDatabaseNew::IsMalwareIPMatchKillSwitchOn() {
full_hashes.push_back(malware_kill_switch);
return ContainsWhitelistedHashes(csd_whitelist_, full_hashes);
}

bool SafeBrowsingDatabaseNew::IsCsdWhitelistKillSwitchOn() {
return csd_whitelist_.second;
}
7 changes: 7 additions & 0 deletions chrome/browser/safe_browsing/safe_browsing_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ class SafeBrowsingDatabase {
// in the csd whitelist.
virtual bool IsMalwareIPMatchKillSwitchOn() = 0;

// Returns true if the whitelist killswitch URL is present in the csd
// whitelist.
virtual bool IsCsdWhitelistKillSwitchOn() = 0;

// The name of the bloom-filter file for the given database file.
// NOTE(shess): OBSOLETE. Present for deleting stale files.
static base::FilePath BloomFilterForFilename(
Expand Down Expand Up @@ -328,6 +332,9 @@ class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase {
// Returns the value of malware_kill_switch_;
virtual bool IsMalwareIPMatchKillSwitchOn() OVERRIDE;

// Returns true if the CSD whitelist has everything whitelisted.
virtual bool IsCsdWhitelistKillSwitchOn() OVERRIDE;

private:
friend class SafeBrowsingDatabaseTest;
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseTest, HashCaching);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,9 @@ TEST_F(SafeBrowsingDatabaseTest, Whitelists) {
EXPECT_FALSE(database_->ContainsDownloadWhitelistedUrl(
GURL(std::string("http://www.google.com/"))));

// The CSD whitelist killswitch is not present.
EXPECT_FALSE(database_->IsCsdWhitelistKillSwitchOn());

// Test only add the malware IP killswitch
csd_chunks.clear();
chunk.hosts.clear();
Expand All @@ -1434,6 +1437,8 @@ TEST_F(SafeBrowsingDatabaseTest, Whitelists) {
database_->UpdateFinished(true);

EXPECT_TRUE(database_->IsMalwareIPMatchKillSwitchOn());
// The CSD whitelist killswitch is not present.
EXPECT_FALSE(database_->IsCsdWhitelistKillSwitchOn());

// Test that the kill-switch works as intended.
csd_chunks.clear();
Expand All @@ -1454,6 +1459,8 @@ TEST_F(SafeBrowsingDatabaseTest, Whitelists) {
download_chunks);
database_->UpdateFinished(true);

// The CSD whitelist killswitch is present.
EXPECT_TRUE(database_->IsCsdWhitelistKillSwitchOn());
EXPECT_TRUE(database_->IsMalwareIPMatchKillSwitchOn());
EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
GURL(std::string("https://") + kGood1Url2 + "/c.html")));
Expand Down Expand Up @@ -1501,6 +1508,7 @@ TEST_F(SafeBrowsingDatabaseTest, Whitelists) {
database_->UpdateFinished(true);

EXPECT_FALSE(database_->IsMalwareIPMatchKillSwitchOn());
EXPECT_FALSE(database_->IsCsdWhitelistKillSwitchOn());
EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
GURL(std::string("https://") + kGood1Url2 + "/c.html")));
EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ class TestSafeBrowsingDatabase : public SafeBrowsingDatabase {
virtual bool IsMalwareIPMatchKillSwitchOn() OVERRIDE {
return false;
}
virtual bool IsCsdWhitelistKillSwitchOn() OVERRIDE {
return false;
}

// Fill up the database with test URL.
void AddUrl(const GURL& url,
Expand Down

0 comments on commit ff17bbb

Please sign in to comment.