author | weijun |
Wed, 08 Apr 2009 13:54:34 +0800 | |
changeset 2584 | a89e7cabf6fd |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
1 |
/* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
2 |
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
4 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
8 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
14 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
18 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
21 |
* have any questions. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
22 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
23 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
24 |
/* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
25 |
* read S11.sh |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
26 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
27 |
import java.io.*; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
28 |
import sun.security.util.*; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
29 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
30 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
31 |
* Test OID serialization between versions |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
32 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
33 |
* java SerialTest out oid // write a OID into System.out |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
34 |
* java SerialTest in oid // read from System.in and compare it with oid |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
35 |
* java SerialTest badin // make sure *cannot* read from System.in |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
36 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
37 |
class SerialTest { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
38 |
public static void main(String[] args) throws Exception { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
39 |
if (args[0].equals("out")) |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
40 |
out(args[1]); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
41 |
else if (args[0].equals("in")) |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
42 |
in(args[1]); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
43 |
else |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
44 |
badin(); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
45 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
46 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
47 |
static void in(String oid) throws Exception { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
48 |
ObjectIdentifier o = (ObjectIdentifier) (new ObjectInputStream(System.in).readObject()); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
49 |
if (!o.toString().equals(oid)) |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
50 |
throw new Exception("Read Fail " + o + ", not " + oid); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
51 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
52 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
53 |
static void badin() throws Exception { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
54 |
boolean pass = true; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
55 |
try { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
56 |
new ObjectInputStream(System.in).readObject(); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
57 |
} catch (Exception e) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
58 |
pass = false; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
59 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
60 |
if (pass) throw new Exception("Should fail but not"); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
61 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
62 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
63 |
static void out(String oid) throws Exception { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
64 |
new ObjectOutputStream(System.out).writeObject(new ObjectIdentifier(oid)); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
65 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
diff
changeset
|
66 |
} |