From 4729514a22bb0f6f4bc94544e45431def820bf0b Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 5 Apr 2020 02:13:53 -0700 Subject: [PATCH] Remove snet module from Magisk --- build.py | 20 --- settings.gradle | 2 +- snet/.gitignore | 1 - snet/build.gradle | 23 ---- snet/proguard-rules.pro | 29 ----- snet/src/main/AndroidManifest.xml | 7 - .../com/topjohnwu/snet/SafetyNetHelper.java | 122 ------------------ 7 files changed, 1 insertion(+), 203 deletions(-) delete mode 100644 snet/.gitignore delete mode 100644 snet/build.gradle delete mode 100644 snet/proguard-rules.pro delete mode 100644 snet/src/main/AndroidManifest.xml delete mode 100644 snet/src/main/java/com/topjohnwu/snet/SafetyNetHelper.java diff --git a/build.py b/build.py index f813ad8b0..db2098475 100755 --- a/build.py +++ b/build.py @@ -395,22 +395,6 @@ def build_stub(args): build_apk(args, 'stub') -def build_snet(args): - header('* Building snet extension') - proc = execv([gradlew, 'snet:assembleRelease']) - if proc.returncode != 0: - error('Build snet extention failed!') - source = op.join('snet', 'build', 'outputs', 'apk', - 'release', 'snet-release-unsigned.apk') - target = op.join(config['outdir'], 'snet.jar') - # Extract classes.dex - with zipfile.ZipFile(target, 'w', compression=zipfile.ZIP_DEFLATED, allowZip64=False) as zout: - with zipfile.ZipFile(source) as zin: - zout.writestr('classes.dex', zin.read('classes.dex')) - rm(source) - header('Output: ' + target) - - def zip_main(args): header('* Packing Flashable Zip') @@ -629,10 +613,6 @@ stub_parser = subparsers.add_parser( 'stub', help='build stub Magisk Manager') stub_parser.set_defaults(func=build_stub) -snet_parser = subparsers.add_parser( - 'snet', help='build snet extention for Magisk Manager') -snet_parser.set_defaults(func=build_snet) - zip_parser = subparsers.add_parser( 'zip', help='zip Magisk into a flashable zip') zip_parser.set_defaults(func=zip_main) diff --git a/settings.gradle b/settings.gradle index fda1b71b5..3d9f4590a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':signing', ':native', ':snet', ':stub', ':shared' +include ':app', ':signing', ':native', ':stub', ':shared' diff --git a/snet/.gitignore b/snet/.gitignore deleted file mode 100644 index 796b96d1c..000000000 --- a/snet/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/snet/build.gradle b/snet/build.gradle deleted file mode 100644 index 37e6be2c0..000000000 --- a/snet/build.gradle +++ /dev/null @@ -1,23 +0,0 @@ -apply plugin: 'com.android.application' - -android { - defaultConfig { - applicationId 'com.topjohnwu.snet' - minSdkVersion 14 - versionCode 13 - versionName 'snet' - } - - buildTypes { - release { - minifyEnabled true - shrinkResources true - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.google.android.gms:play-services-safetynet:17.0.0' -} diff --git a/snet/proguard-rules.pro b/snet/proguard-rules.pro deleted file mode 100644 index 934fdf271..000000000 --- a/snet/proguard-rules.pro +++ /dev/null @@ -1,29 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile - --keep,allowobfuscation class com.topjohnwu.snet.SafetyNetHelper --keepclassmembers class com.topjohnwu.snet.SafetyNetHelper { - ** get(...); -} - --repackageclasses 'x' --allowaccessmodification diff --git a/snet/src/main/AndroidManifest.xml b/snet/src/main/AndroidManifest.xml deleted file mode 100644 index 4fa18362e..000000000 --- a/snet/src/main/AndroidManifest.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - diff --git a/snet/src/main/java/com/topjohnwu/snet/SafetyNetHelper.java b/snet/src/main/java/com/topjohnwu/snet/SafetyNetHelper.java deleted file mode 100644 index 351b5f4f4..000000000 --- a/snet/src/main/java/com/topjohnwu/snet/SafetyNetHelper.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.topjohnwu.snet; - -import android.content.Context; -import android.util.Base64; -import android.util.Log; - -import androidx.annotation.NonNull; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GoogleApiAvailability; -import com.google.android.gms.common.api.ApiException; -import com.google.android.gms.safetynet.SafetyNet; -import com.google.android.gms.safetynet.SafetyNetApi; -import com.google.android.gms.safetynet.SafetyNetClient; -import com.google.android.gms.tasks.OnFailureListener; -import com.google.android.gms.tasks.OnSuccessListener; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.security.SecureRandom; - -public class SafetyNetHelper implements InvocationHandler, - OnSuccessListener, OnFailureListener { - - private static final int RESPONSE_ERR = 0x01; - private static final int CONNECTION_FAIL = 0x02; - private static final int BASIC_PASS = 0x10; - private static final int CTS_PASS = 0x20; - - private static final GoogleApiAvailability API_AVAIL = GoogleApiAvailability.getInstance(); - private static final SecureRandom RANDOM = new SecureRandom(); - private static final String TAG = "SNET"; - - private final Context context; - private final Object callback; - - public static Object get(Class interfaceClass, Context context, Object cb) { - return Proxy.newProxyInstance(SafetyNetHelper.class.getClassLoader(), - new Class[]{interfaceClass}, new SafetyNetHelper(context, cb)); - } - - private SafetyNetHelper(Context c, Object cb) { - context = c; - callback = cb; - } - - private void invokeCallback(int code) { - Class clazz = callback.getClass(); - try { - clazz.getMethod("onResponse", int.class).invoke(callback, code); - } catch (Exception ignored) { - } - } - - /* Return magic API key here :) */ - private String getApiKey() { - return ""; - } - - private int getVersion() { - return BuildConfig.VERSION_CODE; - } - - private void attest() { - int code = API_AVAIL.isGooglePlayServicesAvailable(context); - if (code != ConnectionResult.SUCCESS) { - Log.e(TAG, API_AVAIL.getErrorString(code)); - invokeCallback(CONNECTION_FAIL); - return; - } - // Create nonce - byte[] nonce = new byte[24]; - RANDOM.nextBytes(nonce); - - SafetyNetClient client = SafetyNet.getClient(context); - client.attest(nonce, getApiKey()).addOnSuccessListener(this).addOnFailureListener(this); - } - - @Override - public void onSuccess(SafetyNetApi.AttestationResponse result) { - int code = 0; - try { - String jsonStr = new String(Base64.decode( - result.getJwsResult().split("\\.")[1], Base64.DEFAULT)); - JSONObject json = new JSONObject(jsonStr); - code |= json.getBoolean("ctsProfileMatch") ? CTS_PASS : 0; - code |= json.getBoolean("basicIntegrity") ? BASIC_PASS : 0; - } catch (JSONException e) { - code = RESPONSE_ERR; - } - - // Return results - invokeCallback(code); - } - - @Override - public void onFailure(@NonNull Exception e) { - if (e instanceof ApiException) { - int errCode = ((ApiException) e).getStatusCode(); - Log.e(TAG, API_AVAIL.getErrorString(errCode)); - } else { - Log.e(TAG, "Unknown: " + e); - } - invokeCallback(CONNECTION_FAIL); - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) { - switch (method.getName()) { - case "attest": - attest(); - break; - case "getVersion": - return getVersion(); - } - return null; - } -}