Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ec/ed/EdCRLSign.java
41152 views
1
/*
2
* Copyright (c) 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
import java.security.KeyPair;
25
import java.security.KeyPairGenerator;
26
import java.security.SecureRandom;
27
import java.security.spec.NamedParameterSpec;
28
import java.util.Date;
29
import sun.security.x509.X500Name;
30
import sun.security.x509.X509CRLImpl;
31
32
/*
33
* @test
34
* @bug 8209632
35
* @summary CRL Sign
36
* @modules java.base/sun.security.x509
37
* @run main EdCRLSign
38
*/
39
public class EdCRLSign {
40
41
private static final String ED25519 = "Ed25519";
42
private static final String ED448 = "Ed448";
43
private static final String OIDN25519 = "1.3.101.112";
44
private static final String OID25519 = "OID.1.3.101.112";
45
private static final String OIDN448 = "1.3.101.113";
46
private static final String OID448 = "OID.1.3.101.113";
47
private static final String PROVIDER = "SunEC";
48
private static final SecureRandom S_RND = new SecureRandom(new byte[]{0x1});
49
50
public static void main(String[] args) throws Exception {
51
52
for (boolean initWithRandom : new boolean[]{true, false}) {
53
// Default Parameter
54
test(PROVIDER, ED25519, null, initWithRandom);
55
test(PROVIDER, ED448, null, initWithRandom);
56
57
// With named parameter
58
test(PROVIDER, ED25519, ED25519, initWithRandom);
59
test(PROVIDER, OIDN25519, ED25519, initWithRandom);
60
test(PROVIDER, OID25519, ED25519, initWithRandom);
61
test(PROVIDER, ED448, ED448, initWithRandom);
62
test(PROVIDER, OIDN448, ED448, initWithRandom);
63
test(PROVIDER, OID448, ED448, initWithRandom);
64
65
// With size parameter
66
test(PROVIDER, ED25519, 255, initWithRandom);
67
test(PROVIDER, OIDN25519, 255, initWithRandom);
68
test(PROVIDER, OID25519, 255, initWithRandom);
69
test(PROVIDER, ED448, 448, initWithRandom);
70
test(PROVIDER, OIDN448, 448, initWithRandom);
71
test(PROVIDER, OID448, 448, initWithRandom);
72
}
73
}
74
75
// Test CRL signature using a KeyPair.
76
private static void test(String provider, String name, Object param,
77
boolean initWithRandom) throws Exception {
78
79
System.out.printf("Case Algo:%s, Param:%s, Intitiate with random:%s%n",
80
name, param, initWithRandom);
81
KeyPair kp = genKeyPair(provider, name, param, initWithRandom);
82
X509CRLImpl crl = new X509CRLImpl(
83
new X500Name("CN=Issuer"), new Date(), new Date());
84
crl.sign(kp.getPrivate(), name);
85
crl.verify(kp.getPublic());
86
System.out.println("Passed.");
87
}
88
89
private static KeyPair genKeyPair(String provider, String name,
90
Object param, boolean initWithRandom) throws Exception {
91
92
KeyPairGenerator kpg = KeyPairGenerator.getInstance(name, provider);
93
if (initWithRandom) {
94
if (param instanceof Integer) {
95
kpg.initialize((Integer) param, S_RND);
96
} else if (param instanceof String) {
97
kpg.initialize(new NamedParameterSpec((String) param), S_RND);
98
}
99
} else {
100
if (param instanceof Integer) {
101
kpg.initialize((Integer) param);
102
} else if (param instanceof String) {
103
kpg.initialize(new NamedParameterSpec((String) param));
104
}
105
}
106
return kpg.generateKeyPair();
107
}
108
109
}
110
111