Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/util/Oid/S11N.java
41152 views
1
/*
2
* Copyright (c) 2013, 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 4811968 6908628 8006564 8130696 8242151
27
* @modules java.base/sun.security.util
28
* @run main S11N check
29
* @summary Serialization compatibility with old versions (and fixes)
30
*/
31
32
import java.io.ByteArrayInputStream;
33
import java.io.ByteArrayOutputStream;
34
import java.io.ObjectInputStream;
35
import java.io.ObjectOutputStream;
36
import java.util.HashMap;
37
import java.util.Map;
38
import sun.security.util.ObjectIdentifier;
39
40
public class S11N {
41
static String[] SMALL= {
42
"0.0",
43
"1.1",
44
"2.2",
45
"1.2.3456",
46
"1.2.2147483647.4",
47
"1.2.268435456.4",
48
};
49
50
static String[] HUGE = {
51
"2.16.764.1.3101555394.1.0.100.2.1",
52
"1.2.2147483648.4",
53
"2.3.4444444444444444444444",
54
"1.2.8888888888888888.33333333333333333.44444444444444",
55
};
56
57
public static void main(String[] args) throws Exception {
58
if (args[0].equals("check")) {
59
String jv = System.getProperty("java.version");
60
// java.version format: $VNUM\-$PRE
61
String [] va = (jv.split("-")[0]).split("\\.");
62
String v = (va.length == 1 || !va[0].equals("1")) ? va[0] : va[1];
63
int version = Integer.valueOf(v);
64
System.out.println("version is " + version);
65
if (version >= 7) {
66
for (String oid: SMALL) {
67
// 7 -> 7
68
check(out(oid), oid);
69
// 6 -> 7
70
check(out6(oid), oid);
71
}
72
for (String oid: HUGE) {
73
// 7 -> 7
74
check(out(oid), oid);
75
}
76
} else {
77
for (String oid: SMALL) {
78
// 6 -> 6
79
check(out(oid), oid);
80
// 7 -> 6
81
check(out7(oid), oid);
82
}
83
for (String oid: HUGE) {
84
// 7 -> 6 fails for HUGE oids
85
boolean ok = false;
86
try {
87
check(out7(oid), oid);
88
ok = true;
89
} catch (Exception e) {
90
System.out.println(e);
91
}
92
if (ok) {
93
throw new Exception();
94
}
95
}
96
}
97
} else {
98
// Generates the JDK6 serialized string inside this test, call
99
// $JDK7/bin/java S11N dump7
100
// $JDK6/bin/java S11N dump6
101
// and paste the output at the end of this test.
102
dump(args[0], SMALL);
103
// For jdk6, the following line will throw an exception, ignore it
104
dump(args[0], HUGE);
105
}
106
}
107
108
// Gets the serialized form for jdk6
109
private static byte[] out6(String oid) throws Exception {
110
return decode(dump6.get(oid));
111
}
112
113
// Gets the serialized form for jdk7
114
private static byte[] out7(String oid) throws Exception {
115
return decode(dump7.get(oid));
116
}
117
118
// Gets the serialized form for this java
119
private static byte[] out(String oid) throws Exception {
120
ByteArrayOutputStream bout = new ByteArrayOutputStream();
121
new ObjectOutputStream(bout).writeObject(ObjectIdentifier.of(oid));
122
return bout.toByteArray();
123
}
124
125
// Makes sure serialized form can be deserialized
126
private static void check(byte[] in, String oid) throws Exception {
127
ObjectIdentifier o = (ObjectIdentifier) (
128
new ObjectInputStream(new ByteArrayInputStream(in)).readObject());
129
if (!o.toString().equals(oid)) {
130
throw new Exception("Read Fail " + o + ", not " + oid);
131
}
132
}
133
134
// dump serialized form to java code style text
135
private static void dump(String title, String[] oids) throws Exception {
136
for (String oid: oids) {
137
String hex = encode(out(oid));
138
System.out.println(" " + title + ".put(\"" + oid + "\",");
139
for (int i = 0; i<hex.length(); i+= 64) {
140
int end = i + 64;
141
if (end > hex.length()) {
142
end = hex.length();
143
}
144
System.out.print(" \"" + hex.substring(i, end) + "\"");
145
if (end == hex.length()) {
146
System.out.println(");");
147
} else {
148
System.out.println(" +");
149
}
150
}
151
}
152
}
153
154
private static String encode(byte[] bytes) {
155
StringBuilder sb = new StringBuilder(bytes.length * 2);
156
for (byte b: bytes) {
157
sb.append(String.format("%02x", b & 0xff));
158
}
159
return sb.toString();
160
}
161
162
private static byte[] decode(String var) {
163
byte[] data = new byte[var.length()/2];
164
for (int i=0; i<data.length; i++) {
165
data[i] = Integer.valueOf(var.substring(2 * i, 2 * i + 2), 16).byteValue();
166
}
167
return data;
168
}
169
170
// Do not use diamond operator, this test is also meant to run in jdk6
171
private static Map<String,String> dump7 = new HashMap<String,String>();
172
private static Map<String,String> dump6 = new HashMap<String,String>();
173
174
static {
175
////////////// PASTE BEGIN //////////////
176
dump7.put("0.0",
177
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
178
"4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" +
179
"744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" +
180
"626a6563743b5b0008656e636f64696e677400025b4278700000000275720002" +
181
"5b494dba602676eab2a50200007870000000020000000000000000757200025b" +
182
"42acf317f8060854e00200007870000000010078");
183
dump7.put("1.1",
184
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
185
"4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" +
186
"744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" +
187
"626a6563743b5b0008656e636f64696e677400025b4278700000000275720002" +
188
"5b494dba602676eab2a50200007870000000020000000100000001757200025b" +
189
"42acf317f8060854e00200007870000000012978");
190
dump7.put("2.2",
191
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
192
"4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" +
193
"744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" +
194
"626a6563743b5b0008656e636f64696e677400025b4278700000000275720002" +
195
"5b494dba602676eab2a50200007870000000020000000200000002757200025b" +
196
"42acf317f8060854e00200007870000000015278");
197
dump7.put("1.2.3456",
198
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
199
"4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" +
200
"744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" +
201
"626a6563743b5b0008656e636f64696e677400025b4278700000000375720002" +
202
"5b494dba602676eab2a5020000787000000003000000010000000200000d8075" +
203
"7200025b42acf317f8060854e00200007870000000032a9b0078");
204
dump7.put("1.2.2147483647.4",
205
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
206
"4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" +
207
"744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" +
208
"626a6563743b5b0008656e636f64696e677400025b4278700000000475720002" +
209
"5b494dba602676eab2a502000078700000000400000001000000027fffffff00" +
210
"000004757200025b42acf317f8060854e00200007870000000072a87ffffff7f" +
211
"0478");
212
dump7.put("1.2.268435456.4",
213
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
214
"4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" +
215
"744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" +
216
"626a6563743b5b0008656e636f64696e677400025b4278700000000475720002" +
217
"5b494dba602676eab2a502000078700000000400000001000000021000000000" +
218
"000004757200025b42acf317f8060854e00200007870000000072a8180808000" +
219
"0478");
220
dump7.put("2.16.764.1.3101555394.1.0.100.2.1",
221
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
222
"4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" +
223
"744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" +
224
"626a6563743b5b0008656e636f64696e677400025b427870ffffffff7372003e" +
225
"73756e2e73656375726974792e7574696c2e4f626a6563744964656e74696669" +
226
"657224487567654f69644e6f74537570706f7274656442794f6c644a444b0000" +
227
"0000000000010200007870757200025b42acf317f8060854e002000078700000" +
228
"000e60857c018bc6f7f542010064020178");
229
dump7.put("1.2.2147483648.4",
230
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
231
"4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" +
232
"744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" +
233
"626a6563743b5b0008656e636f64696e677400025b427870ffffffff7372003e" +
234
"73756e2e73656375726974792e7574696c2e4f626a6563744964656e74696669" +
235
"657224487567654f69644e6f74537570706f7274656442794f6c644a444b0000" +
236
"0000000000010200007870757200025b42acf317f8060854e002000078700000" +
237
"00072a88808080000478");
238
dump7.put("2.3.4444444444444444444444",
239
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
240
"4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" +
241
"744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" +
242
"626a6563743b5b0008656e636f64696e677400025b427870ffffffff7372003e" +
243
"73756e2e73656375726974792e7574696c2e4f626a6563744964656e74696669" +
244
"657224487567654f69644e6f74537570706f7274656442794f6c644a444b0000" +
245
"0000000000010200007870757200025b42acf317f8060854e002000078700000" +
246
"000c5383e1ef87a4d1bdebc78e1c78");
247
dump7.put("1.2.8888888888888888.33333333333333333.44444444444444",
248
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
249
"4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" +
250
"744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" +
251
"626a6563743b5b0008656e636f64696e677400025b427870ffffffff7372003e" +
252
"73756e2e73656375726974792e7574696c2e4f626a6563744964656e74696669" +
253
"657224487567654f69644e6f74537570706f7274656442794f6c644a444b0000" +
254
"0000000000010200007870757200025b42acf317f8060854e002000078700000" +
255
"00182a8fe58cdbc5ae9c38bb9b8fd7a48daa558a8dc0bacb8e1c78");
256
257
dump6.put("0.0",
258
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
259
"4964656e74696669657278b20eec64177f2e02000249000c636f6d706f6e656e" +
260
"744c656e5b000a636f6d706f6e656e74737400025b4978700000000275720002" +
261
"5b494dba602676eab2a50200007870000000020000000000000000");
262
dump6.put("1.1",
263
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
264
"4964656e74696669657278b20eec64177f2e02000249000c636f6d706f6e656e" +
265
"744c656e5b000a636f6d706f6e656e74737400025b4978700000000275720002" +
266
"5b494dba602676eab2a50200007870000000020000000100000001");
267
dump6.put("2.2",
268
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
269
"4964656e74696669657278b20eec64177f2e02000249000c636f6d706f6e656e" +
270
"744c656e5b000a636f6d706f6e656e74737400025b4978700000000275720002" +
271
"5b494dba602676eab2a50200007870000000020000000200000002");
272
dump6.put("1.2.3456",
273
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
274
"4964656e74696669657278b20eec64177f2e02000249000c636f6d706f6e656e" +
275
"744c656e5b000a636f6d706f6e656e74737400025b4978700000000375720002" +
276
"5b494dba602676eab2a5020000787000000003000000010000000200000d80");
277
dump6.put("1.2.2147483647.4",
278
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
279
"4964656e74696669657278b20eec64177f2e02000249000c636f6d706f6e656e" +
280
"744c656e5b000a636f6d706f6e656e74737400025b4978700000000475720002" +
281
"5b494dba602676eab2a502000078700000000400000001000000027fffffff00" +
282
"000004");
283
dump6.put("1.2.268435456.4",
284
"aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" +
285
"4964656e74696669657278b20eec64177f2e02000249000c636f6d706f6e656e" +
286
"744c656e5b000a636f6d706f6e656e74737400025b4978700000000475720002" +
287
"5b494dba602676eab2a502000078700000000400000001000000021000000000" +
288
"000004");
289
290
////////////// PASTE END //////////////
291
}
292
}
293
294