From 97cf15007f9f7e4e0612613bf91dd1ca2ee27012 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 23 Jan 2018 05:06:34 +0800 Subject: [PATCH] Update crypto --- app | 2 +- .../src/main/java/com/topjohnwu/crypto/SignAPK.java | 11 +++-------- .../src/main/java/com/topjohnwu/crypto/ZipSigner.java | 7 +++++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app b/app index 759e905c3..00d655f34 160000 --- a/app +++ b/app @@ -1 +1 @@ -Subproject commit 759e905c3c61018ae736e313d0272e215086f6e2 +Subproject commit 00d655f346fe6182d508d76d6b75d8e7357fcb9d diff --git a/crypto/src/main/java/com/topjohnwu/crypto/SignAPK.java b/crypto/src/main/java/com/topjohnwu/crypto/SignAPK.java index 96c2aca5a..6b980778b 100644 --- a/crypto/src/main/java/com/topjohnwu/crypto/SignAPK.java +++ b/crypto/src/main/java/com/topjohnwu/crypto/SignAPK.java @@ -70,9 +70,8 @@ public class SignAPK { } public static void signZip(InputStream publicIn, InputStream privateIn, - JarMap input, File output, boolean minSign) throws Exception { + JarMap input, OutputStream output, boolean minSign) throws Exception { int alignment = 4; - BufferedOutputStream outputFile; int hashes = 0; X509Certificate publicKey = CryptoUtils.readPublicKey(publicIn); hashes |= getDigestAlgorithm(publicKey); @@ -83,11 +82,10 @@ public class SignAPK { long timestamp = publicKey.getNotBefore().getTime() + 3600L * 1000; PrivateKey privateKey = CryptoUtils.readPrivateKey(privateIn); - outputFile = new BufferedOutputStream(new FileOutputStream(output)); if (minSign) { - signWholeFile(input.getFile(), publicKey, privateKey, outputFile); + signWholeFile(input.getFile(), publicKey, privateKey, output); } else { - JarOutputStream outputJar = new JarOutputStream(outputFile); + JarOutputStream outputJar = new JarOutputStream(output); // For signing .apks, use the maximum compression to make // them as small as possible (since they live forever on // the system partition). For OTA packages, use the @@ -98,10 +96,7 @@ public class SignAPK { Manifest manifest = addDigestsToManifest(input, hashes); copyFiles(manifest, input, outputJar, timestamp, alignment); signFile(manifest, input, publicKey, privateKey, outputJar); - outputJar.close(); } - input.close(); - outputFile.close(); } /** diff --git a/crypto/src/main/java/com/topjohnwu/crypto/ZipSigner.java b/crypto/src/main/java/com/topjohnwu/crypto/ZipSigner.java index 6b4599dbf..86be876b7 100644 --- a/crypto/src/main/java/com/topjohnwu/crypto/ZipSigner.java +++ b/crypto/src/main/java/com/topjohnwu/crypto/ZipSigner.java @@ -2,8 +2,10 @@ package com.topjohnwu.crypto; import org.bouncycastle.jce.provider.BouncyCastleProvider; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.InputStream; import java.security.Security; @@ -32,8 +34,9 @@ public class ZipSigner { try (InputStream pub = new FileInputStream(pubKey); InputStream priv = new FileInputStream(privKey); - JarMap jar = new JarMap(input, false)) { - SignAPK.signZip(pub, priv, jar, output, minSign); + JarMap jar = new JarMap(input, false); + BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(output))) { + SignAPK.signZip(pub, priv, jar, out, minSign); } catch (Exception e) { e.printStackTrace(); System.exit(1);