author | juh |
Mon, 29 Jun 2015 16:36:44 -0700 | |
changeset 31426 | 9cd672654f97 |
parent 25859 | 3317bb8137f4 |
child 31538 | 0981099a3e54 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
31426
9cd672654f97
8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.util; |
|
27 |
||
28 |
import java.io.*; |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
29 |
import java.math.BigInteger; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
30 |
import java.util.Arrays; |
2 | 31 |
|
32 |
/** |
|
33 |
* Represent an ISO Object Identifier. |
|
34 |
* |
|
35 |
* <P>Object Identifiers are arbitrary length hierarchical identifiers. |
|
36 |
* The individual components are numbers, and they define paths from the |
|
37 |
* root of an ISO-managed identifier space. You will sometimes see a |
|
38 |
* string name used instead of (or in addition to) the numerical id. |
|
39 |
* These are synonyms for the numerical IDs, but are not widely used |
|
40 |
* since most sites do not know all the requisite strings, while all |
|
41 |
* sites can parse the numeric forms. |
|
42 |
* |
|
43 |
* <P>So for example, JavaSoft has the sole authority to assign the |
|
44 |
* meaning to identifiers below the 1.3.6.1.4.1.42.2.17 node in the |
|
45 |
* hierarchy, and other organizations can easily acquire the ability |
|
46 |
* to assign such unique identifiers. |
|
47 |
* |
|
48 |
* @author David Brownell |
|
49 |
* @author Amit Kapoor |
|
50 |
* @author Hemma Prafullchandra |
|
51 |
*/ |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
52 |
|
2 | 53 |
final public |
54 |
class ObjectIdentifier implements Serializable |
|
55 |
{ |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
56 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
57 |
* We use the DER value (no tag, no length) as the internal format |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
58 |
* @serial |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
59 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
60 |
private byte[] encoding = null; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
61 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
62 |
private transient volatile String stringForm; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
63 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
64 |
/* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
65 |
* IMPORTANT NOTES FOR CODE CHANGES (bug 4811968) IN JDK 1.7.0 |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
66 |
* =========================================================== |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
67 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
68 |
* (Almost) serialization compatibility with old versions: |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
69 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
70 |
* serialVersionUID is unchanged. Old field "component" is changed to |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
71 |
* type Object so that "poison" (unknown object type for old versions) |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
72 |
* can be put inside if there are huge components that cannot be saved |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
73 |
* as integers. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
74 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
75 |
* New version use the new filed "encoding" only. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
76 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
77 |
* Below are all 4 cases in a serialization/deserialization process: |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
78 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
79 |
* 1. old -> old: Not covered here |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
80 |
* 2. old -> new: There's no "encoding" field, new readObject() reads |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
81 |
* "components" and "componentLen" instead and inits correctly. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
82 |
* 3. new -> new: "encoding" field exists, new readObject() uses it |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
83 |
* (ignoring the other 2 fields) and inits correctly. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
84 |
* 4. new -> old: old readObject() only recognizes "components" and |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
85 |
* "componentLen" fields. If no huge components are involved, they |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
86 |
* are serialized as legal values and old object can init correctly. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
87 |
* Otherwise, old object cannot recognize the form (component not int[]) |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
88 |
* and throw a ClassNotFoundException at deserialization time. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
89 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
90 |
* Therfore, for the first 3 cases, exact compatibility is preserved. In |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
91 |
* the 4th case, non-huge OID is still supportable in old versions, while |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
92 |
* huge OID is not. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
93 |
*/ |
2 | 94 |
private static final long serialVersionUID = 8697030238860181294L; |
95 |
||
96 |
/** |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
97 |
* Changed to Object |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
98 |
* @serial |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
99 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
100 |
private Object components = null; // path from root |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
101 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
102 |
* @serial |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
103 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
104 |
private int componentLen = -1; // how much is used. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
105 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
106 |
// Is the components field calculated? |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
107 |
transient private boolean componentsCalculated = false; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
108 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
109 |
private void readObject(ObjectInputStream is) |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
110 |
throws IOException, ClassNotFoundException { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
111 |
is.defaultReadObject(); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
112 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
113 |
if (encoding == null) { // from an old version |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
114 |
init((int[])components, componentLen); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
115 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
116 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
117 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
118 |
private void writeObject(ObjectOutputStream os) |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
119 |
throws IOException { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
120 |
if (!componentsCalculated) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
121 |
int[] comps = toIntArray(); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
122 |
if (comps != null) { // every one understands this |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
123 |
components = comps; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
124 |
componentLen = comps.length; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
125 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
126 |
components = HugeOidNotSupportedByOldJDK.theOne; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
127 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
128 |
componentsCalculated = true; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
129 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
130 |
os.defaultWriteObject(); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
131 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
132 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
133 |
static class HugeOidNotSupportedByOldJDK implements Serializable { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
134 |
private static final long serialVersionUID = 1L; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
135 |
static HugeOidNotSupportedByOldJDK theOne = new HugeOidNotSupportedByOldJDK(); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
136 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
137 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
138 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
139 |
* Constructs, from a string. This string should be of the form 1.23.56. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
140 |
* Validity check included. |
2 | 141 |
*/ |
142 |
public ObjectIdentifier (String oid) throws IOException |
|
143 |
{ |
|
144 |
int ch = '.'; |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
145 |
int start = 0; |
2 | 146 |
int end = 0; |
147 |
||
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
148 |
int pos = 0; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
149 |
byte[] tmp = new byte[oid.length()]; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
150 |
int first = 0, second; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
151 |
int count = 0; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
152 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
153 |
try { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
154 |
String comp = null; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
155 |
do { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
156 |
int length = 0; // length of one section |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
157 |
end = oid.indexOf(ch,start); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
158 |
if (end == -1) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
159 |
comp = oid.substring(start); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
160 |
length = oid.length() - start; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
161 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
162 |
comp = oid.substring(start,end); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
163 |
length = end - start; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
164 |
} |
2 | 165 |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
166 |
if (length > 9) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
167 |
BigInteger bignum = new BigInteger(comp); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
168 |
if (count == 0) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
169 |
checkFirstComponent(bignum); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
170 |
first = bignum.intValue(); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
171 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
172 |
if (count == 1) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
173 |
checkSecondComponent(first, bignum); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
174 |
bignum = bignum.add(BigInteger.valueOf(40*first)); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
175 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
176 |
checkOtherComponent(count, bignum); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
177 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
178 |
pos += pack7Oid(bignum, tmp, pos); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
179 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
180 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
181 |
int num = Integer.parseInt(comp); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
182 |
if (count == 0) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
183 |
checkFirstComponent(num); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
184 |
first = num; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
185 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
186 |
if (count == 1) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
187 |
checkSecondComponent(first, num); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
188 |
num += 40 * first; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
189 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
190 |
checkOtherComponent(count, num); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
191 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
192 |
pos += pack7Oid(num, tmp, pos); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
193 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
194 |
} |
2 | 195 |
start = end + 1; |
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
196 |
count++; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
197 |
} while (end != -1); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
198 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
199 |
checkCount(count); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
200 |
encoding = new byte[pos]; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
201 |
System.arraycopy(tmp, 0, encoding, 0, pos); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
202 |
this.stringForm = oid; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
203 |
} catch (IOException ioe) { // already detected by checkXXX |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
204 |
throw ioe; |
2 | 205 |
} catch (Exception e) { |
206 |
throw new IOException("ObjectIdentifier() -- Invalid format: " |
|
207 |
+ e.toString(), e); |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
/** |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
212 |
* Constructor, from an array of integers. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
213 |
* Validity check included. |
2 | 214 |
*/ |
215 |
public ObjectIdentifier (int values []) throws IOException |
|
216 |
{ |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
217 |
checkCount(values.length); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
218 |
checkFirstComponent(values[0]); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
219 |
checkSecondComponent(values[0], values[1]); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
220 |
for (int i=2; i<values.length; i++) |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
221 |
checkOtherComponent(i, values[i]); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
222 |
init(values, values.length); |
2 | 223 |
} |
224 |
||
225 |
/** |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
226 |
* Constructor, from an ASN.1 encoded input stream. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
227 |
* Validity check NOT included. |
2 | 228 |
* The encoding of the ID in the stream uses "DER", a BER/1 subset. |
229 |
* In this case, that means a triple { typeId, length, data }. |
|
230 |
* |
|
231 |
* <P><STRONG>NOTE:</STRONG> When an exception is thrown, the |
|
232 |
* input stream has not been returned to its "initial" state. |
|
233 |
* |
|
234 |
* @param in DER-encoded data holding an object ID |
|
235 |
* @exception IOException indicates a decoding error |
|
236 |
*/ |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
237 |
public ObjectIdentifier (DerInputStream in) throws IOException |
2 | 238 |
{ |
239 |
byte type_id; |
|
240 |
int bufferEnd; |
|
241 |
||
242 |
/* |
|
243 |
* Object IDs are a "universal" type, and their tag needs only |
|
244 |
* one byte of encoding. Verify that the tag of this datum |
|
245 |
* is that of an object ID. |
|
246 |
* |
|
247 |
* Then get and check the length of the ID's encoding. We set |
|
248 |
* up so that we can use in.available() to check for the end of |
|
249 |
* this value in the data stream. |
|
250 |
*/ |
|
251 |
type_id = (byte) in.getByte (); |
|
252 |
if (type_id != DerValue.tag_ObjectId) |
|
253 |
throw new IOException ( |
|
254 |
"ObjectIdentifier() -- data isn't an object ID" |
|
255 |
+ " (tag = " + type_id + ")" |
|
256 |
); |
|
257 |
||
23345
534d74068ee0
8028591: NegativeArraySizeException in sun.security.util.DerInputStream.getUnalignedBitString()
asmotrak
parents:
5506
diff
changeset
|
258 |
encoding = new byte[in.getDefiniteLength()]; |
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
259 |
in.getBytes(encoding); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
260 |
check(encoding); |
2 | 261 |
} |
262 |
||
263 |
/* |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
264 |
* Constructor, from the rest of a DER input buffer; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
265 |
* the tag and length have been removed/verified |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
266 |
* Validity check NOT included. |
2 | 267 |
*/ |
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
268 |
ObjectIdentifier (DerInputBuffer buf) throws IOException |
2 | 269 |
{ |
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
270 |
DerInputStream in = new DerInputStream(buf); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
271 |
encoding = new byte[in.available()]; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
272 |
in.getBytes(encoding); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
273 |
check(encoding); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
274 |
} |
2 | 275 |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
276 |
private void init(int[] components, int length) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
277 |
int pos = 0; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
278 |
byte[] tmp = new byte[length*5+1]; // +1 for empty input |
2 | 279 |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
280 |
if (components[1] < Integer.MAX_VALUE - components[0]*40) |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
281 |
pos += pack7Oid(components[0]*40+components[1], tmp, pos); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
282 |
else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
283 |
BigInteger big = BigInteger.valueOf(components[1]); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
284 |
big = big.add(BigInteger.valueOf(components[0]*40)); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
285 |
pos += pack7Oid(big, tmp, pos); |
2 | 286 |
} |
287 |
||
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
288 |
for (int i=2; i<length; i++) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
289 |
pos += pack7Oid(components[i], tmp, pos); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
290 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
291 |
encoding = new byte[pos]; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
292 |
System.arraycopy(tmp, 0, encoding, 0, pos); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
293 |
} |
2 | 294 |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
295 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
296 |
* This method is kept for compatibility reasons. The new implementation |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
297 |
* does the check and conversion. All around the JDK, the method is called |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
298 |
* in static blocks to initialize pre-defined ObjectIdentifieies. No |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
299 |
* obvious performance hurt will be made after this change. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
300 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
301 |
* Old doc: Create a new ObjectIdentifier for internal use. The values are |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
302 |
* neither checked nor cloned. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
303 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
304 |
public static ObjectIdentifier newInternal(int[] values) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
305 |
try { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
306 |
return new ObjectIdentifier(values); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
307 |
} catch (IOException ex) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
308 |
throw new RuntimeException(ex); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
309 |
// Should not happen, internal calls always uses legal values. |
2 | 310 |
} |
311 |
} |
|
312 |
||
313 |
/* |
|
314 |
* n.b. the only public interface is DerOutputStream.putOID() |
|
315 |
*/ |
|
316 |
void encode (DerOutputStream out) throws IOException |
|
317 |
{ |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
318 |
out.write (DerValue.tag_ObjectId, encoding); |
2 | 319 |
} |
320 |
||
321 |
/** |
|
322 |
* Compares this identifier with another, for equality. |
|
323 |
* |
|
324 |
* @return true iff the names are identical. |
|
325 |
*/ |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
326 |
@Override |
2 | 327 |
public boolean equals(Object obj) { |
328 |
if (this == obj) { |
|
329 |
return true; |
|
330 |
} |
|
331 |
if (obj instanceof ObjectIdentifier == false) { |
|
332 |
return false; |
|
333 |
} |
|
334 |
ObjectIdentifier other = (ObjectIdentifier)obj; |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
335 |
return Arrays.equals(encoding, other.encoding); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
336 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
337 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
338 |
@Override |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
339 |
public int hashCode() { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
340 |
return Arrays.hashCode(encoding); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
341 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
342 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
343 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
344 |
* Private helper method for serialization. To be compatible with old |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
345 |
* versions of JDK. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
346 |
* @return components in an int array, if all the components are less than |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
347 |
* Integer.MAX_VALUE. Otherwise, null. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
348 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
349 |
private int[] toIntArray() { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
350 |
int length = encoding.length; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
351 |
int[] result = new int[20]; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
352 |
int which = 0; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
353 |
int fromPos = 0; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
354 |
for (int i = 0; i < length; i++) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
355 |
if ((encoding[i] & 0x80) == 0) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
356 |
// one section [fromPos..i] |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
357 |
if (i - fromPos + 1 > 4) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
358 |
BigInteger big = new BigInteger(pack(encoding, fromPos, i-fromPos+1, 7, 8)); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
359 |
if (fromPos == 0) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
360 |
result[which++] = 2; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
361 |
BigInteger second = big.subtract(BigInteger.valueOf(80)); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
362 |
if (second.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 1) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
363 |
return null; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
364 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
365 |
result[which++] = second.intValue(); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
366 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
367 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
368 |
if (big.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 1) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
369 |
return null; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
370 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
371 |
result[which++] = big.intValue(); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
372 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
373 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
374 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
375 |
int retval = 0; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
376 |
for (int j = fromPos; j <= i; j++) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
377 |
retval <<= 7; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
378 |
byte tmp = encoding[j]; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
379 |
retval |= (tmp & 0x07f); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
380 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
381 |
if (fromPos == 0) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
382 |
if (retval < 80) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
383 |
result[which++] = retval / 40; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
384 |
result[which++] = retval % 40; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
385 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
386 |
result[which++] = 2; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
387 |
result[which++] = retval - 80; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
388 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
389 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
390 |
result[which++] = retval; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
391 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
392 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
393 |
fromPos = i+1; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
394 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
395 |
if (which >= result.length) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
396 |
result = Arrays.copyOf(result, which + 10); |
2 | 397 |
} |
398 |
} |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
399 |
return Arrays.copyOf(result, which); |
2 | 400 |
} |
401 |
||
402 |
/** |
|
403 |
* Returns a string form of the object ID. The format is the |
|
404 |
* conventional "dot" notation for such IDs, without any |
|
405 |
* user-friendly descriptive strings, since those strings |
|
406 |
* will not be understood everywhere. |
|
407 |
*/ |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
408 |
@Override |
2 | 409 |
public String toString() { |
410 |
String s = stringForm; |
|
411 |
if (s == null) { |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
412 |
int length = encoding.length; |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23345
diff
changeset
|
413 |
StringBuilder sb = new StringBuilder(length * 4); |
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
414 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
415 |
int fromPos = 0; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
416 |
for (int i = 0; i < length; i++) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
417 |
if ((encoding[i] & 0x80) == 0) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
418 |
// one section [fromPos..i] |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
419 |
if (fromPos != 0) { // not the first segment |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
420 |
sb.append('.'); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
421 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
422 |
if (i - fromPos + 1 > 4) { // maybe big integer |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
423 |
BigInteger big = new BigInteger(pack(encoding, fromPos, i-fromPos+1, 7, 8)); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
424 |
if (fromPos == 0) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
425 |
// first section encoded with more than 4 bytes, |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
426 |
// must be 2.something |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
427 |
sb.append("2."); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
428 |
sb.append(big.subtract(BigInteger.valueOf(80))); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
429 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
430 |
sb.append(big); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
431 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
432 |
} else { // small integer |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
433 |
int retval = 0; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
434 |
for (int j = fromPos; j <= i; j++) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
435 |
retval <<= 7; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
436 |
byte tmp = encoding[j]; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
437 |
retval |= (tmp & 0x07f); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
438 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
439 |
if (fromPos == 0) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
440 |
if (retval < 80) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
441 |
sb.append(retval/40); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
442 |
sb.append('.'); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
443 |
sb.append(retval%40); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
444 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
445 |
sb.append("2."); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
446 |
sb.append(retval - 80); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
447 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
448 |
} else { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
449 |
sb.append(retval); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
450 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
451 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
452 |
fromPos = i+1; |
2 | 453 |
} |
454 |
} |
|
455 |
s = sb.toString(); |
|
456 |
stringForm = s; |
|
457 |
} |
|
458 |
return s; |
|
459 |
} |
|
460 |
||
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
461 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
462 |
* Repack all bits from input to output. On the both sides, only a portion |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
463 |
* (from the least significant bit) of the 8 bits in a byte is used. This |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
464 |
* number is defined as the number of useful bits (NUB) for the array. All the |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
465 |
* used bits from the input byte array and repacked into the output in the |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
466 |
* exactly same order. The output bits are aligned so that the final bit of |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
467 |
* the input (the least significant bit in the last byte), when repacked as |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
468 |
* the final bit of the output, is still at the least significant position. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
469 |
* Zeroes will be padded on the left side of the first output byte if |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
470 |
* necessary. All unused bits in the output are also zeroed. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
471 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
472 |
* For example: if the input is 01001100 with NUB 8, the output which |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
473 |
* has a NUB 6 will look like: |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
474 |
* 00000001 00001100 |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
475 |
* The first 2 bits of the output bytes are unused bits. The other bits |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
476 |
* turn out to be 000001 001100. While the 8 bits on the right are from |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
477 |
* the input, the left 4 zeroes are padded to fill the 6 bits space. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
478 |
* |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
479 |
* @param in the input byte array |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
480 |
* @param ioffset start point inside <code>in</code> |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
481 |
* @param ilength number of bytes to repack |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
482 |
* @param iw NUB for input |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
483 |
* @param ow NUB for output |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
484 |
* @return the repacked bytes |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
485 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
486 |
private static byte[] pack(byte[] in, int ioffset, int ilength, int iw, int ow) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
487 |
assert (iw > 0 && iw <= 8): "input NUB must be between 1 and 8"; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
488 |
assert (ow > 0 && ow <= 8): "output NUB must be between 1 and 8"; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
489 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
490 |
if (iw == ow) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
491 |
return in.clone(); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
492 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
493 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
494 |
int bits = ilength * iw; // number of all used bits |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
495 |
byte[] out = new byte[(bits+ow-1)/ow]; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
496 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
497 |
// starting from the 0th bit in the input |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
498 |
int ipos = 0; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
499 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
500 |
// the number of padding 0's needed in the output, skip them |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
501 |
int opos = (bits+ow-1)/ow*ow-bits; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
502 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
503 |
while(ipos < bits) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
504 |
int count = iw - ipos%iw; // unpacked bits in current input byte |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
505 |
if (count > ow - opos%ow) { // free space available in output byte |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
506 |
count = ow - opos%ow; // choose the smaller number |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
507 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
508 |
// and move them! |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
509 |
out[opos/ow] |= // paste! |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
510 |
(((in[ioffset+ipos/iw]+256) // locate the byte (+256 so that it's never negative) |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
511 |
>> (iw-ipos%iw-count)) // move to the end of a byte |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
512 |
& ((1 << (count))-1)) // zero out all other bits |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
513 |
<< (ow-opos%ow-count); // move to the output position |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
514 |
ipos += count; // advance |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
515 |
opos += count; // advance |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
516 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
517 |
return out; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
518 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
519 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
520 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
521 |
* Repack from NUB 8 to a NUB 7 OID sub-identifier, remove all |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
522 |
* unnecessary 0 headings, set the first bit of all non-tail |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
523 |
* output bytes to 1 (as ITU-T Rec. X.690 8.19.2 says), and |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
524 |
* paste it into an existing byte array. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
525 |
* @param out the existing array to be pasted into |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
526 |
* @param ooffset the starting position to paste |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
527 |
* @return the number of bytes pasted |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
528 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
529 |
private static int pack7Oid(byte[] in, int ioffset, int ilength, byte[] out, int ooffset) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
530 |
byte[] pack = pack(in, ioffset, ilength, 8, 7); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
531 |
int firstNonZero = pack.length-1; // paste at least one byte |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
532 |
for (int i=pack.length-2; i>=0; i--) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
533 |
if (pack[i] != 0) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
534 |
firstNonZero = i; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
535 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
536 |
pack[i] |= 0x80; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
537 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
538 |
System.arraycopy(pack, firstNonZero, out, ooffset, pack.length-firstNonZero); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
539 |
return pack.length-firstNonZero; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
540 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
541 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
542 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
543 |
* Repack from NUB 7 to NUB 8, remove all unnecessary 0 |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
544 |
* headings, and paste it into an existing byte array. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
545 |
* @param out the existing array to be pasted into |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
546 |
* @param ooffset the starting position to paste |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
547 |
* @return the number of bytes pasted |
2 | 548 |
*/ |
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
549 |
private static int pack8(byte[] in, int ioffset, int ilength, byte[] out, int ooffset) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
550 |
byte[] pack = pack(in, ioffset, ilength, 7, 8); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
551 |
int firstNonZero = pack.length-1; // paste at least one byte |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
552 |
for (int i=pack.length-2; i>=0; i--) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
553 |
if (pack[i] != 0) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
554 |
firstNonZero = i; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
555 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
556 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
557 |
System.arraycopy(pack, firstNonZero, out, ooffset, pack.length-firstNonZero); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
558 |
return pack.length-firstNonZero; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
559 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
560 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
561 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
562 |
* Pack the int into a OID sub-identifier DER encoding |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
563 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
564 |
private static int pack7Oid(int input, byte[] out, int ooffset) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
565 |
byte[] b = new byte[4]; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
566 |
b[0] = (byte)(input >> 24); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
567 |
b[1] = (byte)(input >> 16); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
568 |
b[2] = (byte)(input >> 8); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
569 |
b[3] = (byte)(input); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
570 |
return pack7Oid(b, 0, 4, out, ooffset); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
571 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
572 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
573 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
574 |
* Pack the BigInteger into a OID subidentifier DER encoding |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
575 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
576 |
private static int pack7Oid(BigInteger input, byte[] out, int ooffset) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
577 |
byte[] b = input.toByteArray(); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
578 |
return pack7Oid(b, 0, b.length, out, ooffset); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
579 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
580 |
|
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
581 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
582 |
* Private methods to check validity of OID. They must be -- |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
583 |
* 1. at least 2 components |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
584 |
* 2. all components must be non-negative |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
585 |
* 3. the first must be 0, 1 or 2 |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
586 |
* 4. if the first is 0 or 1, the second must be <40 |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
587 |
*/ |
2 | 588 |
|
2584
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
589 |
/** |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
590 |
* Check the DER encoding. Since DER encoding defines that the integer bits |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
591 |
* are unsigned, so there's no need to check the MSB. |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
592 |
*/ |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
593 |
private static void check(byte[] encoding) throws IOException { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
594 |
int length = encoding.length; |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
595 |
if (length < 1 || // too short |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
596 |
(encoding[length - 1] & 0x80) != 0) { // not ended |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
597 |
throw new IOException("ObjectIdentifier() -- " + |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
598 |
"Invalid DER encoding, not ended"); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
599 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
600 |
for (int i=0; i<length; i++) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
601 |
// 0x80 at the beginning of a subidentifier |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
602 |
if (encoding[i] == (byte)0x80 && |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
603 |
(i==0 || (encoding[i-1] & 0x80) == 0)) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
604 |
throw new IOException("ObjectIdentifier() -- " + |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
605 |
"Invalid DER encoding, useless extra octet detected"); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
606 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
607 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
608 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
609 |
private static void checkCount(int count) throws IOException { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
610 |
if (count < 2) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
611 |
throw new IOException("ObjectIdentifier() -- " + |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
612 |
"Must be at least two oid components "); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
613 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
614 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
615 |
private static void checkFirstComponent(int first) throws IOException { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
616 |
if (first < 0 || first > 2) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
617 |
throw new IOException("ObjectIdentifier() -- " + |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
618 |
"First oid component is invalid "); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
619 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
620 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
621 |
private static void checkFirstComponent(BigInteger first) throws IOException { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
622 |
if (first.signum() == -1 || |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
623 |
first.compareTo(BigInteger.valueOf(2)) == 1) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
624 |
throw new IOException("ObjectIdentifier() -- " + |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
625 |
"First oid component is invalid "); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
626 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
627 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
628 |
private static void checkSecondComponent(int first, int second) throws IOException { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
629 |
if (second < 0 || first != 2 && second > 39) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
630 |
throw new IOException("ObjectIdentifier() -- " + |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
631 |
"Second oid component is invalid "); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
632 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
633 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
634 |
private static void checkSecondComponent(int first, BigInteger second) throws IOException { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
635 |
if (second.signum() == -1 || |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
636 |
first != 2 && |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
637 |
second.compareTo(BigInteger.valueOf(39)) == 1) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
638 |
throw new IOException("ObjectIdentifier() -- " + |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
639 |
"Second oid component is invalid "); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
640 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
641 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
642 |
private static void checkOtherComponent(int i, int num) throws IOException { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
643 |
if (num < 0) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
644 |
throw new IOException("ObjectIdentifier() -- " + |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
645 |
"oid component #" + (i+1) + " must be non-negative "); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
646 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
647 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
648 |
private static void checkOtherComponent(int i, BigInteger num) throws IOException { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
649 |
if (num.signum() == -1) { |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
650 |
throw new IOException("ObjectIdentifier() -- " + |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
651 |
"oid component #" + (i+1) + " must be non-negative "); |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
652 |
} |
a89e7cabf6fd
4811968: ASN.1 (X509Certificate) implementations don't handle large OID components
weijun
parents:
2
diff
changeset
|
653 |
} |
2 | 654 |
} |