author | vinnie |
Mon, 05 Oct 2009 23:42:48 +0100 | |
changeset 3957 | c8fdb8fad795 |
parent 715 | f16baef3a20e |
child 4236 | 02f52c723b79 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
3957
c8fdb8fad795
6885204: JSSE should not require Kerberos to be present
vinnie
parents:
715
diff
changeset
|
2 |
* Copyright 2002-2009 Sun Microsystems, Inc. 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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
||
27 |
package sun.security.ssl; |
|
28 |
||
29 |
import java.util.*; |
|
30 |
||
31 |
import java.security.NoSuchAlgorithmException; |
|
32 |
import java.security.InvalidKeyException; |
|
33 |
||
34 |
import javax.crypto.SecretKey; |
|
35 |
import javax.crypto.spec.IvParameterSpec; |
|
36 |
import javax.crypto.spec.SecretKeySpec; |
|
37 |
||
38 |
import sun.security.ssl.CipherSuite.*; |
|
39 |
import static sun.security.ssl.CipherSuite.KeyExchange.*; |
|
40 |
import static sun.security.ssl.JsseJce.*; |
|
41 |
||
42 |
/** |
|
43 |
* An SSL/TLS CipherSuite. Constants for the standard key exchange, cipher, |
|
44 |
* and mac algorithms are also defined in this class. |
|
45 |
* |
|
46 |
* The CipherSuite class and the inner classes defined in this file roughly |
|
47 |
* follow the type safe enum pattern described in Effective Java. This means: |
|
48 |
* |
|
49 |
* . instances are immutable, classes are final |
|
50 |
* |
|
51 |
* . there is a unique instance of every value, i.e. there are never two |
|
52 |
* instances representing the same CipherSuite, etc. This means equality |
|
53 |
* tests can be performed using == instead of equals() (although that works |
|
54 |
* as well). [A minor exception are *unsupported* CipherSuites read from a |
|
55 |
* handshake message, but this is usually irrelevant] |
|
56 |
* |
|
57 |
* . instances are obtained using the static valueOf() factory methods. |
|
58 |
* |
|
59 |
* . properties are defined as final variables and made available as |
|
60 |
* package private variables without method accessors |
|
61 |
* |
|
62 |
* . if the member variable allowed is false, the given algorithm is either |
|
63 |
* unavailable or disabled at compile time |
|
64 |
* |
|
65 |
*/ |
|
66 |
final class CipherSuite implements Comparable { |
|
67 |
||
68 |
// minimum priority for supported CipherSuites |
|
69 |
final static int SUPPORTED_SUITES_PRIORITY = 1; |
|
70 |
||
71 |
// minimum priority for default enabled CipherSuites |
|
72 |
final static int DEFAULT_SUITES_PRIORITY = 300; |
|
73 |
||
74 |
// Flag indicating if CipherSuite availability can change dynamically. |
|
75 |
// This is the case when we rely on a JCE cipher implementation that |
|
76 |
// may not be available in the installed JCE providers. |
|
3957
c8fdb8fad795
6885204: JSSE should not require Kerberos to be present
vinnie
parents:
715
diff
changeset
|
77 |
// It is true because we might not have an ECC or Kerberos implementation. |
2 | 78 |
final static boolean DYNAMIC_AVAILABILITY = true; |
79 |
||
80 |
private final static boolean ALLOW_ECC = Debug.getBooleanProperty |
|
81 |
("com.sun.net.ssl.enableECC", true); |
|
82 |
||
83 |
// Map Integer(id) -> CipherSuite |
|
84 |
// contains all known CipherSuites |
|
85 |
private final static Map<Integer,CipherSuite> idMap; |
|
86 |
||
87 |
// Map String(name) -> CipherSuite |
|
88 |
// contains only supported CipherSuites (i.e. allowed == true) |
|
89 |
private final static Map<String,CipherSuite> nameMap; |
|
90 |
||
91 |
// Protocol defined CipherSuite name, e.g. SSL_RSA_WITH_RC4_128_MD5 |
|
92 |
// we use TLS_* only for new CipherSuites, still SSL_* for old ones |
|
93 |
final String name; |
|
94 |
||
95 |
// id in 16 bit MSB format, i.e. 0x0004 for SSL_RSA_WITH_RC4_128_MD5 |
|
96 |
final int id; |
|
97 |
||
98 |
// priority for the internal default preference order. the higher the |
|
99 |
// better. Each supported CipherSuite *must* have a unique priority. |
|
100 |
// Ciphersuites with priority >= DEFAULT_SUITES_PRIORITY are enabled |
|
101 |
// by default |
|
102 |
final int priority; |
|
103 |
||
104 |
// key exchange, bulk cipher, and mac algorithms. See those classes below. |
|
105 |
final KeyExchange keyExchange; |
|
106 |
final BulkCipher cipher; |
|
107 |
final MacAlg macAlg; |
|
108 |
||
109 |
// whether a CipherSuite qualifies as exportable under 512/40 bit rules. |
|
110 |
final boolean exportable; |
|
111 |
||
112 |
// true iff implemented and enabled at compile time |
|
113 |
final boolean allowed; |
|
114 |
||
115 |
private CipherSuite(String name, int id, int priority, |
|
116 |
KeyExchange keyExchange, BulkCipher cipher, boolean allowed) { |
|
117 |
this.name = name; |
|
118 |
this.id = id; |
|
119 |
this.priority = priority; |
|
120 |
this.keyExchange = keyExchange; |
|
121 |
this.cipher = cipher; |
|
122 |
this.exportable = cipher.exportable; |
|
123 |
if (name.endsWith("_MD5")) { |
|
124 |
macAlg = M_MD5; |
|
125 |
} else if (name.endsWith("_SHA")) { |
|
126 |
macAlg = M_SHA; |
|
127 |
} else if (name.endsWith("_NULL")) { |
|
128 |
macAlg = M_NULL; |
|
129 |
} else { |
|
130 |
throw new IllegalArgumentException |
|
131 |
("Unknown MAC algorithm for ciphersuite " + name); |
|
132 |
} |
|
133 |
||
134 |
allowed &= keyExchange.allowed; |
|
135 |
allowed &= cipher.allowed; |
|
136 |
this.allowed = allowed; |
|
137 |
} |
|
138 |
||
139 |
private CipherSuite(String name, int id) { |
|
140 |
this.name = name; |
|
141 |
this.id = id; |
|
142 |
this.allowed = false; |
|
143 |
||
144 |
this.priority = 0; |
|
145 |
this.keyExchange = null; |
|
146 |
this.cipher = null; |
|
147 |
this.macAlg = null; |
|
148 |
this.exportable = false; |
|
149 |
} |
|
150 |
||
151 |
/** |
|
152 |
* Return whether this CipherSuite is available for use. A |
|
153 |
* CipherSuite may be unavailable even if it is supported |
|
154 |
* (i.e. allowed == true) if the required JCE cipher is not installed. |
|
155 |
* In some configuration, this situation may change over time, call |
|
156 |
* CipherSuiteList.clearAvailableCache() before this method to obtain |
|
157 |
* the most current status. |
|
158 |
*/ |
|
159 |
boolean isAvailable() { |
|
160 |
return allowed && keyExchange.isAvailable() && cipher.isAvailable(); |
|
161 |
} |
|
162 |
||
163 |
/** |
|
164 |
* Compares CipherSuites based on their priority. Has the effect of |
|
165 |
* sorting CipherSuites when put in a sorted collection, which is |
|
166 |
* used by CipherSuiteList. Follows standard Comparable contract. |
|
167 |
* |
|
168 |
* Note that for unsupported CipherSuites parsed from a handshake |
|
169 |
* message we violate the equals() contract. |
|
170 |
*/ |
|
171 |
public int compareTo(Object o) { |
|
172 |
return ((CipherSuite)o).priority - priority; |
|
173 |
} |
|
174 |
||
175 |
/** |
|
176 |
* Returns this.name. |
|
177 |
*/ |
|
178 |
public String toString() { |
|
179 |
return name; |
|
180 |
} |
|
181 |
||
182 |
/** |
|
183 |
* Return a CipherSuite for the given name. The returned CipherSuite |
|
184 |
* is supported by this implementation but may not actually be |
|
185 |
* currently useable. See isAvailable(). |
|
186 |
* |
|
187 |
* @exception IllegalArgumentException if the CipherSuite is unknown or |
|
188 |
* unsupported. |
|
189 |
*/ |
|
190 |
static CipherSuite valueOf(String s) { |
|
191 |
if (s == null) { |
|
192 |
throw new IllegalArgumentException("Name must not be null"); |
|
193 |
} |
|
51 | 194 |
CipherSuite c = nameMap.get(s); |
2 | 195 |
if ((c == null) || (c.allowed == false)) { |
196 |
throw new IllegalArgumentException("Unsupported ciphersuite " + s); |
|
197 |
} |
|
198 |
return c; |
|
199 |
} |
|
200 |
||
201 |
/** |
|
202 |
* Return a CipherSuite with the given ID. A temporary object is |
|
203 |
* constructed if the ID is unknown. Use isAvailable() to verify that |
|
204 |
* the CipherSuite can actually be used. |
|
205 |
*/ |
|
206 |
static CipherSuite valueOf(int id1, int id2) { |
|
207 |
id1 &= 0xff; |
|
208 |
id2 &= 0xff; |
|
209 |
int id = (id1 << 8) | id2; |
|
210 |
CipherSuite c = idMap.get(id); |
|
211 |
if (c == null) { |
|
212 |
String h1 = Integer.toString(id1, 16); |
|
213 |
String h2 = Integer.toString(id2, 16); |
|
214 |
c = new CipherSuite("Unknown 0x" + h1 + ":0x" + h2, id); |
|
215 |
} |
|
216 |
return c; |
|
217 |
} |
|
218 |
||
219 |
// for use by CipherSuiteList only |
|
220 |
static Collection<CipherSuite> allowedCipherSuites() { |
|
221 |
return nameMap.values(); |
|
222 |
} |
|
223 |
||
224 |
private static void add(String name, int id, int priority, |
|
225 |
KeyExchange keyExchange, BulkCipher cipher, boolean allowed) { |
|
226 |
CipherSuite c = new CipherSuite(name, id, priority, keyExchange, |
|
227 |
cipher, allowed); |
|
228 |
if (idMap.put(id, c) != null) { |
|
229 |
throw new RuntimeException("Duplicate ciphersuite definition: " |
|
230 |
+ id + ", " + name); |
|
231 |
} |
|
232 |
if (c.allowed) { |
|
233 |
if (nameMap.put(name, c) != null) { |
|
234 |
throw new RuntimeException("Duplicate ciphersuite definition: " |
|
235 |
+ id + ", " + name); |
|
236 |
} |
|
237 |
} |
|
238 |
} |
|
239 |
||
240 |
private static void add(String name, int id) { |
|
241 |
CipherSuite c = new CipherSuite(name, id); |
|
242 |
if (idMap.put(id, c) != null) { |
|
243 |
throw new RuntimeException("Duplicate ciphersuite definition: " |
|
244 |
+ id + ", " + name); |
|
245 |
} |
|
246 |
} |
|
247 |
||
248 |
/** |
|
249 |
* An SSL/TLS key exchange algorithm. |
|
250 |
*/ |
|
251 |
static enum KeyExchange { |
|
252 |
||
253 |
// key exchange algorithms |
|
254 |
K_NULL ("NULL", false), |
|
255 |
K_RSA ("RSA", true), |
|
256 |
K_RSA_EXPORT ("RSA_EXPORT", true), |
|
257 |
K_DH_RSA ("DH_RSA", false), |
|
258 |
K_DH_DSS ("DH_DSS", false), |
|
259 |
K_DHE_DSS ("DHE_DSS", true), |
|
260 |
K_DHE_RSA ("DHE_RSA", true), |
|
261 |
K_DH_ANON ("DH_anon", true), |
|
262 |
||
263 |
K_ECDH_ECDSA ("ECDH_ECDSA", ALLOW_ECC), |
|
264 |
K_ECDH_RSA ("ECDH_RSA", ALLOW_ECC), |
|
265 |
K_ECDHE_ECDSA("ECDHE_ECDSA", ALLOW_ECC), |
|
266 |
K_ECDHE_RSA ("ECDHE_RSA", ALLOW_ECC), |
|
267 |
K_ECDH_ANON ("ECDH_anon", ALLOW_ECC), |
|
268 |
||
269 |
// Kerberos cipher suites |
|
270 |
K_KRB5 ("KRB5", true), |
|
271 |
K_KRB5_EXPORT("KRB5_EXPORT", true); |
|
272 |
||
273 |
// name of the key exchange algorithm, e.g. DHE_DSS |
|
274 |
final String name; |
|
275 |
final boolean allowed; |
|
276 |
private final boolean alwaysAvailable; |
|
277 |
||
278 |
KeyExchange(String name, boolean allowed) { |
|
279 |
this.name = name; |
|
280 |
this.allowed = allowed; |
|
3957
c8fdb8fad795
6885204: JSSE should not require Kerberos to be present
vinnie
parents:
715
diff
changeset
|
281 |
this.alwaysAvailable = allowed && |
c8fdb8fad795
6885204: JSSE should not require Kerberos to be present
vinnie
parents:
715
diff
changeset
|
282 |
(!name.startsWith("EC")) && (!name.startsWith("KRB")); |
2 | 283 |
} |
284 |
||
285 |
boolean isAvailable() { |
|
286 |
if (alwaysAvailable) { |
|
287 |
return true; |
|
288 |
} |
|
3957
c8fdb8fad795
6885204: JSSE should not require Kerberos to be present
vinnie
parents:
715
diff
changeset
|
289 |
|
c8fdb8fad795
6885204: JSSE should not require Kerberos to be present
vinnie
parents:
715
diff
changeset
|
290 |
if (name.startsWith("EC")) { |
c8fdb8fad795
6885204: JSSE should not require Kerberos to be present
vinnie
parents:
715
diff
changeset
|
291 |
return (allowed && JsseJce.isEcAvailable()); |
c8fdb8fad795
6885204: JSSE should not require Kerberos to be present
vinnie
parents:
715
diff
changeset
|
292 |
} else if (name.startsWith("KRB")) { |
c8fdb8fad795
6885204: JSSE should not require Kerberos to be present
vinnie
parents:
715
diff
changeset
|
293 |
return (allowed && JsseJce.isKerberosAvailable()); |
c8fdb8fad795
6885204: JSSE should not require Kerberos to be present
vinnie
parents:
715
diff
changeset
|
294 |
} else { |
c8fdb8fad795
6885204: JSSE should not require Kerberos to be present
vinnie
parents:
715
diff
changeset
|
295 |
return allowed; |
c8fdb8fad795
6885204: JSSE should not require Kerberos to be present
vinnie
parents:
715
diff
changeset
|
296 |
} |
2 | 297 |
} |
298 |
||
299 |
public String toString() { |
|
300 |
return name; |
|
301 |
} |
|
302 |
} |
|
303 |
||
304 |
/** |
|
305 |
* An SSL/TLS bulk cipher algorithm. One instance per combination of |
|
306 |
* cipher and key length. |
|
307 |
* |
|
308 |
* Also contains a factory method to obtain in initialized CipherBox |
|
309 |
* for this algorithm. |
|
310 |
*/ |
|
311 |
final static class BulkCipher { |
|
312 |
||
313 |
// Map BulkCipher -> Boolean(available) |
|
314 |
private final static Map<BulkCipher,Boolean> availableCache = |
|
315 |
new HashMap<BulkCipher,Boolean>(8); |
|
316 |
||
317 |
// descriptive name including key size, e.g. AES/128 |
|
318 |
final String description; |
|
319 |
||
320 |
// JCE cipher transformation string, e.g. AES/CBC/NoPadding |
|
321 |
final String transformation; |
|
322 |
||
323 |
// algorithm name, e.g. AES |
|
324 |
final String algorithm; |
|
325 |
||
326 |
// supported and compile time enabled. Also see isAvailable() |
|
327 |
final boolean allowed; |
|
328 |
||
329 |
// number of bytes of entropy in the key |
|
330 |
final int keySize; |
|
331 |
||
332 |
// length of the actual cipher key in bytes. |
|
333 |
// for non-exportable ciphers, this is the same as keySize |
|
334 |
final int expandedKeySize; |
|
335 |
||
336 |
// size of the IV (also block size) |
|
337 |
final int ivSize; |
|
338 |
||
339 |
// exportable under 512/40 bit rules |
|
340 |
final boolean exportable; |
|
341 |
||
342 |
BulkCipher(String transformation, int keySize, |
|
343 |
int expandedKeySize, int ivSize, boolean allowed) { |
|
344 |
this.transformation = transformation; |
|
345 |
this.algorithm = transformation.split("/")[0]; |
|
346 |
this.description = this.algorithm + "/" + (keySize << 3); |
|
347 |
this.keySize = keySize; |
|
348 |
this.ivSize = ivSize; |
|
349 |
this.allowed = allowed; |
|
350 |
||
351 |
this.expandedKeySize = expandedKeySize; |
|
352 |
this.exportable = true; |
|
353 |
} |
|
354 |
||
355 |
BulkCipher(String transformation, int keySize, int ivSize, boolean allowed) { |
|
356 |
this.transformation = transformation; |
|
357 |
this.algorithm = transformation.split("/")[0]; |
|
358 |
this.description = this.algorithm + "/" + (keySize << 3); |
|
359 |
this.keySize = keySize; |
|
360 |
this.ivSize = ivSize; |
|
361 |
this.allowed = allowed; |
|
362 |
||
363 |
this.expandedKeySize = keySize; |
|
364 |
this.exportable = false; |
|
365 |
} |
|
366 |
||
367 |
/** |
|
368 |
* Return an initialized CipherBox for this BulkCipher. |
|
369 |
* IV must be null for stream ciphers. |
|
370 |
* |
|
371 |
* @exception NoSuchAlgorithmException if anything goes wrong |
|
372 |
*/ |
|
373 |
CipherBox newCipher(ProtocolVersion version, SecretKey key, IvParameterSpec iv, |
|
374 |
boolean encrypt) throws NoSuchAlgorithmException { |
|
375 |
return CipherBox.newCipherBox(version, this, key, iv, encrypt); |
|
376 |
} |
|
377 |
||
378 |
/** |
|
379 |
* Test if this bulk cipher is available. For use by CipherSuite. |
|
380 |
* |
|
381 |
* Currently all supported ciphers except AES are always available |
|
382 |
* via the JSSE internal implementations. We also assume AES/128 |
|
383 |
* is always available since it is shipped with the SunJCE provider. |
|
384 |
* However, AES/256 is unavailable when the default JCE policy |
|
385 |
* jurisdiction files are installed because of key length restrictions. |
|
386 |
*/ |
|
387 |
boolean isAvailable() { |
|
388 |
if (allowed == false) { |
|
389 |
return false; |
|
390 |
} |
|
391 |
if (this == B_AES_256) { |
|
392 |
return isAvailable(this); |
|
393 |
} |
|
394 |
// always available |
|
395 |
return true; |
|
396 |
} |
|
397 |
||
398 |
// for use by CipherSuiteList.clearAvailableCache(); |
|
399 |
static synchronized void clearAvailableCache() { |
|
400 |
if (DYNAMIC_AVAILABILITY) { |
|
401 |
availableCache.clear(); |
|
402 |
} |
|
403 |
} |
|
404 |
||
405 |
private static synchronized boolean isAvailable(BulkCipher cipher) { |
|
51 | 406 |
Boolean b = availableCache.get(cipher); |
2 | 407 |
if (b == null) { |
408 |
try { |
|
409 |
SecretKey key = new SecretKeySpec |
|
410 |
(new byte[cipher.expandedKeySize], cipher.algorithm); |
|
411 |
IvParameterSpec iv = new IvParameterSpec(new byte[cipher.ivSize]); |
|
412 |
cipher.newCipher(ProtocolVersion.DEFAULT, key, iv, true); |
|
413 |
b = Boolean.TRUE; |
|
414 |
} catch (NoSuchAlgorithmException e) { |
|
415 |
b = Boolean.FALSE; |
|
416 |
} |
|
417 |
availableCache.put(cipher, b); |
|
418 |
} |
|
419 |
return b.booleanValue(); |
|
420 |
} |
|
421 |
||
422 |
public String toString() { |
|
423 |
return description; |
|
424 |
} |
|
425 |
} |
|
426 |
||
427 |
/** |
|
428 |
* An SSL/TLS key MAC algorithm. |
|
429 |
* |
|
430 |
* Also contains a factory method to obtain in initialized MAC |
|
431 |
* for this algorithm. |
|
432 |
*/ |
|
433 |
final static class MacAlg { |
|
434 |
||
435 |
// descriptive name, e.g. MD5 |
|
436 |
final String name; |
|
437 |
||
438 |
// size of the MAC value (and MAC key) in bytes |
|
439 |
final int size; |
|
440 |
||
441 |
MacAlg(String name, int size) { |
|
442 |
this.name = name; |
|
443 |
this.size = size; |
|
444 |
} |
|
445 |
||
446 |
/** |
|
447 |
* Return an initialized MAC for this MacAlg. ProtocolVersion |
|
448 |
* must either be SSL30 (SSLv3 custom MAC) or TLS10 (std. HMAC). |
|
449 |
* |
|
450 |
* @exception NoSuchAlgorithmException if anything goes wrong |
|
451 |
*/ |
|
452 |
MAC newMac(ProtocolVersion protocolVersion, SecretKey secret) |
|
453 |
throws NoSuchAlgorithmException, InvalidKeyException { |
|
454 |
return new MAC(this, protocolVersion, secret); |
|
455 |
} |
|
456 |
||
457 |
public String toString() { |
|
458 |
return name; |
|
459 |
} |
|
460 |
} |
|
461 |
||
462 |
// export strength ciphers |
|
463 |
final static BulkCipher B_NULL = new BulkCipher("NULL", 0, 0, 0, true); |
|
464 |
final static BulkCipher B_RC4_40 = new BulkCipher(CIPHER_RC4, 5, 16, 0, true); |
|
465 |
final static BulkCipher B_RC2_40 = new BulkCipher("RC2", 5, 16, 8, false); |
|
466 |
final static BulkCipher B_DES_40 = new BulkCipher(CIPHER_DES, 5, 8, 8, true); |
|
467 |
||
468 |
// domestic strength ciphers |
|
469 |
final static BulkCipher B_RC4_128 = new BulkCipher(CIPHER_RC4, 16, 0, true); |
|
470 |
final static BulkCipher B_DES = new BulkCipher(CIPHER_DES, 8, 8, true); |
|
471 |
final static BulkCipher B_3DES = new BulkCipher(CIPHER_3DES, 24, 8, true); |
|
472 |
final static BulkCipher B_IDEA = new BulkCipher("IDEA", 16, 8, false); |
|
473 |
final static BulkCipher B_AES_128 = new BulkCipher(CIPHER_AES, 16, 16, true); |
|
474 |
final static BulkCipher B_AES_256 = new BulkCipher(CIPHER_AES, 32, 16, true); |
|
475 |
||
476 |
// MACs |
|
477 |
final static MacAlg M_NULL = new MacAlg("NULL", 0); |
|
478 |
final static MacAlg M_MD5 = new MacAlg("MD5", 16); |
|
479 |
final static MacAlg M_SHA = new MacAlg("SHA", 20); |
|
480 |
||
481 |
static { |
|
482 |
idMap = new HashMap<Integer,CipherSuite>(); |
|
483 |
nameMap = new HashMap<String,CipherSuite>(); |
|
484 |
||
485 |
final boolean F = false; |
|
486 |
final boolean T = true; |
|
487 |
// N: ciphersuites only allowed if we are not in FIPS mode |
|
488 |
final boolean N = (SunJSSE.isFIPS() == false); |
|
489 |
||
490 |
add("SSL_NULL_WITH_NULL_NULL", 0x0000, 1, K_NULL, B_NULL, F); |
|
491 |
||
492 |
// Definition of the CipherSuites that are enabled by default. |
|
493 |
// They are listed in preference order, most preferred first. |
|
494 |
int p = DEFAULT_SUITES_PRIORITY * 2; |
|
495 |
||
496 |
add("SSL_RSA_WITH_RC4_128_MD5", 0x0004, --p, K_RSA, B_RC4_128, N); |
|
497 |
add("SSL_RSA_WITH_RC4_128_SHA", 0x0005, --p, K_RSA, B_RC4_128, N); |
|
498 |
add("TLS_RSA_WITH_AES_128_CBC_SHA", 0x002f, --p, K_RSA, B_AES_128, T); |
|
499 |
add("TLS_RSA_WITH_AES_256_CBC_SHA", 0x0035, --p, K_RSA, B_AES_256, T); |
|
500 |
||
501 |
add("TLS_ECDH_ECDSA_WITH_RC4_128_SHA", 0xC002, --p, K_ECDH_ECDSA, B_RC4_128, N); |
|
502 |
add("TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA", 0xC004, --p, K_ECDH_ECDSA, B_AES_128, T); |
|
503 |
add("TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA", 0xC005, --p, K_ECDH_ECDSA, B_AES_256, T); |
|
504 |
add("TLS_ECDH_RSA_WITH_RC4_128_SHA", 0xC00C, --p, K_ECDH_RSA, B_RC4_128, N); |
|
505 |
add("TLS_ECDH_RSA_WITH_AES_128_CBC_SHA", 0xC00E, --p, K_ECDH_RSA, B_AES_128, T); |
|
506 |
add("TLS_ECDH_RSA_WITH_AES_256_CBC_SHA", 0xC00F, --p, K_ECDH_RSA, B_AES_256, T); |
|
507 |
||
508 |
add("TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", 0xC007, --p, K_ECDHE_ECDSA,B_RC4_128, N); |
|
509 |
add("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", 0xC009, --p, K_ECDHE_ECDSA,B_AES_128, T); |
|
510 |
add("TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", 0xC00A, --p, K_ECDHE_ECDSA,B_AES_256, T); |
|
511 |
add("TLS_ECDHE_RSA_WITH_RC4_128_SHA", 0xC011, --p, K_ECDHE_RSA, B_RC4_128, N); |
|
512 |
add("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", 0xC013, --p, K_ECDHE_RSA, B_AES_128, T); |
|
513 |
add("TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", 0xC014, --p, K_ECDHE_RSA, B_AES_256, T); |
|
514 |
||
515 |
add("TLS_DHE_RSA_WITH_AES_128_CBC_SHA", 0x0033, --p, K_DHE_RSA, B_AES_128, T); |
|
516 |
add("TLS_DHE_RSA_WITH_AES_256_CBC_SHA", 0x0039, --p, K_DHE_RSA, B_AES_256, T); |
|
517 |
add("TLS_DHE_DSS_WITH_AES_128_CBC_SHA", 0x0032, --p, K_DHE_DSS, B_AES_128, T); |
|
518 |
add("TLS_DHE_DSS_WITH_AES_256_CBC_SHA", 0x0038, --p, K_DHE_DSS, B_AES_256, T); |
|
519 |
||
520 |
add("SSL_RSA_WITH_3DES_EDE_CBC_SHA", 0x000a, --p, K_RSA, B_3DES, T); |
|
521 |
add("TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA", 0xC003, --p, K_ECDH_ECDSA, B_3DES, T); |
|
522 |
add("TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA", 0xC00D, --p, K_ECDH_RSA, B_3DES, T); |
|
523 |
add("TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA", 0xC008, --p, K_ECDHE_ECDSA,B_3DES, T); |
|
524 |
add("TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", 0xC012, --p, K_ECDHE_RSA, B_3DES, T); |
|
525 |
add("SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA", 0x0016, --p, K_DHE_RSA, B_3DES, T); |
|
526 |
add("SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA", 0x0013, --p, K_DHE_DSS, B_3DES, N); |
|
527 |
||
528 |
add("SSL_RSA_WITH_DES_CBC_SHA", 0x0009, --p, K_RSA, B_DES, N); |
|
529 |
add("SSL_DHE_RSA_WITH_DES_CBC_SHA", 0x0015, --p, K_DHE_RSA, B_DES, N); |
|
530 |
add("SSL_DHE_DSS_WITH_DES_CBC_SHA", 0x0012, --p, K_DHE_DSS, B_DES, N); |
|
531 |
add("SSL_RSA_EXPORT_WITH_RC4_40_MD5", 0x0003, --p, K_RSA_EXPORT, B_RC4_40, N); |
|
532 |
add("SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", 0x0008, --p, K_RSA_EXPORT, B_DES_40, N); |
|
533 |
add("SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", 0x0014, --p, K_DHE_RSA, B_DES_40, N); |
|
534 |
add("SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA", 0x0011, --p, K_DHE_DSS, B_DES_40, N); |
|
535 |
||
536 |
// Definition of the CipherSuites that are supported but not enabled |
|
537 |
// by default. |
|
538 |
// They are listed in preference order, preferred first. |
|
539 |
p = DEFAULT_SUITES_PRIORITY; |
|
540 |
||
541 |
// Anonymous key exchange and the NULL ciphers |
|
542 |
add("SSL_RSA_WITH_NULL_MD5", 0x0001, --p, K_RSA, B_NULL, N); |
|
543 |
add("SSL_RSA_WITH_NULL_SHA", 0x0002, --p, K_RSA, B_NULL, N); |
|
544 |
add("TLS_ECDH_ECDSA_WITH_NULL_SHA", 0xC001, --p, K_ECDH_ECDSA, B_NULL, N); |
|
545 |
add("TLS_ECDH_RSA_WITH_NULL_SHA", 0xC00B, --p, K_ECDH_RSA, B_NULL, N); |
|
546 |
add("TLS_ECDHE_ECDSA_WITH_NULL_SHA", 0xC006, --p, K_ECDHE_ECDSA,B_NULL, N); |
|
547 |
add("TLS_ECDHE_RSA_WITH_NULL_SHA", 0xC010, --p, K_ECDHE_RSA, B_NULL, N); |
|
548 |
||
549 |
add("SSL_DH_anon_WITH_RC4_128_MD5", 0x0018, --p, K_DH_ANON, B_RC4_128, N); |
|
550 |
add("TLS_DH_anon_WITH_AES_128_CBC_SHA", 0x0034, --p, K_DH_ANON, B_AES_128, N); |
|
551 |
add("TLS_DH_anon_WITH_AES_256_CBC_SHA", 0x003a, --p, K_DH_ANON, B_AES_256, N); |
|
552 |
add("SSL_DH_anon_WITH_3DES_EDE_CBC_SHA", 0x001b, --p, K_DH_ANON, B_3DES, N); |
|
553 |
add("SSL_DH_anon_WITH_DES_CBC_SHA", 0x001a, --p, K_DH_ANON, B_DES, N); |
|
554 |
||
555 |
add("TLS_ECDH_anon_WITH_RC4_128_SHA", 0xC016, --p, K_ECDH_ANON, B_RC4_128, N); |
|
556 |
add("TLS_ECDH_anon_WITH_AES_128_CBC_SHA", 0xC018, --p, K_ECDH_ANON, B_AES_128, T); |
|
557 |
add("TLS_ECDH_anon_WITH_AES_256_CBC_SHA", 0xC019, --p, K_ECDH_ANON, B_AES_256, T); |
|
558 |
add("TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA", 0xC017, --p, K_ECDH_ANON, B_3DES, T); |
|
559 |
||
560 |
add("SSL_DH_anon_EXPORT_WITH_RC4_40_MD5", 0x0017, --p, K_DH_ANON, B_RC4_40, N); |
|
561 |
add("SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA", 0x0019, --p, K_DH_ANON, B_DES_40, N); |
|
562 |
||
563 |
add("TLS_ECDH_anon_WITH_NULL_SHA", 0xC015, --p, K_ECDH_ANON, B_NULL, N); |
|
564 |
||
565 |
// Supported Kerberos ciphersuites from RFC2712 |
|
566 |
add("TLS_KRB5_WITH_RC4_128_SHA", 0x0020, --p, K_KRB5, B_RC4_128, N); |
|
567 |
add("TLS_KRB5_WITH_RC4_128_MD5", 0x0024, --p, K_KRB5, B_RC4_128, N); |
|
568 |
add("TLS_KRB5_WITH_3DES_EDE_CBC_SHA", 0x001f, --p, K_KRB5, B_3DES, N); |
|
569 |
add("TLS_KRB5_WITH_3DES_EDE_CBC_MD5", 0x0023, --p, K_KRB5, B_3DES, N); |
|
570 |
add("TLS_KRB5_WITH_DES_CBC_SHA", 0x001e, --p, K_KRB5, B_DES, N); |
|
571 |
add("TLS_KRB5_WITH_DES_CBC_MD5", 0x0022, --p, K_KRB5, B_DES, N); |
|
572 |
add("TLS_KRB5_EXPORT_WITH_RC4_40_SHA", 0x0028, --p, K_KRB5_EXPORT, B_RC4_40, N); |
|
573 |
add("TLS_KRB5_EXPORT_WITH_RC4_40_MD5", 0x002b, --p, K_KRB5_EXPORT, B_RC4_40, N); |
|
574 |
add("TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA", 0x0026, --p, K_KRB5_EXPORT, B_DES_40, N); |
|
575 |
add("TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5", 0x0029, --p, K_KRB5_EXPORT, B_DES_40, N); |
|
576 |
||
577 |
||
578 |
// Register the names of a few additional CipherSuites. |
|
579 |
// Makes them show up as names instead of numbers in |
|
580 |
// the debug output. |
|
581 |
||
582 |
// remaining unsupported ciphersuites defined in RFC2246. |
|
583 |
add("SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5", 0x0006); |
|
584 |
add("SSL_RSA_WITH_IDEA_CBC_SHA", 0x0007); |
|
585 |
add("SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA", 0x000b); |
|
586 |
add("SSL_DH_DSS_WITH_DES_CBC_SHA", 0x000c); |
|
587 |
add("SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA", 0x000d); |
|
588 |
add("SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA", 0x000e); |
|
589 |
add("SSL_DH_RSA_WITH_DES_CBC_SHA", 0x000f); |
|
590 |
add("SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA", 0x0010); |
|
591 |
||
592 |
// SSL 3.0 Fortezza ciphersuites |
|
593 |
add("SSL_FORTEZZA_DMS_WITH_NULL_SHA", 0x001c); |
|
594 |
add("SSL_FORTEZZA_DMS_WITH_FORTEZZA_CBC_SHA", 0x001d); |
|
595 |
||
596 |
// 1024/56 bit exportable ciphersuites from expired internet draft |
|
597 |
add("SSL_RSA_EXPORT1024_WITH_DES_CBC_SHA", 0x0062); |
|
598 |
add("SSL_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA", 0x0063); |
|
599 |
add("SSL_RSA_EXPORT1024_WITH_RC4_56_SHA", 0x0064); |
|
600 |
add("SSL_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA", 0x0065); |
|
601 |
add("SSL_DHE_DSS_WITH_RC4_128_SHA", 0x0066); |
|
602 |
||
603 |
// Netscape old and new SSL 3.0 FIPS ciphersuites |
|
604 |
// see http://www.mozilla.org/projects/security/pki/nss/ssl/fips-ssl-ciphersuites.html |
|
605 |
add("NETSCAPE_RSA_FIPS_WITH_3DES_EDE_CBC_SHA", 0xffe0); |
|
606 |
add("NETSCAPE_RSA_FIPS_WITH_DES_CBC_SHA", 0xffe1); |
|
607 |
add("SSL_RSA_FIPS_WITH_DES_CBC_SHA", 0xfefe); |
|
608 |
add("SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA", 0xfeff); |
|
609 |
||
610 |
// Unsupported Kerberos cipher suites from RFC 2712 |
|
611 |
add("TLS_KRB5_WITH_IDEA_CBC_SHA", 0x0021); |
|
612 |
add("TLS_KRB5_WITH_IDEA_CBC_MD5", 0x0025); |
|
613 |
add("TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA", 0x0027); |
|
614 |
add("TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5", 0x002a); |
|
615 |
||
616 |
} |
|
617 |
||
618 |
// ciphersuite SSL_NULL_WITH_NULL_NULL |
|
619 |
final static CipherSuite C_NULL = CipherSuite.valueOf(0, 0); |
|
620 |
||
621 |
} |