# HG changeset patch # User sdrach # Date 1454003340 28800 # Node ID 725d738b0ead6b8899352d2ed10479834a536d52 # Parent 30e7774e9190f25ee528364f8d37eb3e4e1f4413 8147607: Remove test library dependency on sun.security.tools.jarsigner.Main Reviewed-by: chegar, psandoz Contributed-by: steve.drach@oracle.com diff -r 30e7774e9190 -r 725d738b0ead jdk/test/lib/testlibrary/java/util/jar/CreateMultiReleaseTestJars.java --- a/jdk/test/lib/testlibrary/java/util/jar/CreateMultiReleaseTestJars.java Thu Jan 28 18:08:53 2016 -0800 +++ b/jdk/test/lib/testlibrary/java/util/jar/CreateMultiReleaseTestJars.java Thu Jan 28 09:49:00 2016 -0800 @@ -21,12 +21,21 @@ * questions. */ +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.security.KeyStore; +import java.security.PrivateKey; +import java.security.cert.CertPath; +import java.security.cert.CertificateFactory; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.zip.ZipFile; +import jdk.security.jarsigner.JarSigner; public class CreateMultiReleaseTestJars { final private String main = @@ -120,14 +129,21 @@ String testsrc = System.getProperty("test.src","."); String testdir = findTestDir(testsrc); String keystore = testdir + "/sun/security/tools/jarsigner/JarSigning.keystore"; - String[] jsArgs = { - "-keystore", keystore, - "-storepass", "bbbbbb", - "-signedJar", "signed-multi-release.jar", - "multi-release.jar", "b" - }; - sun.security.tools.jarsigner.Main.main(jsArgs); + + // jarsigner -keystore keystore -storepass "bbbbbb" + // -signedJar signed-multi-release.jar multi-release.jar b + char[] password = "bbbbbb".toCharArray(); + KeyStore ks = KeyStore.getInstance(new File(keystore), password); + PrivateKey pkb = (PrivateKey)ks.getKey("b", password); + CertPath cp = CertificateFactory.getInstance("X.509") + .generateCertPath(Arrays.asList(ks.getCertificateChain("b"))); + JarSigner js = new JarSigner.Builder(pkb, cp).build(); + try (ZipFile in = new ZipFile("multi-release.jar"); + FileOutputStream os = new FileOutputStream("signed-multi-release.jar")) + { + js.sign(in, os); + } } String findTestDir(String dir) throws IOException {