Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/util/Oid/OidFormat.java
41152 views
1
/*
2
* Copyright (c) 2006, 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
* @author Weijun Wang
27
* @bug 6418422 6418425 6418433 8242151
28
* @summary ObjectIdentifier should reject 1.2.3.-4 and throw IOException on all format errors
29
* @modules java.base/sun.security.util
30
* java.security.jgss
31
*/
32
33
import java.io.IOException;
34
import java.security.NoSuchAlgorithmException;
35
import org.ietf.jgss.GSSException;
36
import org.ietf.jgss.Oid;
37
import javax.crypto.EncryptedPrivateKeyInfo;
38
import sun.security.util.*;
39
import java.util.Arrays;
40
41
public class OidFormat {
42
public static void main(String[] args) throws Exception {
43
String[] badOids = {
44
// number problems
45
"0", "1", "2",
46
"3.1.1", "3", "4",
47
"1.40", "1.111.1",
48
"-1.2", "0,-2", "1.-2", "2.-2",
49
"1.2.-3.4", "1.2.3.-4",
50
// format problems
51
"aa", "aa.aa",
52
"", "....", "1.2..4", "1.2.3.", "1.", "1.2.", "0.1.",
53
"1,2",
54
};
55
56
for (String s: badOids) {
57
testBad(s);
58
}
59
60
String[] goodOids = {
61
"0.0", "0.1", "1.0", "1.2",
62
"0.39", "1.39", "2.47", "2.40.3.6", "2.100.3", "2.123456.3",
63
"1.2.3", "1.2.3445",
64
"1.3.6.1.4.1.42.2.17",
65
// 4811968: ASN.1 cannot handle huge OID components
66
"2.16.764.1.3101555394.1.0.100.2.1",
67
"2.2726957624935694386592435", // as huge as possible
68
"1.2.777777777777777777",
69
"1.2.888888888888888888.111111111111111.2222222222222.33333333333333333.44444444444444",
70
"1.2." +
71
"1111111111111111111111111111111111111111111111111111111111111." +
72
"2222222222222222222222222222222222222222222222222222222222222222." +
73
"333333333333333333333333333333333333333333333333333333333333333." +
74
"4444444444444444444444444444444444444444444444444444444." +
75
"55555555555555555555555555555555555555555555555555555555555555555555555." +
76
"666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666." +
77
"77777777777777777777777777777777777777777777777777777777777777777777777777." +
78
"8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888." +
79
"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
80
"1.2.2147483647.4",
81
"1.2.268435456.4",
82
};
83
84
for (String s: goodOids) {
85
testGood(s);
86
}
87
}
88
89
static void testGood(String s) throws Exception {
90
System.err.println("Trying " + s);
91
ObjectIdentifier oid = ObjectIdentifier.of(s);
92
if (!oid.toString().equals(s)) {
93
throw new Exception("equal test fail");
94
}
95
DerOutputStream os = new DerOutputStream();
96
os.putOID(oid);
97
DerInputStream is = new DerInputStream(os.toByteArray());
98
ObjectIdentifier oid2 = is.getOID();
99
if (!oid.equals(oid2)) {
100
throw new Exception("Test DER I/O fails: " + oid + " and " + oid2);
101
}
102
}
103
104
static void testBad(String s) throws Exception {
105
System.err.println("Trying " + s);
106
try {
107
ObjectIdentifier.of(s);
108
throw new Exception("should be invalid ObjectIdentifier");
109
} catch (IOException ioe) {
110
System.err.println(ioe);
111
}
112
113
try {
114
new Oid(s);
115
throw new Exception("should be invalid Oid");
116
} catch (GSSException gsse) {
117
;
118
}
119
120
try {
121
new EncryptedPrivateKeyInfo(s, new byte[8]);
122
throw new Exception("should be invalid algorithm");
123
} catch (NoSuchAlgorithmException e) {
124
;
125
}
126
}
127
}
128
129