Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/rsa/TestRSAOidSupport.java
41149 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
/**
25
* @test
26
* @bug 8242897
27
* @summary Ensure that RSA key factory can parse X.509 encodings containing
28
* non-standard RSA oid as in older JDK releases before JDK-8146293
29
* @run main TestRSAOidSupport
30
*/
31
32
import java.security.KeyFactory;
33
import java.security.interfaces.RSAPublicKey;
34
import java.security.spec.X509EncodedKeySpec;
35
import java.security.spec.InvalidKeySpecException;
36
37
public class TestRSAOidSupport {
38
39
// SubjectKeyInfo DER encoding w/ Algorithm id 1.3.14.3.2.15
40
// which can be used to generate RSA Public Key before PSS
41
// support is added
42
private static String DER_BYTES =
43
"3058300906052b0e03020f0500034b003048024100d7157c65e8f22557d8" +
44
"a857122cfe85bddfaba3064c21b345e2a7cdd8a6751e519ab861c5109fb8" +
45
"8cce45d161b9817bc0eccdc30fda69e62cc577775f2c1d66bd0203010001";
46
47
// utility method for converting hex string to byte array
48
static byte[] toByteArray(String s) {
49
byte[] bytes = new byte[s.length() / 2];
50
for (int i = 0; i < bytes.length; i++) {
51
int index = i * 2;
52
int v = Integer.parseInt(s.substring(index, index + 2), 16);
53
bytes[i] = (byte) v;
54
}
55
return bytes;
56
}
57
58
public static void main(String[] args) throws Exception {
59
X509EncodedKeySpec x509Spec = new X509EncodedKeySpec
60
(toByteArray(DER_BYTES));
61
String keyAlgo = "RSA";
62
KeyFactory kf = KeyFactory.getInstance(keyAlgo, "SunRsaSign");
63
RSAPublicKey rsaKey = (RSAPublicKey) kf.generatePublic(x509Spec);
64
65
if (rsaKey.getAlgorithm() != keyAlgo) {
66
throw new RuntimeException("Key algo should be " + keyAlgo +
67
", but got " + rsaKey.getAlgorithm());
68
}
69
kf = KeyFactory.getInstance("RSASSA-PSS", "SunRsaSign");
70
try {
71
kf.generatePublic(x509Spec);
72
throw new RuntimeException("Should throw IKSE");
73
} catch (InvalidKeySpecException ikse) {
74
System.out.println("Expected IKSE exception thrown");
75
}
76
}
77
}
78
79
80