Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/keytool/PSS.java
38853 views
1
/*
2
* Copyright (c) 2019, 2020, 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 8215694
27
* @summary keytool cannot generate RSASSA-PSS certificates
28
* @library /lib/testlibrary
29
* @run main/timeout=600 PSS
30
*/
31
32
import jdk.testlibrary.Asserts;
33
import jdk.testlibrary.security.DerUtils;
34
import sun.security.util.ObjectIdentifier;
35
import sun.security.x509.AlgorithmId;
36
37
import java.io.File;
38
import java.io.FileInputStream;
39
import java.security.KeyStore;
40
import java.security.cert.X509Certificate;
41
42
public class PSS {
43
44
public static void main(String[] args) throws Exception {
45
46
// make sure no old file exists
47
new File("ks").delete();
48
49
genkeypair("p", "-keyalg RSASSA-PSS -sigalg RSASSA-PSS");
50
genkeypair("a", "-keyalg RSA -sigalg RSASSA-PSS -keysize 2048");
51
genkeypair("b", "-keyalg RSA -sigalg RSASSA-PSS -keysize 4096");
52
genkeypair("c", "-keyalg RSA -sigalg RSASSA-PSS -keysize 8192");
53
54
//@since jdk9
55
//KeyStore ks = KeyStore.getInstance(
56
// new File("ks"), "changeit".toCharArray());
57
58
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
59
// get user password and file input stream
60
char[] password = "changeit".toCharArray();
61
try (FileInputStream fis = new FileInputStream("ks")) {
62
ks.load(fis, password);
63
}
64
65
check((X509Certificate)ks.getCertificate("p"), "RSASSA-PSS",
66
AlgorithmId.SHA256_oid);
67
68
check((X509Certificate)ks.getCertificate("a"), "RSA",
69
AlgorithmId.SHA256_oid);
70
71
check((X509Certificate)ks.getCertificate("b"), "RSA",
72
AlgorithmId.SHA384_oid);
73
74
check((X509Certificate)ks.getCertificate("c"), "RSA",
75
AlgorithmId.SHA512_oid);
76
77
// More commands
78
kt("-certreq -alias p -sigalg RSASSA-PSS -file p.req");
79
80
kt("-gencert -alias a -sigalg RSASSA-PSS -infile p.req -outfile p.cert");
81
kt("-importcert -alias p -file p.cert");
82
83
kt("-selfcert -alias p -sigalg RSASSA-PSS");
84
}
85
86
static void genkeypair(String alias, String options)
87
throws Exception {
88
kt("-genkeypair -alias " + alias
89
+ " -dname CN=" + alias + " " + options);
90
}
91
92
static void kt(String cmd) throws Exception {
93
String listStr = "-storepass changeit -keypass changeit "
94
+ "-keystore ks " + cmd;
95
sun.security.tools.keytool.Main.main(listStr.split(" "));
96
}
97
98
static void check(X509Certificate cert, String expectedKeyAlg,
99
ObjectIdentifier expectedMdAlg) throws Exception {
100
Asserts.assertEQ(cert.getPublicKey().getAlgorithm(), expectedKeyAlg);
101
Asserts.assertEQ(cert.getSigAlgName(), "RSASSA-PSS");
102
DerUtils.checkAlg(cert.getSigAlgParams(), "000", expectedMdAlg);
103
}
104
}
105
106