From 08818e85424a5bfa7ef8f4eb6635fe390334c29a Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Fri, 26 Jun 2020 17:43:39 +0800 Subject: [PATCH] Remove force_pm_install gms package verifier only checks the `notBefore` value of the certificate --- .../com/topjohnwu/magisk/core/utils/Keygen.kt | 16 +++------------- .../com/topjohnwu/magisk/core/utils/PatchAPK.kt | 2 +- app/src/main/res/raw/manager.sh | 10 ---------- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/Keygen.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/Keygen.kt index 3920c76eb..7c79fef39 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/Keygen.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/Keygen.kt @@ -35,10 +35,11 @@ class Keygen(context: Context) : CertKeyProvider { private const val ALIAS = "magisk" private val PASSWORD get() = "magisk".toCharArray() private const val TESTKEY_CERT = "61ed377e85d386a8dfee6b864bd85b0bfaa5af81" + private const val DNAME = "C=US,ST=California,L=Mountain View,O=Google Inc.,OU=Android,CN=Android" private const val BASE64_FLAG = Base64.NO_PADDING or Base64.NO_WRAP } - private val start = Calendar.getInstance() + private val start = Calendar.getInstance().apply { add(Calendar.MONTH, -3) } private val end = Calendar.getInstance().apply { add(Calendar.YEAR, 30) } override val cert get() = provider.cert @@ -85,17 +86,6 @@ class Keygen(context: Context) : CertKeyProvider { } } - private fun randomString(): String { - val rand = kotlin.random.Random.Default - val len = rand.nextInt(5, 10) - val sb = StringBuilder(len) - for (i in 0..len) { - val idx = rand.nextInt(ALPHANUM.length) - sb.append(ALPHANUM[idx]) - } - return sb.toString() - } - private fun init(): KeyStore { val raw = Config.keyStoreRaw val ks = KeyStore.getInstance("PKCS12") @@ -117,7 +107,7 @@ class Keygen(context: Context) : CertKeyProvider { // Generate new private key and certificate val kp = KeyPairGenerator.getInstance("RSA").apply { initialize(4096) }.genKeyPair() - val dname = X500Name("CN=${randomString()}") + val dname = X500Name(DNAME) val builder = JcaX509v3CertificateBuilder(dname, BigInteger(160, Random()), start.time, end.time, dname, kp.public) val signer = JcaContentSignerBuilder("SHA1WithRSA").build(kp.private) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/PatchAPK.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/PatchAPK.kt index 06ea0b54b..9e6e033fd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/PatchAPK.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/PatchAPK.kt @@ -130,7 +130,7 @@ object PatchAPK { // Install the application repack.setReadable(true, false) - if (!Shell.su("force_pm_install $repack").exec().isSuccess) + if (!Shell.su("pm install $repack").exec().isSuccess) return false Config.suManager = pkg.toString() diff --git a/app/src/main/res/raw/manager.sh b/app/src/main/res/raw/manager.sh index a6048fa42..08f223aba 100644 --- a/app/src/main/res/raw/manager.sh +++ b/app/src/main/res/raw/manager.sh @@ -85,16 +85,6 @@ EOF cd / } -force_pm_install() { - local APK=$1 - local VERIFY=`settings get global package_verifier_enable` - [ "$VERIFY" -eq 1 ] && settings put global package_verifier_enable 0 - pm install -r $APK - local res=$? - [ "$VERIFY" -eq 1 ] && settings put global package_verifier_enable 1 - return $res -} - check_boot_ramdisk() { # Create boolean ISAB [ -z $SLOT ] && ISAB=false || ISAB=true