Skip to content

Commit

Permalink
Fixed mismatched threat codes; removed patches
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyBarabash committed Oct 8, 2024
1 parent 0067b16 commit 9b6df6f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 75 deletions.
10 changes: 0 additions & 10 deletions build/android/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand All @@ -89,34 +106,38 @@ public static int[] safeBrowsingToSafetyNetThreatTypes(int[] safeBrowsingThreatT
List<Integer> arrSafetyNetThreatTypes = new ArrayList<Integer>();
for (int i = 0; i < safeBrowsingThreatTypes.length; ++i) {
int safetyNetThreatType =
sbThreatTypeToSafetyNetJavaThreatType(safeBrowsingThreatTypes[i]);
safeBrowsingToSafetyNetJavaThreatType(safeBrowsingThreatTypes[i]);
if (safetyNetThreatType != SafetyNetJavaThreatType.MAX_VALUE) {
arrSafetyNetThreatTypes.add(safetyNetThreatType);
}
}
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;
}
}
}
12 changes: 0 additions & 12 deletions patches/android_webview-BUILD.gn.patch

This file was deleted.

12 changes: 0 additions & 12 deletions patches/components-safe_browsing-android-BUILD.gn.patch

This file was deleted.

0 comments on commit 9b6df6f

Please sign in to comment.