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/pkcs11/KeyPairGenerator/TestDH2048.java
38855 views
1
/*
2
* Copyright (c) 2013, 2017, 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 7196382 8072452
27
* @summary Ensure that DH key pairs can be generated for 512 - 8192 bits
28
* @author Valerie Peng
29
* @library ..
30
* @run main/othervm TestDH2048
31
* @run main/othervm TestDH2048 sm
32
*/
33
34
import java.security.InvalidParameterException;
35
import java.security.KeyPair;
36
import java.security.KeyPairGenerator;
37
import java.security.Provider;
38
39
public class TestDH2048 extends PKCS11Test {
40
41
private static void checkUnsupportedKeySize(KeyPairGenerator kpg, int ks)
42
throws Exception {
43
try {
44
kpg.initialize(ks);
45
throw new Exception("Expected IPE not thrown for " + ks);
46
} catch (InvalidParameterException ipe) {
47
}
48
}
49
50
@Override
51
public void main(Provider p) throws Exception {
52
if (p.getService("KeyPairGenerator", "DH") == null) {
53
System.out.println("KPG for DH not supported, skipping");
54
return;
55
}
56
KeyPairGenerator kpg = KeyPairGenerator.getInstance("DH", p);
57
kpg.initialize(512);
58
KeyPair kp1 = kpg.generateKeyPair();
59
60
int[] test_values = {768, 1024, 1536, 2048, 3072, 4096, 6144, 8192};
61
for (int i : test_values)
62
try {
63
kpg.initialize(i);
64
kp1 = kpg.generateKeyPair();
65
} catch (InvalidParameterException ipe) {
66
// NSS (as of version 3.13) has a hard coded maximum limit
67
// of 2236 or 3072 bits for DHE keys.
68
// SunPKCS11-Solaris has limit of 4096 on older systems
69
String prov = p.getName();
70
System.out.println(i + "-bit DH key pair generation: " + ipe);
71
if ((prov.equals("SunPKCS11-NSS") && i > 2048) ||
72
(prov.equals("SunPKCS11-Solaris") && i > 4096)) {
73
// OK
74
} else {
75
throw ipe;
76
}
77
}
78
79
// key size must be multiples of 64 though
80
checkUnsupportedKeySize(kpg, 2048 + 63);
81
checkUnsupportedKeySize(kpg, 3072 + 32);
82
}
83
84
public static void main(String[] args) throws Exception {
85
main(new TestDH2048(), args);
86
}
87
}
88
89