Remove snet module from Magisk

This commit is contained in:
topjohnwu 2020-04-05 02:13:53 -07:00
parent 93aedcfeb7
commit 4729514a22
7 changed files with 1 additions and 203 deletions

View File

@ -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)

View File

@ -1 +1 @@
include ':app', ':signing', ':native', ':snet', ':stub', ':shared'
include ':app', ':signing', ':native', ':stub', ':shared'

1
snet/.gitignore vendored
View File

@ -1 +0,0 @@
/build

View File

@ -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'
}

View File

@ -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

View File

@ -1,7 +0,0 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.topjohnwu.snet">
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</manifest>

View File

@ -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<SafetyNetApi.AttestationResponse>, 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;
}
}