2018-01-27 01:34:40 +01:00
|
|
|
package com.topjohnwu.utils;
|
2017-12-04 08:16:41 +01:00
|
|
|
|
|
|
|
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
|
|
|
|
2018-01-26 17:19:35 +01:00
|
|
|
import java.io.BufferedInputStream;
|
2018-01-22 22:06:34 +01:00
|
|
|
import java.io.BufferedOutputStream;
|
2017-12-04 08:16:41 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
2018-01-22 22:06:34 +01:00
|
|
|
import java.io.FileOutputStream;
|
2017-12-04 08:16:41 +01:00
|
|
|
import java.io.InputStream;
|
|
|
|
import java.security.Security;
|
|
|
|
|
|
|
|
public class ZipSigner {
|
2018-01-26 17:19:35 +01:00
|
|
|
|
|
|
|
public static void usage() {
|
2018-01-27 01:25:34 +01:00
|
|
|
System.err.println("Usage: zipsigner [x509.pem] [pk8] input.jar output.jar");
|
|
|
|
System.err.println("Note: If no certificate/private key pair is specified, it will use the embedded test keys.");
|
2018-01-26 17:19:35 +01:00
|
|
|
System.exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
2017-12-04 08:16:41 +01:00
|
|
|
int argStart = 0;
|
|
|
|
|
2018-01-26 17:19:35 +01:00
|
|
|
if (args.length < 2)
|
|
|
|
usage();
|
2017-12-04 08:16:41 +01:00
|
|
|
|
2018-01-26 17:19:35 +01:00
|
|
|
InputStream cert = null;
|
|
|
|
InputStream key = null;
|
|
|
|
|
|
|
|
if (args.length - argStart == 4) {
|
2018-05-20 09:24:47 +02:00
|
|
|
cert = new FileInputStream(new File(args[argStart]));
|
|
|
|
key = new FileInputStream(new File(args[argStart + 1]));
|
2018-01-26 17:19:35 +01:00
|
|
|
argStart += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length - argStart != 2)
|
|
|
|
usage();
|
|
|
|
|
2017-12-04 08:16:41 +01:00
|
|
|
SignAPK.sBouncyCastleProvider = new BouncyCastleProvider();
|
|
|
|
Security.insertProviderAt(SignAPK.sBouncyCastleProvider, 1);
|
|
|
|
|
2018-01-26 17:19:35 +01:00
|
|
|
File input = new File(args[argStart]);
|
|
|
|
File output = new File(args[argStart + 1]);
|
2017-12-04 08:16:41 +01:00
|
|
|
|
2018-01-26 17:19:35 +01:00
|
|
|
try (JarMap jar = new JarMap(input, false);
|
2018-01-22 22:06:34 +01:00
|
|
|
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(output))) {
|
2018-01-27 01:25:34 +01:00
|
|
|
SignAPK.signZip(cert, key, jar, out);
|
2017-12-04 08:16:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|