Add boot signing

This commit is contained in:
topjohnwu
2017-10-30 03:45:22 +08:00
parent 2ee0829871
commit 05f41928cd
17 changed files with 460 additions and 68 deletions

View File

@ -2,7 +2,7 @@ package com.topjohnwu.magisk.asyncs;
import android.app.Activity;
import com.topjohnwu.jarsigner.ByteArrayStream;
import com.topjohnwu.crypto.ByteArrayStream;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.WebService;

View File

@ -3,7 +3,7 @@ package com.topjohnwu.magisk.asyncs;
import android.os.Environment;
import android.widget.Toast;
import com.topjohnwu.jarsigner.JarMap;
import com.topjohnwu.crypto.JarMap;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.database.SuDatabaseHelper;

View File

@ -14,6 +14,7 @@ import android.view.WindowManager;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
public class Activity extends AppCompatActivity {
@ -88,14 +89,9 @@ public class Activity extends AppCompatActivity {
@Keep
public void swapResources(String dexPath) {
try {
AssetManager asset = AssetManager.class.newInstance();
AssetManager.class.getMethod("addAssetPath", String.class).invoke(asset, dexPath);
mAssetManager = asset;
} catch (Exception e) {
e.printStackTrace();
mAssetManager = Utils.getAssets(dexPath);
if (mAssetManager == null)
return;
}
Resources res = super.getResources();
mResources = new Resources(mAssetManager, res.getDisplayMetrics(), res.getConfiguration());
mResources.newTheme().setTo(super.getTheme());

View File

@ -3,8 +3,9 @@ package com.topjohnwu.magisk.services;
import android.app.IntentService;
import android.content.Intent;
import android.os.Build;
import android.support.v7.app.NotificationCompat;
import android.support.v4.app.NotificationCompat;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
public class OnBootIntentService extends IntentService {
@ -19,7 +20,8 @@ public class OnBootIntentService extends IntentService {
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this, MagiskManager.NOTIFICATION_CHANNEL);
builder.setSmallIcon(R.drawable.ic_magisk)
.setContentTitle("onBoot")
.setContentText("Running onBoot operations...");

View File

@ -0,0 +1,46 @@
package com.topjohnwu.magisk.utils;
import android.content.res.AssetManager;
import com.topjohnwu.crypto.SignBoot;
import java.io.FileInputStream;
import java.io.InputStream;
public class BootSigner {
public static void main(String[] args) throws Exception {
if ("-verify".equals(args[0])) {
String certPath = "";
if (args.length >= 4 && "-certificate".equals(args[2])) {
/* args[3] is the path to a public key certificate */
certPath = args[3];
}
/* args[1] is the path to a signed boot image */
boolean signed = SignBoot.verifySignature(args[1],
certPath.isEmpty() ? null : new FileInputStream(certPath));
System.exit(signed ? 0 : 1);
} else {
/* args[0] is the target name, typically /boot
args[1] is the path to a boot image to sign
args[2] is the path where to output the signed boot image
args[3] is the path to a private key
args[4] is the path to the matching public key certificate
*/
InputStream keyIn, sigIn;
if (args.length >= 5) {
keyIn = new FileInputStream(args[3]);
sigIn = new FileInputStream(args[4]);
} else {
/* Use internal test keys */
AssetManager asset = Utils.getAssets(System.getProperty("java.class.path"));
if (asset == null)
System.exit(1);
keyIn = asset.open(ZipUtils.PRIVATE_KEY_NAME);
sigIn = asset.open(ZipUtils.PUBLIC_KEY_NAME);
}
SignBoot.doSignature(args[0], args[1], args[2], keyIn, sigIn);
}
}
}

View File

@ -7,6 +7,7 @@ import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.database.Cursor;
import android.net.ConnectivityManager;
@ -203,4 +204,15 @@ public class Utils {
public static File getDatabasePath(Context context, String dbName) {
return new File(context.getFilesDir().getParent() + "/databases", dbName);
}
public static AssetManager getAssets(String apk) {
try {
AssetManager asset = AssetManager.class.newInstance();
AssetManager.class.getMethod("addAssetPath", String.class).invoke(asset, apk);
return asset;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -2,8 +2,8 @@ package com.topjohnwu.magisk.utils;
import android.content.res.AssetManager;
import com.topjohnwu.jarsigner.JarMap;
import com.topjohnwu.jarsigner.SignAPK;
import com.topjohnwu.crypto.JarMap;
import com.topjohnwu.crypto.SignAPK;
import com.topjohnwu.magisk.MagiskManager;
import java.io.BufferedInputStream;
@ -16,8 +16,8 @@ import java.util.jar.JarInputStream;
public class ZipUtils {
// File name in assets
private static final String PUBLIC_KEY_NAME = "public.certificate.x509.pem";
private static final String PRIVATE_KEY_NAME = "private.key.pk8";
static final String PUBLIC_KEY_NAME = "public.certificate.x509.pem";
static final String PRIVATE_KEY_NAME = "private.key.pk8";
static {
System.loadLibrary("zipadjust");