author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 57572 | c449f430ac3f |
permissions | -rw-r--r-- |
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
1 |
/* |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
4 |
* |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
8 |
* |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
14 |
* |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
18 |
* |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
21 |
* questions. |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
22 |
*/ |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
23 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
24 |
/* |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
25 |
* @test |
55468
076f34b82b98
8225257: sun/security/tools/keytool/PSS.java timed out
weijun
parents:
54774
diff
changeset
|
26 |
* @bug 8215694 8222987 8225257 |
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
27 |
* @summary keytool cannot generate RSASSA-PSS certificates |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
28 |
* @library /test/lib |
55468
076f34b82b98
8225257: sun/security/tools/keytool/PSS.java timed out
weijun
parents:
54774
diff
changeset
|
29 |
* @build java.base/sun.security.rsa.RSAKeyPairGenerator |
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
30 |
* @modules java.base/sun.security.util |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
31 |
* java.base/sun.security.x509 |
54774
271ee240244c
8222987: sun/security/tools/keytool/PSS.java times out on Solaris-SPARC
weijun
parents:
53351
diff
changeset
|
32 |
* @requires os.family != "solaris" |
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
33 |
* @run main PSS |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
34 |
*/ |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
35 |
|
54774
271ee240244c
8222987: sun/security/tools/keytool/PSS.java times out on Solaris-SPARC
weijun
parents:
53351
diff
changeset
|
36 |
// This test is excluded from Solaris because the 8192-bit RSA key pair |
57572
c449f430ac3f
8227595: keytool/fakegen/DefaultSignatureAlgorithm.java fails due to "exitValue = 6"
weijun
parents:
55640
diff
changeset
|
37 |
// generator is extremely slow there. Please note the fake |
c449f430ac3f
8227595: keytool/fakegen/DefaultSignatureAlgorithm.java fails due to "exitValue = 6"
weijun
parents:
55640
diff
changeset
|
38 |
// KeyPairGenerator will not be used because of provider preferences. |
54774
271ee240244c
8222987: sun/security/tools/keytool/PSS.java times out on Solaris-SPARC
weijun
parents:
53351
diff
changeset
|
39 |
|
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
40 |
import jdk.test.lib.Asserts; |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
41 |
import jdk.test.lib.SecurityTools; |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
42 |
import jdk.test.lib.process.OutputAnalyzer; |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
43 |
import jdk.test.lib.security.DerUtils; |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
44 |
import sun.security.util.ObjectIdentifier; |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
45 |
import sun.security.x509.AlgorithmId; |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
46 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
47 |
import java.io.File; |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
48 |
import java.security.KeyStore; |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
49 |
import java.security.cert.X509Certificate; |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
50 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
51 |
public class PSS { |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
52 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
53 |
public static void main(String[] args) throws Exception { |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
54 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
55 |
genkeypair("p", "-keyalg RSASSA-PSS -sigalg RSASSA-PSS") |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
56 |
.shouldHaveExitValue(0); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
57 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
58 |
genkeypair("a", "-keyalg RSA -sigalg RSASSA-PSS -keysize 2048") |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
59 |
.shouldHaveExitValue(0); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
60 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
61 |
genkeypair("b", "-keyalg RSA -sigalg RSASSA-PSS -keysize 4096") |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
62 |
.shouldHaveExitValue(0); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
63 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
64 |
genkeypair("c", "-keyalg RSA -sigalg RSASSA-PSS -keysize 8192") |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
65 |
.shouldHaveExitValue(0); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
66 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
67 |
KeyStore ks = KeyStore.getInstance( |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
68 |
new File("ks"), "changeit".toCharArray()); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
69 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
70 |
check((X509Certificate)ks.getCertificate("p"), "RSASSA-PSS", |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
71 |
AlgorithmId.SHA256_oid); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
72 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
73 |
check((X509Certificate)ks.getCertificate("a"), "RSA", |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
74 |
AlgorithmId.SHA256_oid); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
75 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
76 |
check((X509Certificate)ks.getCertificate("b"), "RSA", |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
77 |
AlgorithmId.SHA384_oid); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
78 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
79 |
check((X509Certificate)ks.getCertificate("c"), "RSA", |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
80 |
AlgorithmId.SHA512_oid); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
81 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
82 |
// More commands |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
83 |
kt("-certreq -alias p -sigalg RSASSA-PSS -file p.req") |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
84 |
.shouldHaveExitValue(0); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
85 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
86 |
kt("-gencert -alias a -sigalg RSASSA-PSS -infile p.req -outfile p.cert") |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
87 |
.shouldHaveExitValue(0); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
88 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
89 |
kt("-importcert -alias p -file p.cert") |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
90 |
.shouldHaveExitValue(0); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
91 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
92 |
kt("-selfcert -alias p -sigalg RSASSA-PSS") |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
93 |
.shouldHaveExitValue(0); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
94 |
} |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
95 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
96 |
static OutputAnalyzer genkeypair(String alias, String options) |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
97 |
throws Exception { |
55468
076f34b82b98
8225257: sun/security/tools/keytool/PSS.java timed out
weijun
parents:
54774
diff
changeset
|
98 |
String patchArg = "-J--patch-module=java.base=" + System.getProperty("test.classes") |
076f34b82b98
8225257: sun/security/tools/keytool/PSS.java timed out
weijun
parents:
54774
diff
changeset
|
99 |
+ File.separator + "patches" + File.separator + "java.base"; |
076f34b82b98
8225257: sun/security/tools/keytool/PSS.java timed out
weijun
parents:
54774
diff
changeset
|
100 |
return kt(patchArg + " -genkeypair -alias " + alias |
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
101 |
+ " -dname CN=" + alias + " " + options); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
102 |
} |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
103 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
104 |
static OutputAnalyzer kt(String cmd) |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
105 |
throws Exception { |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
106 |
return SecurityTools.keytool("-storepass changeit -keypass changeit " |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
107 |
+ "-keystore ks " + cmd); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
108 |
} |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
109 |
|
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
110 |
static void check(X509Certificate cert, String expectedKeyAlg, |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
111 |
ObjectIdentifier expectedMdAlg) throws Exception { |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
112 |
Asserts.assertEQ(cert.getPublicKey().getAlgorithm(), expectedKeyAlg); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
113 |
Asserts.assertEQ(cert.getSigAlgName(), "RSASSA-PSS"); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
114 |
DerUtils.checkAlg(cert.getSigAlgParams(), "000", expectedMdAlg); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
115 |
} |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff
changeset
|
116 |
} |