Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/pkcs11/Signature/SigInteropPSS2.java
41153 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.*;
25
import java.security.spec.*;
26
import java.security.interfaces.*;
27
28
/*
29
* @test
30
* @bug 8080462 8226651 8242332
31
* @summary testing interoperability of PSS signatures of PKCS11 provider
32
* against SunRsaSign provider
33
* @library /test/lib ..
34
* @modules jdk.crypto.cryptoki
35
* @run main/othervm SigInteropPSS2
36
*/
37
public class SigInteropPSS2 extends PKCS11Test {
38
39
private static final byte[] MSG =
40
"Interoperability test between SunRsaSign and SunPKCS11".getBytes();
41
42
private static final String[] DIGESTS = {
43
"SHA224", "SHA256", "SHA384", "SHA512",
44
"SHA3-224", "SHA3-256", "SHA3-384", "SHA3-512"
45
};
46
47
public static void main(String[] args) throws Exception {
48
main(new SigInteropPSS2(), args);
49
}
50
51
@Override
52
public void main(Provider p) throws Exception {
53
54
Signature sigPkcs11;
55
Signature sigSunRsaSign =
56
Signature.getInstance("RSASSA-PSS", "SunRsaSign");
57
58
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", p);
59
kpg.initialize(3072);
60
KeyPair kp = kpg.generateKeyPair();
61
62
for (String digest : DIGESTS) {
63
try {
64
sigPkcs11 = Signature.getInstance(digest + "withRSASSA-PSS", p);
65
} catch (NoSuchAlgorithmException e) {
66
System.out.println("Skip testing " + digest + "withRSASSA-PSS" +
67
" due to no support");
68
continue;
69
}
70
71
runTest(sigPkcs11, sigSunRsaSign, kp);
72
}
73
System.out.println("Test passed");
74
}
75
76
static void runTest(Signature signer, Signature verifier, KeyPair kp)
77
throws Exception {
78
System.out.println("\tSign: " + signer.getProvider().getName());
79
System.out.println("\tVerify: " + verifier.getProvider().getName());
80
81
signer.initSign(kp.getPrivate());
82
signer.update(MSG);
83
byte[] sigBytes = signer.sign();
84
85
AlgorithmParameters signParams = signer.getParameters();
86
verifier.setParameter(signParams.getParameterSpec
87
(PSSParameterSpec.class));
88
verifier.initVerify(kp.getPublic());
89
90
verifier.update(MSG);
91
boolean isValid = verifier.verify(sigBytes);
92
if (isValid) {
93
System.out.println("\tPSS Signature verified");
94
} else {
95
throw new RuntimeException("ERROR verifying PSS Signature");
96
}
97
}
98
}
99
100