Commit 2650506a authored by Balazs Engedy's avatar Balazs Engedy Committed by Commit Bot

Make API_ABUSE Safe Browsing list platform-specific.

Update GetChromeUrlApiId() to use {WINDOWS|LINUX|OSX|ANDROID}_PLATFORM as
|platform_type|, based on the current platform, instead of CHROME_PLATFORM
being hard-coded.

This change also necessitates relaxing the check in
V4GetHashProtocolManager::ParseMetadata to expect permission-related
metadata to be present for each of the above, now platform-specific,
versions of the API_ABUSE list.

Bug: 1028642
Change-Id: I88f917f04368470b77eca647972883d859fdcbc9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1945823
Commit-Queue: Balazs Engedy <engedy@chromium.org>
Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721296}
parent 6b57ecfe
...@@ -617,8 +617,7 @@ void V4GetHashProtocolManager::ParseMetadata(const ThreatMatch& match, ...@@ -617,8 +617,7 @@ void V4GetHashProtocolManager::ParseMetadata(const ThreatMatch& match,
ThreatMetadata* metadata) { ThreatMetadata* metadata) {
// Different threat types will handle the metadata differently. // Different threat types will handle the metadata differently.
if (match.threat_type() == API_ABUSE) { if (match.threat_type() == API_ABUSE) {
if (!match.has_platform_type() || if (!match.has_platform_type()) {
match.platform_type() != CHROME_PLATFORM) {
RecordParseGetHashResult(UNEXPECTED_PLATFORM_TYPE_ERROR); RecordParseGetHashResult(UNEXPECTED_PLATFORM_TYPE_ERROR);
return; return;
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/simple_test_clock.h" #include "base/test/simple_test_clock.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h"
#include "components/safe_browsing/db/safebrowsing.pb.h" #include "components/safe_browsing/db/safebrowsing.pb.h"
#include "components/safe_browsing/db/util.h" #include "components/safe_browsing/db/util.h"
#include "components/safe_browsing/db/v4_test_util.h" #include "components/safe_browsing/db/v4_test_util.h"
...@@ -364,8 +365,18 @@ TEST_F(V4GetHashProtocolManagerTest, ...@@ -364,8 +365,18 @@ TEST_F(V4GetHashProtocolManagerTest,
TEST_F(V4GetHashProtocolManagerTest, TestGetHashRequest) { TEST_F(V4GetHashProtocolManagerTest, TestGetHashRequest) {
FindFullHashesRequest req; FindFullHashesRequest req;
ThreatInfo* info = req.mutable_threat_info(); ThreatInfo* info = req.mutable_threat_info();
for (const PlatformType& p :
std::set<PlatformType>{GetCurrentPlatformType(), CHROME_PLATFORM}) { const std::set<PlatformType> platform_types = {
GetCurrentPlatformType(),
CHROME_PLATFORM,
// TODO(crbug.com/1030487): This special case for Android will no longer be
// needed once GetCurrentPlatformType() returns ANDROID_PLATFORM on Android.
#if defined(OS_ANDROID)
ANDROID_PLATFORM,
#endif
};
for (const PlatformType& p : platform_types) {
info->add_platform_types(p); info->add_platform_types(p);
} }
...@@ -412,7 +423,13 @@ TEST_F(V4GetHashProtocolManagerTest, TestParseHashResponse) { ...@@ -412,7 +423,13 @@ TEST_F(V4GetHashProtocolManagerTest, TestParseHashResponse) {
res.mutable_minimum_wait_duration()->set_seconds(400); res.mutable_minimum_wait_duration()->set_seconds(400);
ThreatMatch* m = res.add_matches(); ThreatMatch* m = res.add_matches();
m->set_threat_type(API_ABUSE); m->set_threat_type(API_ABUSE);
m->set_platform_type(CHROME_PLATFORM); // TODO(crbug.com/1030487): This special case for Android will no longer be
// needed once GetCurrentPlatformType() returns ANDROID_PLATFORM on Android.
#if defined(OS_ANDROID)
m->set_platform_type(ANDROID_PLATFORM);
#else
m->set_platform_type(GetCurrentPlatformType());
#endif
m->set_threat_entry_type(URL); m->set_threat_entry_type(URL);
m->mutable_cache_duration()->set_seconds(300); m->mutable_cache_duration()->set_seconds(300);
m->mutable_threat()->set_hash(full_hash); m->mutable_threat()->set_hash(full_hash);
...@@ -670,7 +687,13 @@ TEST_F(V4GetHashProtocolManagerTest, ...@@ -670,7 +687,13 @@ TEST_F(V4GetHashProtocolManagerTest,
res.mutable_negative_cache_duration()->set_seconds(600); res.mutable_negative_cache_duration()->set_seconds(600);
ThreatMatch* m = res.add_matches(); ThreatMatch* m = res.add_matches();
m->set_threat_type(API_ABUSE); m->set_threat_type(API_ABUSE);
m->set_platform_type(CHROME_PLATFORM); // TODO(crbug.com/1030487): This special case for Android will no longer be
// needed once GetCurrentPlatformType() returns ANDROID_PLATFORM on Android.
#if defined(OS_ANDROID)
m->set_platform_type(ANDROID_PLATFORM);
#else
m->set_platform_type(GetCurrentPlatformType());
#endif
m->set_threat_entry_type(URL); m->set_threat_entry_type(URL);
m->mutable_threat()->set_hash(full_hash); m->mutable_threat()->set_hash(full_hash);
ThreatEntryMetadata::MetadataEntry* e = ThreatEntryMetadata::MetadataEntry* e =
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#include "crypto/sha2.h" #include "crypto/sha2.h"
#include "google_apis/google_api_keys.h" #include "google_apis/google_api_keys.h"
...@@ -117,6 +118,10 @@ PlatformType GetCurrentPlatformType() { ...@@ -117,6 +118,10 @@ PlatformType GetCurrentPlatformType() {
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
return OSX_PLATFORM; return OSX_PLATFORM;
#else #else
// TODO(crbug.com/1030487): This file is, in fact, intended to be compiled on
// Android, the comment below is obsolete. We should be able to return
// ANDROID_PLATFORM here.
//
// This should ideally never compile but it is getting compiled on Android. // This should ideally never compile but it is getting compiled on Android.
// See: https://bugs.chromium.org/p/chromium/issues/detail?id=621647 // See: https://bugs.chromium.org/p/chromium/issues/detail?id=621647
// TODO(vakh): Once that bug is fixed, this should be removed. If we leave // TODO(vakh): Once that bug is fixed, this should be removed. If we leave
...@@ -135,7 +140,13 @@ ListIdentifier GetChromeExtMalwareId() { ...@@ -135,7 +140,13 @@ ListIdentifier GetChromeExtMalwareId() {
} }
ListIdentifier GetChromeUrlApiId() { ListIdentifier GetChromeUrlApiId() {
return ListIdentifier(CHROME_PLATFORM, URL, API_ABUSE); // TODO(crbug.com/1030487): This special case for Android will no longer be
// needed once GetCurrentPlatformType() returns ANDROID_PLATFORM on Android.
#if defined(OS_ANDROID)
return ListIdentifier(ANDROID_PLATFORM, URL, API_ABUSE);
#else
return ListIdentifier(GetCurrentPlatformType(), URL, API_ABUSE);
#endif
} }
ListIdentifier GetChromeUrlClientIncidentId() { ListIdentifier GetChromeUrlClientIncidentId() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment