From 9b6df6f76199be4c3cc34391450278b55e88f656 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 8 Oct 2024 13:45:37 +0300 Subject: [PATCH] Fixed mismatched threat codes; removed patches --- build/android/config.gni | 10 --- .../BraveSafeBrowsingApiHandler.java | 27 +++---- .../safe_browsing/BraveSafeBrowsingUtils.java | 73 ++++++++++++------- patches/android_webview-BUILD.gn.patch | 12 --- ...nents-safe_browsing-android-BUILD.gn.patch | 12 --- 5 files changed, 59 insertions(+), 75 deletions(-) delete mode 100644 patches/android_webview-BUILD.gn.patch delete mode 100644 patches/components-safe_browsing-android-BUILD.gn.patch diff --git a/build/android/config.gni b/build/android/config.gni index e1b89ef9bc3c..1303360c1b89 100644 --- a/build/android/config.gni +++ b/build/android/config.gni @@ -94,16 +94,6 @@ brave_resources_exclusion_exceptions = playcore_target = "//brave/third_party/android_deps:com_google_android_play_core_java" -# The variable below are required to use SBThreatType enum at -# BraveSafeBrowsingApiHandler / BraveSafeBrowsingUtils. -# Direct add "//components/safe_browsing/core/browser/db:sb_threat_values" into -# //brave/components/safe_browsing/android:brave_safe_browsing_java -# causes 'Type org.chromium.components.safe_browsing.SBThreatType is defined multiple times' error -brave_android_webview_browser_java_srcjar_deps_exclude = - [ "//components/safe_browsing/core/browser/db:sb_threat_values" ] -brave_components_safe_browsing_android_safe_browsing_java_srcjar_deps = - [ "//components/safe_browsing/core/browser/db:sb_threat_values" ] - brave_jni_headers_sources = [ "//brave/android/java/org/chromium/chrome/browser/BraveFeatureUtil.java", "//brave/android/java/org/chromium/chrome/browser/BraveLocalState.java", diff --git a/components/safe_browsing/android/java/src/org/chromium/components/safe_browsing/BraveSafeBrowsingApiHandler.java b/components/safe_browsing/android/java/src/org/chromium/components/safe_browsing/BraveSafeBrowsingApiHandler.java index 7b684613238f..fb4b126d700f 100644 --- a/components/safe_browsing/android/java/src/org/chromium/components/safe_browsing/BraveSafeBrowsingApiHandler.java +++ b/components/safe_browsing/android/java/src/org/chromium/components/safe_browsing/BraveSafeBrowsingApiHandler.java @@ -17,6 +17,8 @@ import org.chromium.base.ContextUtils; import org.chromium.base.Log; +import org.chromium.components.safe_browsing.BraveSafeBrowsingUtils.SafeBrowsingJavaResponseStatus; +import org.chromium.components.safe_browsing.BraveSafeBrowsingUtils.SafeBrowsingJavaThreatType; import org.chromium.components.safe_browsing.SafeBrowsingApiHandler.LookupResult; /** @@ -87,9 +89,9 @@ public void startUriLookup(long callbackId, String uri, int[] threatTypes, int p mObserver.onUrlCheckDone( callbackId, LookupResult.FAILURE_API_CALL_TIMEOUT, - SBThreatType.UNUSED, + SafeBrowsingJavaThreatType.NO_THREAT, THREAT_ATTRIBUTES_STUB, - BraveSafeBrowsingUtils.SafeBrowsingJavaResponseStatus.SUCCESS_WITH_REAL_TIME, + SafeBrowsingJavaResponseStatus.SUCCESS_WITH_REAL_TIME, DEFAULT_CHECK_DELTA); return; } @@ -108,15 +110,13 @@ public void startUriLookup(long callbackId, String uri, int[] threatTypes, int p mBraveSafeBrowsingApiHandlerDelegate.getActivity(), sbResponse -> { mTriesCount = 0; - if (sbResponse.getDetectedThreats().isEmpty()) { mObserver.onUrlCheckDone( callbackId, LookupResult.SUCCESS, - SBThreatType.SAFE, + SafeBrowsingJavaThreatType.NO_THREAT, THREAT_ATTRIBUTES_STUB, - BraveSafeBrowsingUtils.SafeBrowsingJavaResponseStatus - .SUCCESS_WITH_REAL_TIME, + SafeBrowsingJavaResponseStatus.SUCCESS_WITH_REAL_TIME, DEFAULT_CHECK_DELTA); return; } else { @@ -127,14 +127,13 @@ public void startUriLookup(long callbackId, String uri, int[] threatTypes, int p callbackId, LookupResult.SUCCESS, BraveSafeBrowsingUtils - .safetyNetJavaThreatTypeToSBThreatType( + .safetyNetToSafeBrowsingJavaThreatType( sbResponse .getDetectedThreats() .get(0) .getThreatType()), THREAT_ATTRIBUTES_STUB, - BraveSafeBrowsingUtils.SafeBrowsingJavaResponseStatus - .SUCCESS_WITH_REAL_TIME, + SafeBrowsingJavaResponseStatus.SUCCESS_WITH_REAL_TIME, DEFAULT_CHECK_DELTA); return; } @@ -180,10 +179,9 @@ public void startUriLookup(long callbackId, String uri, int[] threatTypes, int p mObserver.onUrlCheckDone( callbackId, LookupResult.FAILURE_API_CALL_TIMEOUT, - SBThreatType.UNUSED, + SafeBrowsingJavaThreatType.NO_THREAT, THREAT_ATTRIBUTES_STUB, - BraveSafeBrowsingUtils.SafeBrowsingJavaResponseStatus - .SUCCESS_WITH_REAL_TIME, + SafeBrowsingJavaResponseStatus.SUCCESS_WITH_REAL_TIME, DEFAULT_CHECK_DELTA); } } else { @@ -194,10 +192,9 @@ public void startUriLookup(long callbackId, String uri, int[] threatTypes, int p mObserver.onUrlCheckDone( callbackId, LookupResult.FAILURE_API_CALL_TIMEOUT, - SBThreatType.UNUSED, + SafeBrowsingJavaThreatType.NO_THREAT, THREAT_ATTRIBUTES_STUB, - BraveSafeBrowsingUtils.SafeBrowsingJavaResponseStatus - .SUCCESS_WITH_REAL_TIME, + SafeBrowsingJavaResponseStatus.SUCCESS_WITH_REAL_TIME, DEFAULT_CHECK_DELTA); } mTriesCount = 0; diff --git a/components/safe_browsing/android/java/src/org/chromium/components/safe_browsing/BraveSafeBrowsingUtils.java b/components/safe_browsing/android/java/src/org/chromium/components/safe_browsing/BraveSafeBrowsingUtils.java index 48ec0157953c..a1ed9cbf354e 100644 --- a/components/safe_browsing/android/java/src/org/chromium/components/safe_browsing/BraveSafeBrowsingUtils.java +++ b/components/safe_browsing/android/java/src/org/chromium/components/safe_browsing/BraveSafeBrowsingUtils.java @@ -39,7 +39,6 @@ public class BraveSafeBrowsingUtils { int MAX_VALUE = 17; } - // SUCCESS_WITH_REAL_TIME @IntDef({ SafeBrowsingJavaResponseStatus.SUCCESS_WITH_LOCAL_BLOCKLIST, SafeBrowsingJavaResponseStatus.SUCCESS_WITH_REAL_TIME, @@ -59,27 +58,45 @@ public class BraveSafeBrowsingUtils { int FAILURE_INVALID_URL = 6; }; - private static int sbThreatTypeToSafetyNetJavaThreatType(int safeBrowsingThreatType) { + @IntDef({ + SafeBrowsingJavaThreatType.NO_THREAT, + SafeBrowsingJavaThreatType.SOCIAL_ENGINEERING, + SafeBrowsingJavaThreatType.UNWANTED_SOFTWARE, + SafeBrowsingJavaThreatType.POTENTIALLY_HARMFUL_APPLICATION, + SafeBrowsingJavaThreatType.BILLING, + SafeBrowsingJavaThreatType.ABUSIVE_EXPERIENCE_VIOLATION, + SafeBrowsingJavaThreatType.BETTER_ADS_VIOLATION + }) + public @interface SafeBrowsingJavaThreatType { + int NO_THREAT = 0; + int SOCIAL_ENGINEERING = 2; + int UNWANTED_SOFTWARE = 3; + int POTENTIALLY_HARMFUL_APPLICATION = 4; + int BILLING = 15; + int ABUSIVE_EXPERIENCE_VIOLATION = 20; + int BETTER_ADS_VIOLATION = 21; + }; + + private static int safeBrowsingToSafetyNetJavaThreatType(int safeBrowsingThreatType) { switch (safeBrowsingThreatType) { - case SBThreatType.BILLING: - return SafetyNetJavaThreatType.BILLING; - case SBThreatType.SUBRESOURCE_FILTER: - return SafetyNetJavaThreatType.SUBRESOURCE_FILTER; - case SBThreatType.URL_PHISHING: + case SafeBrowsingJavaThreatType.NO_THREAT: + return 0; + case SafeBrowsingJavaThreatType.SOCIAL_ENGINEERING: return SafetyNetJavaThreatType.SOCIAL_ENGINEERING; - case SBThreatType.URL_MALWARE: - return SafetyNetJavaThreatType.POTENTIALLY_HARMFUL_APPLICATION; - case SBThreatType.URL_UNWANTED: + case SafeBrowsingJavaThreatType.UNWANTED_SOFTWARE: return SafetyNetJavaThreatType.UNWANTED_SOFTWARE; - case SBThreatType.CSD_ALLOWLIST: - return SafetyNetJavaThreatType.CSD_ALLOWLIST; + case SafeBrowsingJavaThreatType.POTENTIALLY_HARMFUL_APPLICATION: + return SafetyNetJavaThreatType.POTENTIALLY_HARMFUL_APPLICATION; + case SafeBrowsingJavaThreatType.BILLING: + return SafetyNetJavaThreatType.BILLING; + case SafeBrowsingJavaThreatType.ABUSIVE_EXPERIENCE_VIOLATION: + case SafeBrowsingJavaThreatType.BETTER_ADS_VIOLATION: + // See SafeBrowsingJavaToSBThreatType at safe_browsing_api_handler_bridge.cc + return SafetyNetJavaThreatType.SUBRESOURCE_FILTER; default: - // Threats codes seen here without SafetyNet counterpart: - // int SUSPICIOUS_SITE = 20; - // int SIGNED_IN_SYNC_PASSWORD_REUSE = 15; Log.w( TAG, - "sbThreatTypeToSafetyNetJavaThreatType: unexpected safeBrowsingThreatType=" + "safeBrowsingToSafetyNetJavaThreatType: unexpected safeBrowsingThreatType=" + safeBrowsingThreatType); return SafetyNetJavaThreatType.MAX_VALUE; } @@ -89,7 +106,7 @@ public static int[] safeBrowsingToSafetyNetThreatTypes(int[] safeBrowsingThreatT List arrSafetyNetThreatTypes = new ArrayList(); for (int i = 0; i < safeBrowsingThreatTypes.length; ++i) { int safetyNetThreatType = - sbThreatTypeToSafetyNetJavaThreatType(safeBrowsingThreatTypes[i]); + safeBrowsingToSafetyNetJavaThreatType(safeBrowsingThreatTypes[i]); if (safetyNetThreatType != SafetyNetJavaThreatType.MAX_VALUE) { arrSafetyNetThreatTypes.add(safetyNetThreatType); } @@ -97,26 +114,30 @@ public static int[] safeBrowsingToSafetyNetThreatTypes(int[] safeBrowsingThreatT return arrSafetyNetThreatTypes.stream().mapToInt(i -> i).toArray(); } - public static int safetyNetJavaThreatTypeToSBThreatType(int safetyNetThreatType) { + public static int safetyNetToSafeBrowsingJavaThreatType(int safetyNetThreatType) { switch (safetyNetThreatType) { case SafetyNetJavaThreatType.BILLING: - return SBThreatType.BILLING; + return SafeBrowsingJavaThreatType.BILLING; case SafetyNetJavaThreatType.SUBRESOURCE_FILTER: - return SBThreatType.SUBRESOURCE_FILTER; + Log.w(TAG, "safetyNetToSafeBrowsingJavaThreatType: unexpected SUBRESOURCE_FILTER"); + assert false; + return SafeBrowsingJavaThreatType.NO_THREAT; case SafetyNetJavaThreatType.SOCIAL_ENGINEERING: - return SBThreatType.URL_PHISHING; + return SafeBrowsingJavaThreatType.SOCIAL_ENGINEERING; case SafetyNetJavaThreatType.POTENTIALLY_HARMFUL_APPLICATION: - return SBThreatType.URL_MALWARE; + return SafeBrowsingJavaThreatType.POTENTIALLY_HARMFUL_APPLICATION; case SafetyNetJavaThreatType.UNWANTED_SOFTWARE: - return SBThreatType.URL_UNWANTED; + return SafeBrowsingJavaThreatType.UNWANTED_SOFTWARE; case SafetyNetJavaThreatType.CSD_ALLOWLIST: - return SBThreatType.CSD_ALLOWLIST; + Log.w(TAG, "safetyNetToSafeBrowsingJavaThreatType: unexpected CSD_ALLOWLIST"); + assert false; + return SafeBrowsingJavaThreatType.NO_THREAT; default: Log.w( TAG, - "safetyNetJavaThreatTypeToSBThreatType: unexpected safetyNetThreatType=" + "safetyNetToSafeBrowsingJavaThreatType: unexpected safetyNetThreatType=" + safetyNetThreatType); - return SafetyNetJavaThreatType.MAX_VALUE; + return SafeBrowsingJavaThreatType.NO_THREAT; } } } diff --git a/patches/android_webview-BUILD.gn.patch b/patches/android_webview-BUILD.gn.patch deleted file mode 100644 index 89092bbae4d9..000000000000 --- a/patches/android_webview-BUILD.gn.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/android_webview/BUILD.gn b/android_webview/BUILD.gn -index 2be3d2d8aab8ec0023196d7efc9e3f832cab458b..a4558144ca5f63fec07c66ffd339c3f8ccc671c7 100644 ---- a/android_webview/BUILD.gn -+++ b/android_webview/BUILD.gn -@@ -773,6 +773,7 @@ android_library("browser_java") { - ] - - resources_package = "org.chromium.android_webview" -+ srcjar_deps -= brave_android_webview_browser_java_srcjar_deps_exclude - } - - android_library("common_variations_java") { diff --git a/patches/components-safe_browsing-android-BUILD.gn.patch b/patches/components-safe_browsing-android-BUILD.gn.patch deleted file mode 100644 index 3bd2eed1d191..000000000000 --- a/patches/components-safe_browsing-android-BUILD.gn.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/components/safe_browsing/android/BUILD.gn b/components/safe_browsing/android/BUILD.gn -index 3dc301f1f7d0e1dab061079b1f11505136b67816..087329e1bfc2cd9d2e03396656be017fcb995843 100644 ---- a/components/safe_browsing/android/BUILD.gn -+++ b/components/safe_browsing/android/BUILD.gn -@@ -27,6 +27,7 @@ android_library("safe_browsing_java") { - "java/src/org/chromium/components/safe_browsing/SafeBrowsingApiHandler.java", - "java/src/org/chromium/components/safe_browsing/SafetyNetApiHandler.java", - ] -+ srcjar_deps += brave_components_safe_browsing_android_safe_browsing_java_srcjar_deps - } - - # Expose Safe Browsing feature flags to Java code