author | skovalev |
Thu, 15 Sep 2016 13:03:03 +0300 | |
changeset 40975 | 680639c9b307 |
parent 39464 | f49988e2d982 |
child 44107 | a3d145e4f03c |
permissions | -rw-r--r-- |
38439 | 1 |
/* |
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 8138766 |
|
27 |
* @summary New default -sigalg for keytool |
|
28 |
* @modules java.base/sun.security.tools.keytool |
|
40975
680639c9b307
8165689: Fix module dependencies for sun/security/pkcs11/* tests
skovalev
parents:
39464
diff
changeset
|
29 |
* @modules jdk.crypto.ec |
39464
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
30 |
* @run main/othervm DefaultSignatureAlgorithm RSA 1024 SHA256withRSA |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
31 |
* @run main/othervm DefaultSignatureAlgorithm RSA 3072 SHA256withRSA |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
32 |
* @run main/othervm DefaultSignatureAlgorithm RSA 3073 SHA384withRSA |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
33 |
* @run main/othervm DefaultSignatureAlgorithm DSA 1024 SHA256withDSA |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
34 |
* @run main/othervm/timeout=700 DefaultSignatureAlgorithm DSA 3072 |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
35 |
* SHA256withDSA |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
36 |
* @run main/othervm DefaultSignatureAlgorithm EC 192 SHA256withECDSA |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
37 |
* @run main/othervm DefaultSignatureAlgorithm EC 384 SHA384withECDSA |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
38 |
* @run main/othervm DefaultSignatureAlgorithm EC 571 SHA512withECDSA |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
39 |
* @run main/othervm DefaultSignatureAlgorithm EC 571 SHA256withECDSA |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
40 |
* SHA256withECDSA |
38439 | 41 |
*/ |
42 |
||
43 |
import sun.security.tools.keytool.Main; |
|
44 |
||
45 |
import java.io.File; |
|
46 |
import java.security.KeyStore; |
|
47 |
import java.security.cert.X509Certificate; |
|
48 |
||
49 |
public class DefaultSignatureAlgorithm { |
|
50 |
||
51 |
public static void main(String[] args) throws Exception { |
|
39464
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
52 |
if(args == null || args.length < 3) { |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
53 |
throw new RuntimeException("Invalid arguments provided."); |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
54 |
} |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
55 |
String sigAlg = (args.length == 4) ? args[3] : null; |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
56 |
run(args[0], Integer.valueOf(args[1]), args[2], sigAlg); |
38439 | 57 |
} |
58 |
||
59 |
private static void run(String keyAlg, int keySize, |
|
39464
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
60 |
String expectedSigAlg, String sigAlg) throws Exception { |
f49988e2d982
8159861: sun/security/tools/keytool/DefaultSignatureAlgorithm.java timeout
ssahoo
parents:
38439
diff
changeset
|
61 |
String alias = keyAlg + keySize + System.currentTimeMillis(); |
38439 | 62 |
String cmd = "-keystore ks -storepass changeit" + |
63 |
" -keypass changeit -alias " + alias + |
|
64 |
" -keyalg " + keyAlg + " -keysize " + keySize + |
|
65 |
" -genkeypair -dname CN=" + alias + " -debug"; |
|
66 |
if (sigAlg != null) { |
|
67 |
cmd += " -sigalg " + sigAlg; |
|
68 |
} |
|
69 |
Main.main(cmd.split(" ")); |
|
70 |
||
71 |
KeyStore ks = KeyStore.getInstance( |
|
72 |
new File("ks"), "changeit".toCharArray()); |
|
73 |
X509Certificate cert = (X509Certificate)ks.getCertificate(alias); |
|
74 |
String actualSigAlg = cert.getSigAlgName(); |
|
75 |
if (!actualSigAlg.equals(expectedSigAlg)) { |
|
76 |
throw new Exception("Failure at " + alias + ": expected " |
|
77 |
+ expectedSigAlg + ", actually " + actualSigAlg); |
|
78 |
} |
|
79 |
} |
|
80 |
} |