# HG changeset patch # User rpatil # Date 1511320354 0 # Node ID b531b441e3c33bfb2769ff0ec6e0e2a1cc480354 # Parent f468fe7840567620a21f45874a122d5019320527 8057810: New defaults for DSA keys in jarsigner and keytool Reviewed-by: coffeys, valeriep Contributed-by: prasadarao.koppula@oracle.com diff -r f468fe784056 -r b531b441e3c3 src/share/classes/sun/security/tools/jarsigner/Main.java --- a/src/share/classes/sun/security/tools/jarsigner/Main.java Tue Nov 21 23:14:09 2017 +0000 +++ b/src/share/classes/sun/security/tools/jarsigner/Main.java Wed Nov 22 03:12:34 2017 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2517,7 +2517,7 @@ if (sigalg == null) { if (keyAlgorithm.equalsIgnoreCase("DSA")) - signatureAlgorithm = "SHA1withDSA"; + signatureAlgorithm = "SHA256withDSA"; else if (keyAlgorithm.equalsIgnoreCase("RSA")) signatureAlgorithm = "SHA256withRSA"; else if (keyAlgorithm.equalsIgnoreCase("EC")) diff -r f468fe784056 -r b531b441e3c3 src/share/classes/sun/security/tools/keytool/Main.java --- a/src/share/classes/sun/security/tools/keytool/Main.java Tue Nov 21 23:14:09 2017 +0000 +++ b/src/share/classes/sun/security/tools/keytool/Main.java Wed Nov 22 03:12:34 2017 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1596,7 +1596,7 @@ private static String getCompatibleSigAlgName(String keyAlgName) throws Exception { if ("DSA".equalsIgnoreCase(keyAlgName)) { - return "SHA1WithDSA"; + return "SHA256WithDSA"; } else if ("RSA".equalsIgnoreCase(keyAlgName)) { return "SHA256WithRSA"; } else if ("EC".equalsIgnoreCase(keyAlgName)) { diff -r f468fe784056 -r b531b441e3c3 test/sun/security/tools/jarsigner/DefaultSigalg.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/sun/security/tools/jarsigner/DefaultSigalg.java Wed Nov 22 03:12:34 2017 +0000 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8057810 + * @summary New defaults for DSA keys in jarsigner and keytool + * @compile -XDignore.symbol.file DefaultSigalg.java + */ + +import sun.security.pkcs.PKCS7; +import sun.security.util.KeyUtil; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.KeyStore; +import java.security.cert.X509Certificate; +import java.util.jar.JarFile; + +public class DefaultSigalg { + + public static void main(String[] args) throws Exception { + + // Three test cases + String[] keyalgs = {"DSA", "RSA", "EC"}; + // Expected default keytool sigalg + String[] sigalgs = {"SHA256withDSA", "SHA256withRSA", "SHA256withECDSA"}; + // Expected keysizes + int[] keysizes = {2048, 2048, 256}; + // Expected jarsigner digest alg used in signature + String[] digestalgs = {"SHA-256", "SHA-256", "SHA-256"}; + + // Create a jar file + sun.tools.jar.Main m = + new sun.tools.jar.Main(System.out, System.err, "jar"); + Files.write(Paths.get("x"), new byte[10]); + if (!m.run("cvf a.jar x".split(" "))) { + throw new Exception("jar creation failed"); + } + + // Generate keypairs and sign the jar + Files.deleteIfExists(Paths.get("jks")); + for (String keyalg: keyalgs) { + sun.security.tools.keytool.Main.main( + ("-keystore jks -storepass changeit -keypass changeit " + + "-dname CN=A -alias " + keyalg + " -genkeypair " + + "-keyalg " + keyalg).split(" ")); + sun.security.tools.jarsigner.Main.main( + ("-keystore jks -storepass changeit a.jar " + keyalg).split(" ")); + } + + // Check result + KeyStore ks = KeyStore.getInstance("JKS"); + try (FileInputStream jks = new FileInputStream("jks"); + JarFile jf = new JarFile("a.jar")) { + ks.load(jks, null); + for (int i = 0; i