mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-28 20:45:24 +00:00
Fix zipsigner when using external keys
This commit is contained in:
parent
bcdadc6581
commit
6d93831488
2
build.py
2
build.py
@ -361,7 +361,7 @@ def zip_uninstaller(args):
|
|||||||
header('Output: ' + output)
|
header('Output: ' + output)
|
||||||
|
|
||||||
def sign_adjust_zip(unsigned, output):
|
def sign_adjust_zip(unsigned, output):
|
||||||
signer_name = 'zipsigner-2.1.jar'
|
signer_name = 'zipsigner-2.2.jar'
|
||||||
jarsigner = os.path.join('utils', 'build', 'libs', signer_name)
|
jarsigner = os.path.join('utils', 'build', 'libs', signer_name)
|
||||||
|
|
||||||
if not os.path.exists(jarsigner):
|
if not os.path.exists(jarsigner):
|
||||||
|
@ -15,7 +15,7 @@ jar {
|
|||||||
shadowJar {
|
shadowJar {
|
||||||
baseName = 'zipsigner'
|
baseName = 'zipsigner'
|
||||||
classifier = null
|
classifier = null
|
||||||
version = 2.1
|
version = 2.2
|
||||||
}
|
}
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
@ -23,7 +23,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
|
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,6 +33,6 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
implementation 'org.bouncycastle:bcprov-jdk15on:1.58'
|
implementation 'org.bouncycastle:bcprov-jdk15on:1.59'
|
||||||
implementation 'org.bouncycastle:bcpkix-jdk15on:1.58'
|
implementation 'org.bouncycastle:bcpkix-jdk15on:1.59'
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.topjohnwu.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class ReusableInputStream extends BufferedInputStream {
|
||||||
|
|
||||||
|
public ReusableInputStream(InputStream in) {
|
||||||
|
super(in);
|
||||||
|
mark(Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReusableInputStream(InputStream in, int size) {
|
||||||
|
super(in, size);
|
||||||
|
mark(Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
/* Reset at close so we can reuse it */
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void destroy() throws IOException {
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
|||||||
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder;
|
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder;
|
||||||
import org.bouncycastle.util.encoders.Base64;
|
import org.bouncycastle.util.encoders.Base64;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -73,19 +74,31 @@ public class SignAPK {
|
|||||||
JarMap input, OutputStream output) throws Exception {
|
JarMap input, OutputStream output) throws Exception {
|
||||||
File temp1 = File.createTempFile("signAPK", null);
|
File temp1 = File.createTempFile("signAPK", null);
|
||||||
File temp2 = File.createTempFile("signAPK", null);
|
File temp2 = File.createTempFile("signAPK", null);
|
||||||
|
if (cert == null) {
|
||||||
|
cert = SignAPK.class.getResourceAsStream("/keys/testkey.x509.pem");
|
||||||
|
}
|
||||||
|
if (key == null) {
|
||||||
|
key = SignAPK.class.getResourceAsStream("/keys/testkey.pk8");
|
||||||
|
}
|
||||||
|
|
||||||
|
ReusableInputStream c = new ReusableInputStream(cert);
|
||||||
|
ReusableInputStream k = new ReusableInputStream(key);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(temp1))) {
|
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(temp1))) {
|
||||||
signZip(cert, key, input, out, false);
|
signZip(c, k, input, out, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZipAdjust.adjust(temp1, temp2);
|
ZipAdjust.adjust(temp1, temp2);
|
||||||
|
|
||||||
try (JarMap map = new JarMap(temp2, false)) {
|
try (JarMap map = new JarMap(temp2, false)) {
|
||||||
signZip(cert, key, map, output, true);
|
signZip(c, k, map, output, true);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
temp1.delete();
|
temp1.delete();
|
||||||
temp2.delete();
|
temp2.delete();
|
||||||
|
c.destroy();
|
||||||
|
k.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ public class ZipSigner {
|
|||||||
InputStream key = null;
|
InputStream key = null;
|
||||||
|
|
||||||
if (args.length - argStart == 4) {
|
if (args.length - argStart == 4) {
|
||||||
cert = new BufferedInputStream(new FileInputStream(new File(args[argStart])));
|
cert = new FileInputStream(new File(args[argStart]));
|
||||||
key = new BufferedInputStream(new FileInputStream(new File(args[argStart + 1])));
|
key = new FileInputStream(new File(args[argStart + 1]));
|
||||||
argStart += 2;
|
argStart += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user