author | weijun |
Sat, 21 Jul 2012 19:56:53 +0800 | |
changeset 13361 | bda5c2354fc6 |
parent 12685 | 8a448b5b9006 |
child 13661 | 7c894680910a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
12685 | 2 |
* Copyright (c) 1996, 2012, 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.x509; |
|
27 |
||
28 |
import java.io.*; |
|
29 |
import java.util.*; |
|
30 |
import java.security.*; |
|
31 |
||
32 |
import sun.security.util.*; |
|
33 |
||
34 |
||
35 |
/** |
|
36 |
* This class identifies algorithms, such as cryptographic transforms, each |
|
37 |
* of which may be associated with parameters. Instances of this base class |
|
38 |
* are used when this runtime environment has no special knowledge of the |
|
39 |
* algorithm type, and may also be used in other cases. Equivalence is |
|
40 |
* defined according to OID and (where relevant) parameters. |
|
41 |
* |
|
42 |
* <P>Subclasses may be used, for example when when the algorithm ID has |
|
43 |
* associated parameters which some code (e.g. code using public keys) needs |
|
44 |
* to have parsed. Two examples of such algorithms are Diffie-Hellman key |
|
45 |
* exchange, and the Digital Signature Standard Algorithm (DSS/DSA). |
|
46 |
* |
|
47 |
* <P>The OID constants defined in this class correspond to some widely |
|
48 |
* used algorithms, for which conventional string names have been defined. |
|
49 |
* This class is not a general repository for OIDs, or for such string names. |
|
50 |
* Note that the mappings between algorithm IDs and algorithm names is |
|
51 |
* not one-to-one. |
|
52 |
* |
|
53 |
* |
|
54 |
* @author David Brownell |
|
55 |
* @author Amit Kapoor |
|
56 |
* @author Hemma Prafullchandra |
|
57 |
*/ |
|
58 |
public class AlgorithmId implements Serializable, DerEncoder { |
|
59 |
||
60 |
/** use serialVersionUID from JDK 1.1. for interoperability */ |
|
61 |
private static final long serialVersionUID = 7205873507486557157L; |
|
62 |
||
63 |
/** |
|
64 |
* The object identitifer being used for this algorithm. |
|
65 |
*/ |
|
66 |
private ObjectIdentifier algid; |
|
67 |
||
68 |
// The (parsed) parameters |
|
69 |
private AlgorithmParameters algParams; |
|
70 |
private boolean constructedFromDer = true; |
|
71 |
||
72 |
/** |
|
73 |
* Parameters for this algorithm. These are stored in unparsed |
|
74 |
* DER-encoded form; subclasses can be made to automaticaly parse |
|
75 |
* them so there is fast access to these parameters. |
|
76 |
*/ |
|
77 |
protected DerValue params; |
|
78 |
||
79 |
||
80 |
/** |
|
81 |
* Constructs an algorithm ID which will be initialized |
|
82 |
* separately, for example by deserialization. |
|
83 |
* @deprecated use one of the other constructors. |
|
84 |
*/ |
|
85 |
@Deprecated |
|
86 |
public AlgorithmId() { } |
|
87 |
||
88 |
/** |
|
89 |
* Constructs a parameterless algorithm ID. |
|
90 |
* |
|
91 |
* @param oid the identifier for the algorithm |
|
92 |
*/ |
|
93 |
public AlgorithmId(ObjectIdentifier oid) { |
|
94 |
algid = oid; |
|
95 |
} |
|
96 |
||
97 |
/** |
|
98 |
* Constructs an algorithm ID with algorithm parameters. |
|
99 |
* |
|
100 |
* @param oid the identifier for the algorithm. |
|
101 |
* @param algparams the associated algorithm parameters. |
|
102 |
*/ |
|
103 |
public AlgorithmId(ObjectIdentifier oid, AlgorithmParameters algparams) { |
|
104 |
algid = oid; |
|
105 |
algParams = algparams; |
|
106 |
constructedFromDer = false; |
|
107 |
} |
|
108 |
||
109 |
private AlgorithmId(ObjectIdentifier oid, DerValue params) |
|
110 |
throws IOException { |
|
111 |
this.algid = oid; |
|
112 |
this.params = params; |
|
113 |
if (this.params != null) { |
|
114 |
decodeParams(); |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
protected void decodeParams() throws IOException { |
|
119 |
String algidString = algid.toString(); |
|
120 |
try { |
|
121 |
algParams = AlgorithmParameters.getInstance(algidString); |
|
122 |
} catch (NoSuchAlgorithmException e) { |
|
123 |
try { |
|
124 |
// Try the internal EC code so that we can fully parse EC |
|
125 |
// keys even if the provider is not registered. |
|
126 |
// This code can go away once we have EC in the SUN provider. |
|
127 |
algParams = AlgorithmParameters.getInstance(algidString, |
|
128 |
sun.security.ec.ECKeyFactory.ecInternalProvider); |
|
129 |
} catch (NoSuchAlgorithmException ee) { |
|
130 |
/* |
|
131 |
* This algorithm parameter type is not supported, so we cannot |
|
132 |
* parse the parameters. |
|
133 |
*/ |
|
134 |
algParams = null; |
|
135 |
return; |
|
136 |
} |
|
137 |
} |
|
138 |
// Decode (parse) the parameters |
|
139 |
algParams.init(params.toByteArray()); |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* Marshal a DER-encoded "AlgorithmID" sequence on the DER stream. |
|
144 |
*/ |
|
145 |
public final void encode(DerOutputStream out) throws IOException { |
|
146 |
derEncode(out); |
|
147 |
} |
|
148 |
||
149 |
/** |
|
150 |
* DER encode this object onto an output stream. |
|
151 |
* Implements the <code>DerEncoder</code> interface. |
|
152 |
* |
|
153 |
* @param out |
|
154 |
* the output stream on which to write the DER encoding. |
|
155 |
* |
|
156 |
* @exception IOException on encoding error. |
|
157 |
*/ |
|
158 |
public void derEncode (OutputStream out) throws IOException { |
|
159 |
DerOutputStream bytes = new DerOutputStream(); |
|
160 |
DerOutputStream tmp = new DerOutputStream(); |
|
161 |
||
162 |
bytes.putOID(algid); |
|
163 |
// Setup params from algParams since no DER encoding is given |
|
164 |
if (constructedFromDer == false) { |
|
165 |
if (algParams != null) { |
|
166 |
params = new DerValue(algParams.getEncoded()); |
|
167 |
} else { |
|
168 |
params = null; |
|
169 |
} |
|
170 |
} |
|
171 |
if (params == null) { |
|
172 |
// Changes backed out for compatibility with Solaris |
|
173 |
||
174 |
// Several AlgorithmId should omit the whole parameter part when |
|
175 |
// it's NULL. They are --- |
|
176 |
// rfc3370 2.1: Implementations SHOULD generate SHA-1 |
|
177 |
// AlgorithmIdentifiers with absent parameters. |
|
12685 | 178 |
// rfc3447 C1: When id-sha1, id-sha224, id-sha256, id-sha384 and |
179 |
// id-sha512 are used in an AlgorithmIdentifier the parameters |
|
180 |
// (which are optional) SHOULD be omitted. |
|
2 | 181 |
// rfc3279 2.3.2: The id-dsa algorithm syntax includes optional |
182 |
// domain parameters... When omitted, the parameters component |
|
183 |
// MUST be omitted entirely |
|
184 |
// rfc3370 3.1: When the id-dsa-with-sha1 algorithm identifier |
|
185 |
// is used, the AlgorithmIdentifier parameters field MUST be absent. |
|
186 |
/*if ( |
|
187 |
algid.equals((Object)SHA_oid) || |
|
12685 | 188 |
algid.equals((Object)SHA224_oid) || |
2 | 189 |
algid.equals((Object)SHA256_oid) || |
190 |
algid.equals((Object)SHA384_oid) || |
|
191 |
algid.equals((Object)SHA512_oid) || |
|
192 |
algid.equals((Object)DSA_oid) || |
|
193 |
algid.equals((Object)sha1WithDSA_oid)) { |
|
194 |
; // no parameter part encoded |
|
195 |
} else { |
|
196 |
bytes.putNull(); |
|
197 |
}*/ |
|
198 |
bytes.putNull(); |
|
199 |
} else { |
|
200 |
bytes.putDerValue(params); |
|
201 |
} |
|
202 |
tmp.write(DerValue.tag_Sequence, bytes); |
|
203 |
out.write(tmp.toByteArray()); |
|
204 |
} |
|
205 |
||
206 |
||
207 |
/** |
|
208 |
* Returns the DER-encoded X.509 AlgorithmId as a byte array. |
|
209 |
*/ |
|
210 |
public final byte[] encode() throws IOException { |
|
211 |
DerOutputStream out = new DerOutputStream(); |
|
212 |
derEncode(out); |
|
213 |
return out.toByteArray(); |
|
214 |
} |
|
215 |
||
216 |
/** |
|
217 |
* Returns the ISO OID for this algorithm. This is usually converted |
|
218 |
* to a string and used as part of an algorithm name, for example |
|
219 |
* "OID.1.3.14.3.2.13" style notation. Use the <code>getName</code> |
|
220 |
* call when you do not need to ensure cross-system portability |
|
221 |
* of algorithm names, or need a user friendly name. |
|
222 |
*/ |
|
223 |
public final ObjectIdentifier getOID () { |
|
224 |
return algid; |
|
225 |
} |
|
226 |
||
227 |
/** |
|
228 |
* Returns a name for the algorithm which may be more intelligible |
|
229 |
* to humans than the algorithm's OID, but which won't necessarily |
|
230 |
* be comprehensible on other systems. For example, this might |
|
231 |
* return a name such as "MD5withRSA" for a signature algorithm on |
|
232 |
* some systems. It also returns names like "OID.1.2.3.4", when |
|
233 |
* no particular name for the algorithm is known. |
|
234 |
*/ |
|
235 |
public String getName() { |
|
236 |
String algName = nameTable.get(algid); |
|
237 |
if (algName != null) { |
|
238 |
return algName; |
|
239 |
} |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
6122
diff
changeset
|
240 |
if ((params != null) && algid.equals((Object)specifiedWithECDSA_oid)) { |
2 | 241 |
try { |
242 |
AlgorithmId paramsId = |
|
243 |
AlgorithmId.parse(new DerValue(getEncodedParams())); |
|
244 |
String paramsName = paramsId.getName(); |
|
13361
bda5c2354fc6
7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents:
12685
diff
changeset
|
245 |
algName = makeSigAlg(paramsName, "EC"); |
2 | 246 |
} catch (IOException e) { |
247 |
// ignore |
|
248 |
} |
|
249 |
} |
|
250 |
return (algName == null) ? algid.toString() : algName; |
|
251 |
} |
|
252 |
||
253 |
public AlgorithmParameters getParameters() { |
|
254 |
return algParams; |
|
255 |
} |
|
256 |
||
257 |
/** |
|
258 |
* Returns the DER encoded parameter, which can then be |
|
259 |
* used to initialize java.security.AlgorithmParamters. |
|
260 |
* |
|
261 |
* @return DER encoded parameters, or null not present. |
|
262 |
*/ |
|
263 |
public byte[] getEncodedParams() throws IOException { |
|
264 |
return (params == null) ? null : params.toByteArray(); |
|
265 |
} |
|
266 |
||
267 |
/** |
|
268 |
* Returns true iff the argument indicates the same algorithm |
|
269 |
* with the same parameters. |
|
270 |
*/ |
|
271 |
public boolean equals(AlgorithmId other) { |
|
272 |
boolean paramsEqual = |
|
273 |
(params == null ? other.params == null : params.equals(other.params)); |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
6122
diff
changeset
|
274 |
return (algid.equals((Object)other.algid) && paramsEqual); |
2 | 275 |
} |
276 |
||
277 |
/** |
|
278 |
* Compares this AlgorithmID to another. If algorithm parameters are |
|
279 |
* available, they are compared. Otherwise, just the object IDs |
|
280 |
* for the algorithm are compared. |
|
281 |
* |
|
282 |
* @param other preferably an AlgorithmId, else an ObjectIdentifier |
|
283 |
*/ |
|
284 |
public boolean equals(Object other) { |
|
285 |
if (this == other) { |
|
286 |
return true; |
|
287 |
} |
|
288 |
if (other instanceof AlgorithmId) { |
|
289 |
return equals((AlgorithmId) other); |
|
290 |
} else if (other instanceof ObjectIdentifier) { |
|
291 |
return equals((ObjectIdentifier) other); |
|
292 |
} else { |
|
293 |
return false; |
|
294 |
} |
|
295 |
} |
|
296 |
||
297 |
/** |
|
298 |
* Compares two algorithm IDs for equality. Returns true iff |
|
299 |
* they are the same algorithm, ignoring algorithm parameters. |
|
300 |
*/ |
|
301 |
public final boolean equals(ObjectIdentifier id) { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
6122
diff
changeset
|
302 |
return algid.equals((Object)id); |
2 | 303 |
} |
304 |
||
305 |
/** |
|
306 |
* Returns a hashcode for this AlgorithmId. |
|
307 |
* |
|
308 |
* @return a hashcode for this AlgorithmId. |
|
309 |
*/ |
|
310 |
public int hashCode() { |
|
311 |
StringBuilder sbuf = new StringBuilder(); |
|
312 |
sbuf.append(algid.toString()); |
|
313 |
sbuf.append(paramsToString()); |
|
314 |
return sbuf.toString().hashCode(); |
|
315 |
} |
|
316 |
||
317 |
/** |
|
318 |
* Provides a human-readable description of the algorithm parameters. |
|
319 |
* This may be redefined by subclasses which parse those parameters. |
|
320 |
*/ |
|
321 |
protected String paramsToString() { |
|
322 |
if (params == null) { |
|
323 |
return ""; |
|
324 |
} else if (algParams != null) { |
|
325 |
return algParams.toString(); |
|
326 |
} else { |
|
327 |
return ", params unparsed"; |
|
328 |
} |
|
329 |
} |
|
330 |
||
331 |
/** |
|
332 |
* Returns a string describing the algorithm and its parameters. |
|
333 |
*/ |
|
334 |
public String toString() { |
|
335 |
return getName() + paramsToString(); |
|
336 |
} |
|
337 |
||
338 |
/** |
|
339 |
* Parse (unmarshal) an ID from a DER sequence input value. This form |
|
340 |
* parsing might be used when expanding a value which has already been |
|
341 |
* partially unmarshaled as a set or sequence member. |
|
342 |
* |
|
343 |
* @exception IOException on error. |
|
344 |
* @param val the input value, which contains the algid and, if |
|
345 |
* there are any parameters, those parameters. |
|
346 |
* @return an ID for the algorithm. If the system is configured |
|
347 |
* appropriately, this may be an instance of a class |
|
348 |
* with some kind of special support for this algorithm. |
|
349 |
* In that case, you may "narrow" the type of the ID. |
|
350 |
*/ |
|
351 |
public static AlgorithmId parse(DerValue val) throws IOException { |
|
352 |
if (val.tag != DerValue.tag_Sequence) { |
|
353 |
throw new IOException("algid parse error, not a sequence"); |
|
354 |
} |
|
355 |
||
356 |
/* |
|
357 |
* Get the algorithm ID and any parameters. |
|
358 |
*/ |
|
359 |
ObjectIdentifier algid; |
|
360 |
DerValue params; |
|
361 |
DerInputStream in = val.toDerInputStream(); |
|
362 |
||
363 |
algid = in.getOID(); |
|
364 |
if (in.available() == 0) { |
|
365 |
params = null; |
|
366 |
} else { |
|
367 |
params = in.getDerValue(); |
|
368 |
if (params.tag == DerValue.tag_Null) { |
|
369 |
if (params.length() != 0) { |
|
370 |
throw new IOException("invalid NULL"); |
|
371 |
} |
|
372 |
params = null; |
|
373 |
} |
|
374 |
if (in.available() != 0) { |
|
375 |
throw new IOException("Invalid AlgorithmIdentifier: extra data"); |
|
376 |
} |
|
377 |
} |
|
378 |
||
379 |
return new AlgorithmId(algid, params); |
|
380 |
} |
|
381 |
||
382 |
/** |
|
383 |
* Returns one of the algorithm IDs most commonly associated |
|
384 |
* with this algorithm name. |
|
385 |
* |
|
386 |
* @param algname the name being used |
|
387 |
* @deprecated use the short get form of this method. |
|
388 |
* @exception NoSuchAlgorithmException on error. |
|
389 |
*/ |
|
390 |
@Deprecated |
|
391 |
public static AlgorithmId getAlgorithmId(String algname) |
|
392 |
throws NoSuchAlgorithmException { |
|
393 |
return get(algname); |
|
394 |
} |
|
395 |
||
396 |
/** |
|
397 |
* Returns one of the algorithm IDs most commonly associated |
|
398 |
* with this algorithm name. |
|
399 |
* |
|
400 |
* @param algname the name being used |
|
401 |
* @exception NoSuchAlgorithmException on error. |
|
402 |
*/ |
|
403 |
public static AlgorithmId get(String algname) |
|
404 |
throws NoSuchAlgorithmException { |
|
405 |
ObjectIdentifier oid; |
|
406 |
try { |
|
407 |
oid = algOID(algname); |
|
408 |
} catch (IOException ioe) { |
|
409 |
throw new NoSuchAlgorithmException |
|
410 |
("Invalid ObjectIdentifier " + algname); |
|
411 |
} |
|
412 |
||
413 |
if (oid == null) { |
|
414 |
throw new NoSuchAlgorithmException |
|
415 |
("unrecognized algorithm name: " + algname); |
|
416 |
} |
|
417 |
return new AlgorithmId(oid); |
|
418 |
} |
|
419 |
||
420 |
/** |
|
421 |
* Returns one of the algorithm IDs most commonly associated |
|
422 |
* with this algorithm parameters. |
|
423 |
* |
|
424 |
* @param algparams the associated algorithm parameters. |
|
425 |
* @exception NoSuchAlgorithmException on error. |
|
426 |
*/ |
|
427 |
public static AlgorithmId get(AlgorithmParameters algparams) |
|
428 |
throws NoSuchAlgorithmException { |
|
429 |
ObjectIdentifier oid; |
|
430 |
String algname = algparams.getAlgorithm(); |
|
431 |
try { |
|
432 |
oid = algOID(algname); |
|
433 |
} catch (IOException ioe) { |
|
434 |
throw new NoSuchAlgorithmException |
|
435 |
("Invalid ObjectIdentifier " + algname); |
|
436 |
} |
|
437 |
if (oid == null) { |
|
438 |
throw new NoSuchAlgorithmException |
|
439 |
("unrecognized algorithm name: " + algname); |
|
440 |
} |
|
441 |
return new AlgorithmId(oid, algparams); |
|
442 |
} |
|
443 |
||
444 |
/* |
|
445 |
* Translates from some common algorithm names to the |
|
446 |
* OID with which they're usually associated ... this mapping |
|
447 |
* is the reverse of the one below, except in those cases |
|
448 |
* where synonyms are supported or where a given algorithm |
|
449 |
* is commonly associated with multiple OIDs. |
|
450 |
* |
|
451 |
* XXX This method needs to be enhanced so that we can also pass the |
|
452 |
* scope of the algorithm name to it, e.g., the algorithm name "DSA" |
|
453 |
* may have a different OID when used as a "Signature" algorithm than when |
|
454 |
* used as a "KeyPairGenerator" algorithm. |
|
455 |
*/ |
|
456 |
private static ObjectIdentifier algOID(String name) throws IOException { |
|
457 |
// See if algname is in printable OID ("dot-dot") notation |
|
458 |
if (name.indexOf('.') != -1) { |
|
459 |
if (name.startsWith("OID.")) { |
|
460 |
return new ObjectIdentifier(name.substring("OID.".length())); |
|
461 |
} else { |
|
462 |
return new ObjectIdentifier(name); |
|
463 |
} |
|
464 |
} |
|
465 |
||
466 |
// Digesting algorithms |
|
467 |
if (name.equalsIgnoreCase("MD5")) { |
|
468 |
return AlgorithmId.MD5_oid; |
|
469 |
} |
|
470 |
if (name.equalsIgnoreCase("MD2")) { |
|
471 |
return AlgorithmId.MD2_oid; |
|
472 |
} |
|
473 |
if (name.equalsIgnoreCase("SHA") || name.equalsIgnoreCase("SHA1") |
|
474 |
|| name.equalsIgnoreCase("SHA-1")) { |
|
475 |
return AlgorithmId.SHA_oid; |
|
476 |
} |
|
477 |
if (name.equalsIgnoreCase("SHA-256") || |
|
478 |
name.equalsIgnoreCase("SHA256")) { |
|
479 |
return AlgorithmId.SHA256_oid; |
|
480 |
} |
|
481 |
if (name.equalsIgnoreCase("SHA-384") || |
|
482 |
name.equalsIgnoreCase("SHA384")) { |
|
483 |
return AlgorithmId.SHA384_oid; |
|
484 |
} |
|
485 |
if (name.equalsIgnoreCase("SHA-512") || |
|
486 |
name.equalsIgnoreCase("SHA512")) { |
|
487 |
return AlgorithmId.SHA512_oid; |
|
488 |
} |
|
12685 | 489 |
if (name.equalsIgnoreCase("SHA-224") || |
490 |
name.equalsIgnoreCase("SHA224")) { |
|
491 |
return AlgorithmId.SHA224_oid; |
|
492 |
} |
|
2 | 493 |
|
494 |
// Various public key algorithms |
|
495 |
if (name.equalsIgnoreCase("RSA")) { |
|
496 |
return AlgorithmId.RSAEncryption_oid; |
|
497 |
} |
|
498 |
if (name.equalsIgnoreCase("Diffie-Hellman") |
|
499 |
|| name.equalsIgnoreCase("DH")) { |
|
500 |
return AlgorithmId.DH_oid; |
|
501 |
} |
|
502 |
if (name.equalsIgnoreCase("DSA")) { |
|
503 |
return AlgorithmId.DSA_oid; |
|
504 |
} |
|
505 |
if (name.equalsIgnoreCase("EC")) { |
|
506 |
return EC_oid; |
|
507 |
} |
|
508 |
||
509 |
// Common signature types |
|
510 |
if (name.equalsIgnoreCase("MD5withRSA") |
|
511 |
|| name.equalsIgnoreCase("MD5/RSA")) { |
|
512 |
return AlgorithmId.md5WithRSAEncryption_oid; |
|
513 |
} |
|
514 |
if (name.equalsIgnoreCase("MD2withRSA") |
|
515 |
|| name.equalsIgnoreCase("MD2/RSA")) { |
|
516 |
return AlgorithmId.md2WithRSAEncryption_oid; |
|
517 |
} |
|
518 |
if (name.equalsIgnoreCase("SHAwithDSA") |
|
519 |
|| name.equalsIgnoreCase("SHA1withDSA") |
|
520 |
|| name.equalsIgnoreCase("SHA/DSA") |
|
521 |
|| name.equalsIgnoreCase("SHA1/DSA") |
|
522 |
|| name.equalsIgnoreCase("DSAWithSHA1") |
|
523 |
|| name.equalsIgnoreCase("DSS") |
|
524 |
|| name.equalsIgnoreCase("SHA-1/DSA")) { |
|
525 |
return AlgorithmId.sha1WithDSA_oid; |
|
526 |
} |
|
527 |
if (name.equalsIgnoreCase("SHA1WithRSA") |
|
528 |
|| name.equalsIgnoreCase("SHA1/RSA")) { |
|
529 |
return AlgorithmId.sha1WithRSAEncryption_oid; |
|
530 |
} |
|
531 |
if (name.equalsIgnoreCase("SHA1withECDSA") |
|
532 |
|| name.equalsIgnoreCase("ECDSA")) { |
|
533 |
return AlgorithmId.sha1WithECDSA_oid; |
|
534 |
} |
|
3717
c2ea049a4442
6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents:
2944
diff
changeset
|
535 |
if (name.equalsIgnoreCase("SHA224withECDSA")) { |
c2ea049a4442
6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents:
2944
diff
changeset
|
536 |
return AlgorithmId.sha224WithECDSA_oid; |
c2ea049a4442
6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents:
2944
diff
changeset
|
537 |
} |
c2ea049a4442
6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents:
2944
diff
changeset
|
538 |
if (name.equalsIgnoreCase("SHA256withECDSA")) { |
c2ea049a4442
6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents:
2944
diff
changeset
|
539 |
return AlgorithmId.sha256WithECDSA_oid; |
c2ea049a4442
6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents:
2944
diff
changeset
|
540 |
} |
c2ea049a4442
6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents:
2944
diff
changeset
|
541 |
if (name.equalsIgnoreCase("SHA384withECDSA")) { |
c2ea049a4442
6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents:
2944
diff
changeset
|
542 |
return AlgorithmId.sha384WithECDSA_oid; |
c2ea049a4442
6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents:
2944
diff
changeset
|
543 |
} |
c2ea049a4442
6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents:
2944
diff
changeset
|
544 |
if (name.equalsIgnoreCase("SHA512withECDSA")) { |
c2ea049a4442
6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents:
2944
diff
changeset
|
545 |
return AlgorithmId.sha512WithECDSA_oid; |
c2ea049a4442
6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents:
2944
diff
changeset
|
546 |
} |
2 | 547 |
|
548 |
// See if any of the installed providers supply a mapping from |
|
549 |
// the given algorithm name to an OID string |
|
550 |
String oidString; |
|
551 |
if (!initOidTable) { |
|
552 |
Provider[] provs = Security.getProviders(); |
|
553 |
for (int i=0; i<provs.length; i++) { |
|
554 |
for (Enumeration<Object> enum_ = provs[i].keys(); |
|
555 |
enum_.hasMoreElements(); ) { |
|
556 |
String alias = (String)enum_.nextElement(); |
|
6122
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
557 |
String upperCaseAlias = alias.toUpperCase(Locale.ENGLISH); |
2 | 558 |
int index; |
6122
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
559 |
if (upperCaseAlias.startsWith("ALG.ALIAS") && |
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
560 |
(index=upperCaseAlias.indexOf("OID.", 0)) != -1) { |
2 | 561 |
index += "OID.".length(); |
562 |
if (index == alias.length()) { |
|
563 |
// invalid alias entry |
|
564 |
break; |
|
565 |
} |
|
566 |
if (oidTable == null) { |
|
567 |
oidTable = new HashMap<String,ObjectIdentifier>(); |
|
568 |
} |
|
569 |
oidString = alias.substring(index); |
|
6122
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
570 |
String stdAlgName = provs[i].getProperty(alias); |
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
571 |
if (stdAlgName != null) { |
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
572 |
stdAlgName = stdAlgName.toUpperCase(Locale.ENGLISH); |
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
573 |
} |
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
574 |
if (stdAlgName != null && |
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
575 |
oidTable.get(stdAlgName) == null) { |
2 | 576 |
oidTable.put(stdAlgName, |
577 |
new ObjectIdentifier(oidString)); |
|
578 |
} |
|
579 |
} |
|
580 |
} |
|
581 |
} |
|
6122
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
582 |
|
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
583 |
if (oidTable == null) { |
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
584 |
oidTable = new HashMap<String,ObjectIdentifier>(1); |
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
585 |
} |
2 | 586 |
initOidTable = true; |
587 |
} |
|
588 |
||
6122
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5506
diff
changeset
|
589 |
return oidTable.get(name.toUpperCase(Locale.ENGLISH)); |
2 | 590 |
} |
591 |
||
592 |
private static ObjectIdentifier oid(int ... values) { |
|
593 |
return ObjectIdentifier.newInternal(values); |
|
594 |
} |
|
595 |
||
596 |
private static boolean initOidTable = false; |
|
597 |
private static Map<String,ObjectIdentifier> oidTable; |
|
598 |
private static final Map<ObjectIdentifier,String> nameTable; |
|
599 |
||
600 |
/*****************************************************************/ |
|
601 |
||
602 |
/* |
|
603 |
* HASHING ALGORITHMS |
|
604 |
*/ |
|
605 |
||
606 |
/** |
|
607 |
* Algorithm ID for the MD2 Message Digest Algorthm, from RFC 1319. |
|
608 |
* OID = 1.2.840.113549.2.2 |
|
609 |
*/ |
|
610 |
public static final ObjectIdentifier MD2_oid = |
|
611 |
ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 2, 2}); |
|
612 |
||
613 |
/** |
|
614 |
* Algorithm ID for the MD5 Message Digest Algorthm, from RFC 1321. |
|
615 |
* OID = 1.2.840.113549.2.5 |
|
616 |
*/ |
|
617 |
public static final ObjectIdentifier MD5_oid = |
|
618 |
ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 2, 5}); |
|
619 |
||
620 |
/** |
|
621 |
* Algorithm ID for the SHA1 Message Digest Algorithm, from FIPS 180-1. |
|
622 |
* This is sometimes called "SHA", though that is often confusing since |
|
623 |
* many people refer to FIPS 180 (which has an error) as defining SHA. |
|
624 |
* OID = 1.3.14.3.2.26. Old SHA-0 OID: 1.3.14.3.2.18. |
|
625 |
*/ |
|
626 |
public static final ObjectIdentifier SHA_oid = |
|
627 |
ObjectIdentifier.newInternal(new int[] {1, 3, 14, 3, 2, 26}); |
|
628 |
||
12685 | 629 |
public static final ObjectIdentifier SHA224_oid = |
630 |
ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 4}); |
|
631 |
||
2 | 632 |
public static final ObjectIdentifier SHA256_oid = |
633 |
ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 1}); |
|
634 |
||
635 |
public static final ObjectIdentifier SHA384_oid = |
|
636 |
ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 2}); |
|
637 |
||
638 |
public static final ObjectIdentifier SHA512_oid = |
|
639 |
ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 3}); |
|
640 |
||
641 |
/* |
|
642 |
* COMMON PUBLIC KEY TYPES |
|
643 |
*/ |
|
644 |
private static final int DH_data[] = { 1, 2, 840, 113549, 1, 3, 1 }; |
|
645 |
private static final int DH_PKIX_data[] = { 1, 2, 840, 10046, 2, 1 }; |
|
646 |
private static final int DSA_OIW_data[] = { 1, 3, 14, 3, 2, 12 }; |
|
647 |
private static final int DSA_PKIX_data[] = { 1, 2, 840, 10040, 4, 1 }; |
|
2944
276b6d106714
6570344: Invalid RSA OID in sun.security.x509.AlgorithmId
xuelei
parents:
2
diff
changeset
|
648 |
private static final int RSA_data[] = { 2, 5, 8, 1, 1 }; |
2 | 649 |
private static final int RSAEncryption_data[] = |
650 |
{ 1, 2, 840, 113549, 1, 1, 1 }; |
|
651 |
||
652 |
public static final ObjectIdentifier DH_oid; |
|
653 |
public static final ObjectIdentifier DH_PKIX_oid; |
|
654 |
public static final ObjectIdentifier DSA_oid; |
|
655 |
public static final ObjectIdentifier DSA_OIW_oid; |
|
656 |
public static final ObjectIdentifier EC_oid = oid(1, 2, 840, 10045, 2, 1); |
|
657 |
public static final ObjectIdentifier RSA_oid; |
|
658 |
public static final ObjectIdentifier RSAEncryption_oid; |
|
659 |
||
660 |
/* |
|
661 |
* COMMON SIGNATURE ALGORITHMS |
|
662 |
*/ |
|
663 |
private static final int md2WithRSAEncryption_data[] = |
|
664 |
{ 1, 2, 840, 113549, 1, 1, 2 }; |
|
665 |
private static final int md5WithRSAEncryption_data[] = |
|
666 |
{ 1, 2, 840, 113549, 1, 1, 4 }; |
|
667 |
private static final int sha1WithRSAEncryption_data[] = |
|
668 |
{ 1, 2, 840, 113549, 1, 1, 5 }; |
|
669 |
private static final int sha1WithRSAEncryption_OIW_data[] = |
|
670 |
{ 1, 3, 14, 3, 2, 29 }; |
|
12685 | 671 |
private static final int sha224WithRSAEncryption_data[] = |
672 |
{ 1, 2, 840, 113549, 1, 1, 14 }; |
|
2 | 673 |
private static final int sha256WithRSAEncryption_data[] = |
674 |
{ 1, 2, 840, 113549, 1, 1, 11 }; |
|
675 |
private static final int sha384WithRSAEncryption_data[] = |
|
676 |
{ 1, 2, 840, 113549, 1, 1, 12 }; |
|
677 |
private static final int sha512WithRSAEncryption_data[] = |
|
678 |
{ 1, 2, 840, 113549, 1, 1, 13 }; |
|
679 |
private static final int shaWithDSA_OIW_data[] = |
|
680 |
{ 1, 3, 14, 3, 2, 13 }; |
|
681 |
private static final int sha1WithDSA_OIW_data[] = |
|
682 |
{ 1, 3, 14, 3, 2, 27 }; |
|
683 |
private static final int dsaWithSHA1_PKIX_data[] = |
|
684 |
{ 1, 2, 840, 10040, 4, 3 }; |
|
685 |
||
686 |
public static final ObjectIdentifier md2WithRSAEncryption_oid; |
|
687 |
public static final ObjectIdentifier md5WithRSAEncryption_oid; |
|
688 |
public static final ObjectIdentifier sha1WithRSAEncryption_oid; |
|
689 |
public static final ObjectIdentifier sha1WithRSAEncryption_OIW_oid; |
|
12685 | 690 |
public static final ObjectIdentifier sha224WithRSAEncryption_oid; |
2 | 691 |
public static final ObjectIdentifier sha256WithRSAEncryption_oid; |
692 |
public static final ObjectIdentifier sha384WithRSAEncryption_oid; |
|
693 |
public static final ObjectIdentifier sha512WithRSAEncryption_oid; |
|
694 |
public static final ObjectIdentifier shaWithDSA_OIW_oid; |
|
695 |
public static final ObjectIdentifier sha1WithDSA_OIW_oid; |
|
696 |
public static final ObjectIdentifier sha1WithDSA_oid; |
|
697 |
||
698 |
public static final ObjectIdentifier sha1WithECDSA_oid = |
|
699 |
oid(1, 2, 840, 10045, 4, 1); |
|
700 |
public static final ObjectIdentifier sha224WithECDSA_oid = |
|
701 |
oid(1, 2, 840, 10045, 4, 3, 1); |
|
702 |
public static final ObjectIdentifier sha256WithECDSA_oid = |
|
703 |
oid(1, 2, 840, 10045, 4, 3, 2); |
|
704 |
public static final ObjectIdentifier sha384WithECDSA_oid = |
|
705 |
oid(1, 2, 840, 10045, 4, 3, 3); |
|
706 |
public static final ObjectIdentifier sha512WithECDSA_oid = |
|
707 |
oid(1, 2, 840, 10045, 4, 3, 4); |
|
708 |
public static final ObjectIdentifier specifiedWithECDSA_oid = |
|
709 |
oid(1, 2, 840, 10045, 4, 3); |
|
710 |
||
711 |
/** |
|
712 |
* Algorithm ID for the PBE encryption algorithms from PKCS#5 and |
|
713 |
* PKCS#12. |
|
714 |
*/ |
|
715 |
public static final ObjectIdentifier pbeWithMD5AndDES_oid = |
|
716 |
ObjectIdentifier.newInternal(new int[]{1, 2, 840, 113549, 1, 5, 3}); |
|
717 |
public static final ObjectIdentifier pbeWithMD5AndRC2_oid = |
|
718 |
ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 5, 6}); |
|
719 |
public static final ObjectIdentifier pbeWithSHA1AndDES_oid = |
|
720 |
ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 5, 10}); |
|
721 |
public static final ObjectIdentifier pbeWithSHA1AndRC2_oid = |
|
722 |
ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 5, 11}); |
|
723 |
public static ObjectIdentifier pbeWithSHA1AndDESede_oid = |
|
724 |
ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 12, 1, 3}); |
|
725 |
public static ObjectIdentifier pbeWithSHA1AndRC2_40_oid = |
|
726 |
ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 12, 1, 6}); |
|
727 |
||
728 |
||
729 |
static { |
|
730 |
/* |
|
731 |
* Note the preferred OIDs are named simply with no "OIW" or |
|
732 |
* "PKIX" in them, even though they may point to data from these |
|
733 |
* specs; e.g. SHA_oid, DH_oid, DSA_oid, SHA1WithDSA_oid... |
|
734 |
*/ |
|
735 |
/** |
|
736 |
* Algorithm ID for Diffie Hellman Key agreement, from PKCS #3. |
|
737 |
* Parameters include public values P and G, and may optionally specify |
|
738 |
* the length of the private key X. Alternatively, algorithm parameters |
|
739 |
* may be derived from another source such as a Certificate Authority's |
|
740 |
* certificate. |
|
741 |
* OID = 1.2.840.113549.1.3.1 |
|
742 |
*/ |
|
743 |
DH_oid = ObjectIdentifier.newInternal(DH_data); |
|
744 |
||
745 |
/** |
|
746 |
* Algorithm ID for the Diffie Hellman Key Agreement (DH), from RFC 3279. |
|
747 |
* Parameters may include public values P and G. |
|
748 |
* OID = 1.2.840.10046.2.1 |
|
749 |
*/ |
|
750 |
DH_PKIX_oid = ObjectIdentifier.newInternal(DH_PKIX_data); |
|
751 |
||
752 |
/** |
|
753 |
* Algorithm ID for the Digital Signing Algorithm (DSA), from the |
|
754 |
* NIST OIW Stable Agreements part 12. |
|
755 |
* Parameters may include public values P, Q, and G; or these may be |
|
756 |
* derived from |
|
757 |
* another source such as a Certificate Authority's certificate. |
|
758 |
* OID = 1.3.14.3.2.12 |
|
759 |
*/ |
|
760 |
DSA_OIW_oid = ObjectIdentifier.newInternal(DSA_OIW_data); |
|
761 |
||
762 |
/** |
|
763 |
* Algorithm ID for the Digital Signing Algorithm (DSA), from RFC 3279. |
|
764 |
* Parameters may include public values P, Q, and G; or these may be |
|
765 |
* derived from another source such as a Certificate Authority's |
|
766 |
* certificate. |
|
767 |
* OID = 1.2.840.10040.4.1 |
|
768 |
*/ |
|
769 |
DSA_oid = ObjectIdentifier.newInternal(DSA_PKIX_data); |
|
770 |
||
771 |
/** |
|
772 |
* Algorithm ID for RSA keys used for any purpose, as defined in X.509. |
|
773 |
* The algorithm parameter is a single value, the number of bits in the |
|
774 |
* public modulus. |
|
2944
276b6d106714
6570344: Invalid RSA OID in sun.security.x509.AlgorithmId
xuelei
parents:
2
diff
changeset
|
775 |
* OID = 2.5.8.1.1 |
2 | 776 |
*/ |
777 |
RSA_oid = ObjectIdentifier.newInternal(RSA_data); |
|
778 |
||
779 |
/** |
|
780 |
* Algorithm ID for RSA keys used with RSA encryption, as defined |
|
781 |
* in PKCS #1. There are no parameters associated with this algorithm. |
|
782 |
* OID = 1.2.840.113549.1.1.1 |
|
783 |
*/ |
|
784 |
RSAEncryption_oid = ObjectIdentifier.newInternal(RSAEncryption_data); |
|
785 |
||
786 |
/** |
|
787 |
* Identifies a signing algorithm where an MD2 digest is encrypted |
|
788 |
* using an RSA private key; defined in PKCS #1. Use of this |
|
789 |
* signing algorithm is discouraged due to MD2 vulnerabilities. |
|
790 |
* OID = 1.2.840.113549.1.1.2 |
|
791 |
*/ |
|
792 |
md2WithRSAEncryption_oid = |
|
793 |
ObjectIdentifier.newInternal(md2WithRSAEncryption_data); |
|
794 |
||
795 |
/** |
|
796 |
* Identifies a signing algorithm where an MD5 digest is |
|
797 |
* encrypted using an RSA private key; defined in PKCS #1. |
|
798 |
* OID = 1.2.840.113549.1.1.4 |
|
799 |
*/ |
|
800 |
md5WithRSAEncryption_oid = |
|
801 |
ObjectIdentifier.newInternal(md5WithRSAEncryption_data); |
|
802 |
||
803 |
/** |
|
804 |
* Identifies a signing algorithm where a SHA1 digest is |
|
805 |
* encrypted using an RSA private key; defined by RSA DSI. |
|
806 |
* OID = 1.2.840.113549.1.1.5 |
|
807 |
*/ |
|
808 |
sha1WithRSAEncryption_oid = |
|
809 |
ObjectIdentifier.newInternal(sha1WithRSAEncryption_data); |
|
810 |
||
811 |
/** |
|
812 |
* Identifies a signing algorithm where a SHA1 digest is |
|
813 |
* encrypted using an RSA private key; defined in NIST OIW. |
|
814 |
* OID = 1.3.14.3.2.29 |
|
815 |
*/ |
|
816 |
sha1WithRSAEncryption_OIW_oid = |
|
817 |
ObjectIdentifier.newInternal(sha1WithRSAEncryption_OIW_data); |
|
818 |
||
819 |
/** |
|
12685 | 820 |
* Identifies a signing algorithm where a SHA224 digest is |
821 |
* encrypted using an RSA private key; defined by PKCS #1. |
|
822 |
* OID = 1.2.840.113549.1.1.14 |
|
823 |
*/ |
|
824 |
sha224WithRSAEncryption_oid = |
|
825 |
ObjectIdentifier.newInternal(sha224WithRSAEncryption_data); |
|
826 |
||
827 |
/** |
|
2 | 828 |
* Identifies a signing algorithm where a SHA256 digest is |
829 |
* encrypted using an RSA private key; defined by PKCS #1. |
|
830 |
* OID = 1.2.840.113549.1.1.11 |
|
831 |
*/ |
|
832 |
sha256WithRSAEncryption_oid = |
|
833 |
ObjectIdentifier.newInternal(sha256WithRSAEncryption_data); |
|
834 |
||
835 |
/** |
|
836 |
* Identifies a signing algorithm where a SHA384 digest is |
|
837 |
* encrypted using an RSA private key; defined by PKCS #1. |
|
838 |
* OID = 1.2.840.113549.1.1.12 |
|
839 |
*/ |
|
840 |
sha384WithRSAEncryption_oid = |
|
841 |
ObjectIdentifier.newInternal(sha384WithRSAEncryption_data); |
|
842 |
||
843 |
/** |
|
844 |
* Identifies a signing algorithm where a SHA512 digest is |
|
845 |
* encrypted using an RSA private key; defined by PKCS #1. |
|
846 |
* OID = 1.2.840.113549.1.1.13 |
|
847 |
*/ |
|
848 |
sha512WithRSAEncryption_oid = |
|
849 |
ObjectIdentifier.newInternal(sha512WithRSAEncryption_data); |
|
850 |
||
851 |
/** |
|
852 |
* Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a |
|
853 |
* SHA digest is signed using the Digital Signing Algorithm (DSA). |
|
854 |
* This should not be used. |
|
855 |
* OID = 1.3.14.3.2.13 |
|
856 |
*/ |
|
857 |
shaWithDSA_OIW_oid = ObjectIdentifier.newInternal(shaWithDSA_OIW_data); |
|
858 |
||
859 |
/** |
|
860 |
* Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a |
|
861 |
* SHA1 digest is signed using the Digital Signing Algorithm (DSA). |
|
862 |
* OID = 1.3.14.3.2.27 |
|
863 |
*/ |
|
864 |
sha1WithDSA_OIW_oid = ObjectIdentifier.newInternal(sha1WithDSA_OIW_data); |
|
865 |
||
866 |
/** |
|
867 |
* Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a |
|
868 |
* SHA1 digest is signed using the Digital Signing Algorithm (DSA). |
|
869 |
* OID = 1.2.840.10040.4.3 |
|
870 |
*/ |
|
871 |
sha1WithDSA_oid = ObjectIdentifier.newInternal(dsaWithSHA1_PKIX_data); |
|
872 |
||
873 |
nameTable = new HashMap<ObjectIdentifier,String>(); |
|
874 |
nameTable.put(MD5_oid, "MD5"); |
|
875 |
nameTable.put(MD2_oid, "MD2"); |
|
13361
bda5c2354fc6
7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents:
12685
diff
changeset
|
876 |
nameTable.put(SHA_oid, "SHA-1"); |
bda5c2354fc6
7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents:
12685
diff
changeset
|
877 |
nameTable.put(SHA224_oid, "SHA-224"); |
bda5c2354fc6
7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents:
12685
diff
changeset
|
878 |
nameTable.put(SHA256_oid, "SHA-256"); |
bda5c2354fc6
7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents:
12685
diff
changeset
|
879 |
nameTable.put(SHA384_oid, "SHA-384"); |
bda5c2354fc6
7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents:
12685
diff
changeset
|
880 |
nameTable.put(SHA512_oid, "SHA-512"); |
2 | 881 |
nameTable.put(RSAEncryption_oid, "RSA"); |
882 |
nameTable.put(RSA_oid, "RSA"); |
|
883 |
nameTable.put(DH_oid, "Diffie-Hellman"); |
|
884 |
nameTable.put(DH_PKIX_oid, "Diffie-Hellman"); |
|
885 |
nameTable.put(DSA_oid, "DSA"); |
|
886 |
nameTable.put(DSA_OIW_oid, "DSA"); |
|
887 |
nameTable.put(EC_oid, "EC"); |
|
888 |
nameTable.put(sha1WithECDSA_oid, "SHA1withECDSA"); |
|
889 |
nameTable.put(sha224WithECDSA_oid, "SHA224withECDSA"); |
|
890 |
nameTable.put(sha256WithECDSA_oid, "SHA256withECDSA"); |
|
891 |
nameTable.put(sha384WithECDSA_oid, "SHA384withECDSA"); |
|
892 |
nameTable.put(sha512WithECDSA_oid, "SHA512withECDSA"); |
|
893 |
nameTable.put(md5WithRSAEncryption_oid, "MD5withRSA"); |
|
894 |
nameTable.put(md2WithRSAEncryption_oid, "MD2withRSA"); |
|
895 |
nameTable.put(sha1WithDSA_oid, "SHA1withDSA"); |
|
896 |
nameTable.put(sha1WithDSA_OIW_oid, "SHA1withDSA"); |
|
897 |
nameTable.put(shaWithDSA_OIW_oid, "SHA1withDSA"); |
|
898 |
nameTable.put(sha1WithRSAEncryption_oid, "SHA1withRSA"); |
|
899 |
nameTable.put(sha1WithRSAEncryption_OIW_oid, "SHA1withRSA"); |
|
12685 | 900 |
nameTable.put(sha224WithRSAEncryption_oid, "SHA224withRSA"); |
2 | 901 |
nameTable.put(sha256WithRSAEncryption_oid, "SHA256withRSA"); |
902 |
nameTable.put(sha384WithRSAEncryption_oid, "SHA384withRSA"); |
|
903 |
nameTable.put(sha512WithRSAEncryption_oid, "SHA512withRSA"); |
|
904 |
nameTable.put(pbeWithMD5AndDES_oid, "PBEWithMD5AndDES"); |
|
905 |
nameTable.put(pbeWithMD5AndRC2_oid, "PBEWithMD5AndRC2"); |
|
906 |
nameTable.put(pbeWithSHA1AndDES_oid, "PBEWithSHA1AndDES"); |
|
907 |
nameTable.put(pbeWithSHA1AndRC2_oid, "PBEWithSHA1AndRC2"); |
|
908 |
nameTable.put(pbeWithSHA1AndDESede_oid, "PBEWithSHA1AndDESede"); |
|
909 |
nameTable.put(pbeWithSHA1AndRC2_40_oid, "PBEWithSHA1AndRC2_40"); |
|
910 |
} |
|
4152
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
911 |
|
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
912 |
/** |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
913 |
* Creates a signature algorithm name from a digest algorithm |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
914 |
* name and a encryption algorithm name. |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
915 |
*/ |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
916 |
public static String makeSigAlg(String digAlg, String encAlg) { |
13361
bda5c2354fc6
7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents:
12685
diff
changeset
|
917 |
digAlg = digAlg.replace("-", ""); |
bda5c2354fc6
7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents:
12685
diff
changeset
|
918 |
if (encAlg.equalsIgnoreCase("EC")) encAlg = "ECDSA"; |
4152
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
919 |
|
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
920 |
return digAlg + "with" + encAlg; |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
921 |
} |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
922 |
|
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
923 |
/** |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
924 |
* Extracts the encryption algorithm name from a signature |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
925 |
* algorithm name. |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
926 |
*/ |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
927 |
public static String getEncAlgFromSigAlg(String signatureAlgorithm) { |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
928 |
signatureAlgorithm = signatureAlgorithm.toUpperCase(Locale.ENGLISH); |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
929 |
int with = signatureAlgorithm.indexOf("WITH"); |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
930 |
String keyAlgorithm = null; |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
931 |
if (with > 0) { |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
932 |
int and = signatureAlgorithm.indexOf("AND", with + 4); |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
933 |
if (and > 0) { |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
934 |
keyAlgorithm = signatureAlgorithm.substring(with + 4, and); |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
935 |
} else { |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
936 |
keyAlgorithm = signatureAlgorithm.substring(with + 4); |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
937 |
} |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
938 |
if (keyAlgorithm.equalsIgnoreCase("ECDSA")) { |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
939 |
keyAlgorithm = "EC"; |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
940 |
} |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
941 |
} |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
942 |
return keyAlgorithm; |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
943 |
} |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
944 |
|
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
945 |
/** |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
946 |
* Extracts the digest algorithm name from a signature |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
947 |
* algorithm name. |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
948 |
*/ |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
949 |
public static String getDigAlgFromSigAlg(String signatureAlgorithm) { |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
950 |
signatureAlgorithm = signatureAlgorithm.toUpperCase(Locale.ENGLISH); |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
951 |
int with = signatureAlgorithm.indexOf("WITH"); |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
952 |
if (with > 0) { |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
953 |
return signatureAlgorithm.substring(0, with); |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
954 |
} |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
955 |
return null; |
bc36a9f01ac6
6870812: enhance security tools to use ECC algorithms
weijun
parents:
3717
diff
changeset
|
956 |
} |
2 | 957 |
} |