Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/keytool/fakegen/DefaultSignatureAlgorithm.java
41154 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 8138766 8227059 8227595
27
* @summary New default -sigalg for keytool
28
* @library /test/lib
29
* @build java.base/sun.security.rsa.RSAKeyPairGenerator
30
* java.base/sun.security.provider.DSAKeyPairGenerator
31
* jdk.crypto.ec/sun.security.ec.ECKeyPairGenerator
32
* @run main DefaultSignatureAlgorithm
33
* @modules jdk.crypto.ec
34
*/
35
36
import jdk.test.lib.Asserts;
37
import jdk.test.lib.SecurityTools;
38
import jdk.test.lib.process.OutputAnalyzer;
39
40
import java.io.File;
41
import java.security.KeyStore;
42
import java.security.cert.X509Certificate;
43
44
public class DefaultSignatureAlgorithm {
45
46
static int pos = 0;
47
48
public static void main(String[] args) throws Exception {
49
check("RSA", 1024, null, "SHA256withRSA");
50
check("RSA", 3072, null, "SHA256withRSA");
51
check("RSA", 3073, null, "SHA384withRSA");
52
check("RSA", 7680, null, "SHA384withRSA");
53
check("RSA", 7681, null, "SHA512withRSA");
54
55
check("DSA", 1024, null, "SHA256withDSA");
56
check("DSA", 3072, null, "SHA256withDSA");
57
58
check("EC", 384, null, "SHA384withECDSA");
59
60
check("EC", 384, "SHA256withECDSA", "SHA256withECDSA");
61
}
62
63
private static void check(String keyAlg, int keySize,
64
String requestedSigAlg, String expectedSigAlg)
65
throws Exception {
66
String alias = keyAlg + keySize + "-" + pos++;
67
String sigAlgParam = requestedSigAlg == null
68
? ""
69
: (" -sigalg " + requestedSigAlg);
70
genkeypair(alias,
71
"-keyalg " + keyAlg + " -keysize " + keySize + sigAlgParam)
72
.shouldHaveExitValue(0);
73
74
KeyStore ks = KeyStore.getInstance(
75
new File("ks"), "changeit".toCharArray());
76
X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
77
Asserts.assertEQ(cert.getPublicKey().getAlgorithm(), keyAlg);
78
Asserts.assertEQ(cert.getSigAlgName(), expectedSigAlg);
79
}
80
81
static OutputAnalyzer genkeypair(String alias, String options)
82
throws Exception {
83
String patchArg = "-J--patch-module=java.base="
84
+ System.getProperty("test.classes")
85
+ File.separator + "patches" + File.separator + "java.base"
86
+ " -J--patch-module=jdk.crypto.ec="
87
+ System.getProperty("test.classes")
88
+ File.separator + "patches" + File.separator + "jdk.crypto.ec";
89
return kt(patchArg + " -genkeypair -alias " + alias
90
+ " -dname CN=" + alias + " " + options);
91
}
92
93
static OutputAnalyzer kt(String cmd)
94
throws Exception {
95
return SecurityTools.keytool("-storepass changeit -keypass changeit "
96
+ "-keystore ks " + cmd);
97
}
98
}
99
100