1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45:
46: import ;
47:
48: import ;
49: import ;
50: import ;
51:
52: import ;
53: import ;
54: import ;
55:
56: import ;
57: import ;
58: import ;
59: import ;
60:
61: public final class CipherSuite implements Constructed
62: {
63:
64:
65:
66:
67: private static final List<String> tlsSuiteNames = new LinkedList<String>();
68: private static final HashMap<String, CipherSuite> namesToSuites = new HashMap<String, CipherSuite>();
69:
70:
71: public static final CipherSuite TLS_NULL_WITH_NULL_NULL =
72: new CipherSuite (CipherAlgorithm.NULL,
73: KeyExchangeAlgorithm.NONE,
74: SignatureAlgorithm.ANONYMOUS,
75: MacAlgorithm.NULL, 0, 0x00, 0x00,
76: "TLS_NULL_WITH_NULL_NULL", false);
77: public static final CipherSuite TLS_RSA_WITH_NULL_MD5 =
78: new CipherSuite (CipherAlgorithm.NULL,
79: KeyExchangeAlgorithm.RSA,
80: SignatureAlgorithm.RSA,
81: MacAlgorithm.MD5, 0, 0x00, 0x01,
82: "TLS_RSA_WITH_NULL_MD5", false);
83: public static final CipherSuite TLS_RSA_WITH_NULL_SHA =
84: new CipherSuite (CipherAlgorithm.NULL,
85: KeyExchangeAlgorithm.RSA,
86: SignatureAlgorithm.RSA,
87: MacAlgorithm.SHA, 0, 0x00, 0x02,
88: "TLS_RSA_WITH_NULL_SHA", false);
89: public static final CipherSuite TLS_RSA_EXPORT_WITH_RC4_40_MD5 =
90: new CipherSuite (CipherAlgorithm.RC4,
91: KeyExchangeAlgorithm.RSA,
92: SignatureAlgorithm.RSA,
93: MacAlgorithm.MD5, 5, 0x00, 0x03,
94: "TLS_RSA_EXPORT_WITH_RC4_40_MD5", false);
95: public static final CipherSuite TLS_RSA_WITH_RC4_128_MD5 =
96: new CipherSuite (CipherAlgorithm.RC4,
97: KeyExchangeAlgorithm.RSA,
98: SignatureAlgorithm.RSA,
99: MacAlgorithm.MD5, 16, 0x00, 0x04,
100: "TLS_RSA_WITH_RC4_128_MD5", false);
101: public static final CipherSuite TLS_RSA_WITH_RC4_128_SHA =
102: new CipherSuite (CipherAlgorithm.RC4,
103: KeyExchangeAlgorithm.RSA,
104: SignatureAlgorithm.RSA,
105: MacAlgorithm.SHA, 16, 0x00, 0x05,
106: "TLS_RSA_WITH_RC4_128_SHA", false);
107: public static final CipherSuite TLS_RSA_EXPORT_WITH_DES40_CBC_SHA =
108: new CipherSuite (CipherAlgorithm.DES,
109: KeyExchangeAlgorithm.RSA,
110: SignatureAlgorithm.RSA,
111: MacAlgorithm.SHA, 5, 0x00, 0x08,
112: "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA", true);
113: public static final CipherSuite TLS_RSA_WITH_DES_CBC_SHA =
114: new CipherSuite (CipherAlgorithm.DES,
115: KeyExchangeAlgorithm.RSA,
116: SignatureAlgorithm.RSA,
117: MacAlgorithm.SHA, 8, 0x00, 0x09,
118: "TLS_RSA_WITH_DES_CBC_SHA", true);
119: public static final CipherSuite TLS_RSA_WITH_3DES_EDE_CBC_SHA =
120: new CipherSuite (CipherAlgorithm.DESede,
121: KeyExchangeAlgorithm.RSA,
122: SignatureAlgorithm.RSA,
123: MacAlgorithm.SHA, 24, 0x00, 0x0A,
124: "TLS_RSA_WITH_3DES_EDE_CBC_SHA", true);
125: public static final CipherSuite TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA =
126: new CipherSuite (CipherAlgorithm.DES,
127: KeyExchangeAlgorithm.DH_DSS,
128: SignatureAlgorithm.ANONYMOUS,
129: MacAlgorithm.SHA, 5, 0x00, 0x0B,
130: "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA", true);
131: public static final CipherSuite TLS_DH_DSS_WITH_DES_CBC_SHA =
132: new CipherSuite (CipherAlgorithm.DES,
133: KeyExchangeAlgorithm.DH_DSS,
134: SignatureAlgorithm.ANONYMOUS,
135: MacAlgorithm.SHA, 8, 0x00, 0x0C,
136: "TLS_DH_DSS_WITH_DES_CBC_SHA", true);
137: public static final CipherSuite TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA =
138: new CipherSuite (CipherAlgorithm.DESede,
139: KeyExchangeAlgorithm.DH_DSS,
140: SignatureAlgorithm.ANONYMOUS,
141: MacAlgorithm.SHA, 24, 0x00, 0x0D,
142: "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA", true);
143: public static final CipherSuite TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA =
144: new CipherSuite (CipherAlgorithm.DES,
145: KeyExchangeAlgorithm.DH_RSA,
146: SignatureAlgorithm.ANONYMOUS,
147: MacAlgorithm.SHA, 5, 0x00, 0x0E,
148: "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA", true);
149: public static final CipherSuite TLS_DH_RSA_WITH_DES_CBC_SHA =
150: new CipherSuite (CipherAlgorithm.DES,
151: KeyExchangeAlgorithm.DH_RSA,
152: SignatureAlgorithm.ANONYMOUS,
153: MacAlgorithm.SHA, 8, 0x00, 0x0F,
154: "TLS_DH_RSA_WITH_DES_CBC_SHA", true);
155: public static final CipherSuite TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA =
156: new CipherSuite (CipherAlgorithm.DESede,
157: KeyExchangeAlgorithm.DH_RSA,
158: SignatureAlgorithm.ANONYMOUS,
159: MacAlgorithm.SHA, 24, 0x00, 0x10,
160: "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA", true);
161: public static final CipherSuite TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA =
162: new CipherSuite (CipherAlgorithm.DES,
163: KeyExchangeAlgorithm.DHE_DSS, true,
164: SignatureAlgorithm.DSA,
165: MacAlgorithm.SHA, 5, 0x00, 0x11,
166: "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA", true);
167: public static final CipherSuite TLS_DHE_DSS_WITH_DES_CBC_SHA =
168: new CipherSuite (CipherAlgorithm.DES,
169: KeyExchangeAlgorithm.DHE_DSS, true,
170: SignatureAlgorithm.DSA,
171: MacAlgorithm.SHA, 8, 0x00, 0x12,
172: "TLS_DHE_DSS_WITH_DES_CBC_SHA", true);
173: public static final CipherSuite TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA =
174: new CipherSuite (CipherAlgorithm.DESede,
175: KeyExchangeAlgorithm.DHE_DSS, true,
176: SignatureAlgorithm.DSA,
177: MacAlgorithm.SHA, 24, 0x00, 0x13,
178: "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA", true);
179: public static final CipherSuite TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA =
180: new CipherSuite (CipherAlgorithm.DES,
181: KeyExchangeAlgorithm.DHE_RSA, true,
182: SignatureAlgorithm.RSA,
183: MacAlgorithm.SHA, 5, 0x00, 0x14,
184: "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", true);
185: public static final CipherSuite TLS_DHE_RSA_WITH_DES_CBC_SHA =
186: new CipherSuite (CipherAlgorithm.DES,
187: KeyExchangeAlgorithm.DHE_RSA, true,
188: SignatureAlgorithm.RSA,
189: MacAlgorithm.SHA, 8, 0x00, 0x15,
190: "TLS_DHE_RSA_WITH_DES_CBC_SHA", true);
191: public static final CipherSuite TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA =
192: new CipherSuite (CipherAlgorithm.DESede,
193: KeyExchangeAlgorithm.DHE_RSA, true,
194: SignatureAlgorithm.RSA,
195: MacAlgorithm.SHA, 24, 0x00, 0x16,
196: "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA", true);
197:
198:
199: public static final CipherSuite TLS_RSA_WITH_AES_128_CBC_SHA =
200: new CipherSuite (CipherAlgorithm.AES,
201: KeyExchangeAlgorithm.RSA,
202: SignatureAlgorithm.RSA,
203: MacAlgorithm.SHA, 16, 0x00, 0x2F,
204: "TLS_RSA_WITH_AES_128_CBC_SHA", true);
205: public static final CipherSuite TLS_DH_DSS_WITH_AES_128_CBC_SHA =
206: new CipherSuite (CipherAlgorithm.AES,
207: KeyExchangeAlgorithm.DH_DSS,
208: SignatureAlgorithm.ANONYMOUS,
209: MacAlgorithm.SHA, 16, 0x00, 0x30,
210: "TLS_DH_DSS_WITH_AES_128_CBC_SHA", true);
211: public static final CipherSuite TLS_DH_RSA_WITH_AES_128_CBC_SHA =
212: new CipherSuite (CipherAlgorithm.AES,
213: KeyExchangeAlgorithm.DH_RSA,
214: SignatureAlgorithm.ANONYMOUS,
215: MacAlgorithm.SHA, 16, 0x00, 0x31,
216: "TLS_DH_RSA_WITH_AES_128_CBC_SHA", true);
217: public static final CipherSuite TLS_DHE_DSS_WITH_AES_128_CBC_SHA =
218: new CipherSuite (CipherAlgorithm.AES,
219: KeyExchangeAlgorithm.DHE_DSS, true,
220: SignatureAlgorithm.DSA,
221: MacAlgorithm.SHA, 16, 0x00, 0x32,
222: "TLS_DHE_DSS_WITH_AES_128_CBC_SHA", true);
223: public static final CipherSuite TLS_DHE_RSA_WITH_AES_128_CBC_SHA =
224: new CipherSuite (CipherAlgorithm.AES,
225: KeyExchangeAlgorithm.DHE_RSA, true,
226: SignatureAlgorithm.RSA,
227: MacAlgorithm.SHA, 16, 0x00, 0x33,
228: "TLS_DHE_RSA_WITH_AES_128_CBC_SHA", true);
229: public static final CipherSuite TLS_RSA_WITH_AES_256_CBC_SHA =
230: new CipherSuite (CipherAlgorithm.AES,
231: KeyExchangeAlgorithm.RSA,
232: SignatureAlgorithm.ANONYMOUS,
233: MacAlgorithm.SHA, 32, 0x00, 0x35,
234: "TLS_RSA_WITH_AES_256_CBC_SHA", true);
235: public static final CipherSuite TLS_DH_DSS_WITH_AES_256_CBC_SHA =
236: new CipherSuite (CipherAlgorithm.AES,
237: KeyExchangeAlgorithm.DH_DSS,
238: SignatureAlgorithm.ANONYMOUS,
239: MacAlgorithm.SHA, 32, 0x00, 0x36,
240: "TLS_DH_DSS_WITH_AES_256_CBC_SHA", true);
241: public static final CipherSuite TLS_DH_RSA_WITH_AES_256_CBC_SHA =
242: new CipherSuite (CipherAlgorithm.AES,
243: KeyExchangeAlgorithm.DH_RSA,
244: SignatureAlgorithm.ANONYMOUS,
245: MacAlgorithm.SHA, 32, 0x00, 0x37,
246: "TLS_DH_RSA_WITH_AES_256_CBC_SHA", true);
247: public static final CipherSuite TLS_DHE_DSS_WITH_AES_256_CBC_SHA =
248: new CipherSuite (CipherAlgorithm.AES,
249: KeyExchangeAlgorithm.DHE_DSS, true,
250: SignatureAlgorithm.DSA,
251: MacAlgorithm.SHA, 32, 0x00, 0x38,
252: "TLS_DHE_DSS_WITH_AES_256_CBC_SHA", true);
253: public static final CipherSuite TLS_DHE_RSA_WITH_AES_256_CBC_SHA =
254: new CipherSuite (CipherAlgorithm.AES,
255: KeyExchangeAlgorithm.DHE_RSA, true,
256: SignatureAlgorithm.RSA,
257: MacAlgorithm.SHA, 32, 0x00, 0x39,
258: "TLS_DHE_RSA_WITH_AES_256_CBC_SHA", true);
259:
260:
261:
262:
316:
317:
318: public static final CipherSuite TLS_PSK_WITH_RC4_128_SHA =
319: new CipherSuite(CipherAlgorithm.RC4,
320: KeyExchangeAlgorithm.PSK,
321: SignatureAlgorithm.ANONYMOUS,
322: MacAlgorithm.SHA, 16, 0x00, 0x8A,
323: "TLS_PSK_WITH_RC4_128_SHA", true);
324: public static final CipherSuite TLS_PSK_WITH_3DES_EDE_CBC_SHA =
325: new CipherSuite(CipherAlgorithm.DESede,
326: KeyExchangeAlgorithm.PSK,
327: SignatureAlgorithm.ANONYMOUS,
328: MacAlgorithm.SHA, 24, 0x00, 0x8B,
329: "TLS_PSK_WITH_3DES_EDE_CBC_SHA", true);
330: public static final CipherSuite TLS_PSK_WITH_AES_128_CBC_SHA =
331: new CipherSuite(CipherAlgorithm.AES,
332: KeyExchangeAlgorithm.PSK,
333: SignatureAlgorithm.ANONYMOUS,
334: MacAlgorithm.SHA, 16, 0x00, 0x8C,
335: "TLS_PSK_WITH_AES_128_CBC_SHA", true);
336: public static final CipherSuite TLS_PSK_WITH_AES_256_CBC_SHA =
337: new CipherSuite(CipherAlgorithm.AES,
338: KeyExchangeAlgorithm.PSK,
339: SignatureAlgorithm.ANONYMOUS,
340: MacAlgorithm.SHA, 32, 0x00, 0x8D,
341: "TLS_PSK_WITH_AES_256_CBC_SHA", true);
342:
343: public static final CipherSuite TLS_DHE_PSK_WITH_RC4_128_SHA =
344: new CipherSuite(CipherAlgorithm.RC4,
345: KeyExchangeAlgorithm.DHE_PSK, true,
346: SignatureAlgorithm.ANONYMOUS,
347: MacAlgorithm.SHA, 16, 0x00, 0x8E,
348: "TLS_DHE_PSK_WITH_RC4_128_SHA", false);
349: public static final CipherSuite TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA =
350: new CipherSuite(CipherAlgorithm.DESede,
351: KeyExchangeAlgorithm.DHE_PSK, true,
352: SignatureAlgorithm.ANONYMOUS,
353: MacAlgorithm.SHA, 24, 0x00, 0x8F,
354: "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA", true);
355: public static final CipherSuite TLS_DHE_PSK_WITH_AES_128_CBC_SHA =
356: new CipherSuite(CipherAlgorithm.AES,
357: KeyExchangeAlgorithm.DHE_PSK, true,
358: SignatureAlgorithm.ANONYMOUS,
359: MacAlgorithm.SHA, 16, 0x00, 0x90,
360: "TLS_DHE_PSK_WITH_AES_128_CBC_SHA", true);
361: public static final CipherSuite TLS_DHE_PSK_WITH_AES_256_CBC_SHA =
362: new CipherSuite(CipherAlgorithm.AES,
363: KeyExchangeAlgorithm.DHE_PSK, true,
364: SignatureAlgorithm.ANONYMOUS,
365: MacAlgorithm.SHA, 32, 0x00, 0x91,
366: "TLS_DHE_PSK_WITH_AES_256_CBC_SHA", true);
367:
368: public static final CipherSuite TLS_RSA_PSK_WITH_RC4_128_SHA =
369: new CipherSuite(CipherAlgorithm.RC4,
370: KeyExchangeAlgorithm.RSA_PSK,
371: SignatureAlgorithm.ANONYMOUS,
372: MacAlgorithm.SHA, 16, 0x00, 0x92,
373: "TLS_RSA_PSK_WITH_RC4_128_SHA", false);
374: public static final CipherSuite TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA =
375: new CipherSuite(CipherAlgorithm.DESede,
376: KeyExchangeAlgorithm.RSA_PSK,
377: SignatureAlgorithm.ANONYMOUS,
378: MacAlgorithm.SHA, 24, 0x00, 0x93,
379: "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA", true);
380: public static final CipherSuite TLS_RSA_PSK_WITH_AES_128_CBC_SHA =
381: new CipherSuite(CipherAlgorithm.AES,
382: KeyExchangeAlgorithm.RSA_PSK,
383: SignatureAlgorithm.ANONYMOUS,
384: MacAlgorithm.SHA, 16, 0x00, 0x94,
385: "TLS_RSA_PSK_WITH_AES_128_CBC_SHA", true);
386: public static final CipherSuite TLS_RSA_PSK_WITH_AES_256_CBC_SHA =
387: new CipherSuite(CipherAlgorithm.AES,
388: KeyExchangeAlgorithm.RSA_PSK,
389: SignatureAlgorithm.ANONYMOUS,
390: MacAlgorithm.SHA, 32, 0x00, 0x95,
391: "TLS_RSA_PSK_WITH_AES_256_CBC_SHA", true);
392:
393:
394:
395:
485:
486: private final CipherAlgorithm cipherAlgorithm;
487: private final KeyExchangeAlgorithm keyExchangeAlgorithm;
488: private final SignatureAlgorithm signatureAlgorithm;
489: private final MacAlgorithm macAlgorithm;
490: private final boolean ephemeralDH;
491: private final boolean exportable;
492: private final boolean isStream;
493: private final boolean isCBCMode;
494: private final int keyLength;
495: private final byte[] id;
496: private final String name;
497: private final boolean isResolved;
498:
499:
500:
501:
502: private CipherSuite (final CipherAlgorithm cipherAlgorithm,
503: final KeyExchangeAlgorithm keyExchangeAlgorithm,
504: final SignatureAlgorithm signatureAlgorithm,
505: final MacAlgorithm macAlgorithm,
506: final int keyLength,
507: final int id1,
508: final int id2,
509: final String name,
510: final boolean isCBCMode)
511: {
512: this (cipherAlgorithm, keyExchangeAlgorithm, false, signatureAlgorithm,
513: macAlgorithm, keyLength, id1, id2, name, isCBCMode);
514: }
515:
516: private CipherSuite (final CipherAlgorithm cipherAlgorithm,
517: final KeyExchangeAlgorithm keyExchangeAlgorithm,
518: final boolean ephemeralDH,
519: final SignatureAlgorithm signatureAlgorithm,
520: final MacAlgorithm macAlgorithm,
521: final int keyLength,
522: final int id1,
523: final int id2,
524: final String name,
525: final boolean isCBCMode)
526: {
527: this.cipherAlgorithm = cipherAlgorithm;
528: this.keyExchangeAlgorithm = keyExchangeAlgorithm;
529: this.ephemeralDH = ephemeralDH;
530: this.signatureAlgorithm = signatureAlgorithm;
531: this.macAlgorithm = macAlgorithm;
532: this.exportable = keyLength <= 5;
533: this.isStream = (cipherAlgorithm == CipherAlgorithm.NULL
534: || cipherAlgorithm == CipherAlgorithm.RC4);
535: this.isCBCMode = isCBCMode;
536: this.keyLength = keyLength;
537: this.id = new byte[] { (byte) id1, (byte) id2 };
538: this.name = name.intern();
539: namesToSuites.put(name, this);
540: if (name.startsWith("TLS"))
541: {
542: tlsSuiteNames.add(name);
543: }
544: isResolved = true;
545: }
546:
547: private CipherSuite(byte[] id)
548: {
549: cipherAlgorithm = null;
550: keyExchangeAlgorithm = null;
551: signatureAlgorithm = null;
552: macAlgorithm = null;
553: ephemeralDH = false;
554: exportable = false;
555: isStream = false;
556: isCBCMode = false;
557: keyLength = 0;
558: this.id = id;
559: name = null;
560: isResolved = false;
561: }
562:
563:
564:
565:
566:
572: public static CipherSuite forName(String name)
573: {
574: if (name.startsWith("SSL_"))
575: name = "TLS_" + name.substring(4);
576: return namesToSuites.get(name);
577: }
578:
579: public static CipherSuite forValue(final short raw_value)
580: {
581: byte[] b = new byte[] { (byte) (raw_value >>> 8), (byte) raw_value };
582: return new CipherSuite(b).resolve();
583: }
584:
585: public static List<String> availableSuiteNames()
586: {
587: return tlsSuiteNames;
588: }
589:
590:
591:
592:
593: public CipherAlgorithm cipherAlgorithm ()
594: {
595: return cipherAlgorithm;
596: }
597:
598: public Cipher cipher () throws NoSuchAlgorithmException, NoSuchPaddingException
599: {
600: if (cipherAlgorithm == null)
601: throw new NoSuchAlgorithmException (toString () + ": unresolved cipher suite");
602: if (cipherAlgorithm == CipherAlgorithm.NULL)
603: return new NullCipher ();
604:
605: String alg = null;
606: if (isCBCMode)
607: alg = cipherAlgorithm + "/CBC/NoPadding";
608: else
609: alg = cipherAlgorithm.toString();
610: GetSecurityPropertyAction gspa =
611: new GetSecurityPropertyAction ("jessie.jce.provider");
612: final String provider = (String) AccessController.doPrivileged (gspa);
613: if (provider != null)
614: {
615: try
616: {
617: return Cipher.getInstance (alg, provider);
618: }
619: catch (NoSuchProviderException nspe)
620: {
621: }
622: }
623: return Cipher.getInstance (alg);
624: }
625:
626: public MacAlgorithm macAlgorithm ()
627: {
628: return macAlgorithm;
629: }
630:
631: public Mac mac(ProtocolVersion version) throws NoSuchAlgorithmException
632: {
633: if (macAlgorithm == null)
634: throw new NoSuchAlgorithmException(toString() + ": unresolved cipher suite");
635: if (macAlgorithm == MacAlgorithm.NULL)
636: return null;
637:
638: String macAlg = null;
639: if (version == ProtocolVersion.SSL_3)
640: {
641: macAlg = "SSLv3HMac-" + macAlgorithm;
642: }
643: else
644: {
645: if (macAlgorithm == MacAlgorithm.MD5)
646: macAlg = "HMac-MD5";
647: if (macAlgorithm == MacAlgorithm.SHA)
648: macAlg = "HMac-SHA1";
649: }
650:
651: GetSecurityPropertyAction gspa =
652: new GetSecurityPropertyAction ("jessie.jce.provider");
653: final String provider = AccessController.doPrivileged (gspa);
654: if (provider != null)
655: {
656: try
657: {
658: return Mac.getInstance(macAlg, provider);
659: }
660: catch (NoSuchProviderException nspe)
661: {
662:
663: }
664: }
665: return Mac.getInstance(macAlg);
666: }
667:
668: public SignatureAlgorithm signatureAlgorithm ()
669: {
670: return signatureAlgorithm;
671: }
672:
673: public KeyExchangeAlgorithm keyExchangeAlgorithm ()
674: {
675: return keyExchangeAlgorithm;
676: }
677:
678: public boolean isEphemeralDH ()
679: {
680: return ephemeralDH;
681: }
682:
683: public int length ()
684: {
685: return 2;
686: }
687:
688: public void write(OutputStream out) throws IOException
689: {
690: out.write(id);
691: }
692:
693: public void put (final ByteBuffer buf)
694: {
695: buf.put (id);
696: }
697:
698: public CipherSuite resolve()
699: {
700: if (id[0] == 0x00) switch (id[1] & 0xFF)
701: {
702: case 0x00: return TLS_NULL_WITH_NULL_NULL;
703: case 0x01: return TLS_RSA_WITH_NULL_MD5;
704: case 0x02: return TLS_RSA_WITH_NULL_SHA;
705: case 0x03: return TLS_RSA_EXPORT_WITH_RC4_40_MD5;
706: case 0x04: return TLS_RSA_WITH_RC4_128_MD5;
707: case 0x05: return TLS_RSA_WITH_RC4_128_SHA;
708: case 0x08: return TLS_RSA_EXPORT_WITH_DES40_CBC_SHA;
709: case 0x09: return TLS_RSA_WITH_DES_CBC_SHA;
710: case 0x0A: return TLS_RSA_WITH_3DES_EDE_CBC_SHA;
711: case 0x0B: return TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA;
712: case 0x0C: return TLS_DH_DSS_WITH_DES_CBC_SHA;
713: case 0x0D: return TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA;
714: case 0x0E: return TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA;
715: case 0x0F: return TLS_DH_RSA_WITH_DES_CBC_SHA;
716: case 0x10: return TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA;
717: case 0x11: return TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA;
718: case 0x12: return TLS_DHE_DSS_WITH_DES_CBC_SHA;
719: case 0x13: return TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA;
720: case 0x14: return TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA;
721: case 0x15: return TLS_DHE_RSA_WITH_DES_CBC_SHA;
722: case 0x16: return TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA;
723: case 0x2F: return TLS_RSA_WITH_AES_128_CBC_SHA;
724: case 0x30: return TLS_DH_DSS_WITH_AES_128_CBC_SHA;
725: case 0x31: return TLS_DH_RSA_WITH_AES_128_CBC_SHA;
726: case 0x32: return TLS_DHE_DSS_WITH_AES_128_CBC_SHA;
727: case 0x33: return TLS_DHE_RSA_WITH_AES_128_CBC_SHA;
728: case 0x35: return TLS_RSA_WITH_AES_256_CBC_SHA;
729: case 0x36: return TLS_DH_DSS_WITH_AES_256_CBC_SHA;
730: case 0x37: return TLS_DH_RSA_WITH_AES_256_CBC_SHA;
731: case 0x38: return TLS_DHE_DSS_WITH_AES_256_CBC_SHA;
732: case 0x39: return TLS_DHE_RSA_WITH_AES_256_CBC_SHA;
733:
757: case 0x8A: return TLS_PSK_WITH_RC4_128_SHA;
758: case 0x8B: return TLS_PSK_WITH_3DES_EDE_CBC_SHA;
759: case 0x8C: return TLS_PSK_WITH_AES_128_CBC_SHA;
760: case 0x8D: return TLS_PSK_WITH_AES_256_CBC_SHA;
761: case 0x8E: return TLS_DHE_PSK_WITH_RC4_128_SHA;
762: case 0x8F: return TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA;
763: case 0x90: return TLS_DHE_PSK_WITH_AES_128_CBC_SHA;
764: case 0x91: return TLS_DHE_PSK_WITH_AES_256_CBC_SHA;
765: case 0x92: return TLS_RSA_PSK_WITH_RC4_128_SHA;
766: case 0x93: return TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA;
767: case 0x94: return TLS_RSA_PSK_WITH_AES_128_CBC_SHA;
768: case 0x95: return TLS_RSA_PSK_WITH_AES_256_CBC_SHA;
769: }
770: return this;
771: }
772:
773: public boolean isResolved()
774: {
775: return isResolved;
776: }
777:
778: public int keyLength()
779: {
780: return keyLength;
781: }
782:
783: public boolean isExportable()
784: {
785: return exportable;
786: }
787:
788: public boolean isStreamCipher()
789: {
790: return isStream;
791: }
792:
793:
794:
795:
796:
797:
798:
799:
800:
801:
802:
803:
804:
805:
806: public byte[] id()
807: {
808: return id;
809: }
810:
811: public boolean equals(Object o)
812: {
813: if (!(o instanceof CipherSuite))
814: {
815: return false;
816: }
817: if (o == this)
818: return true;
819: byte[] id = ((CipherSuite) o).id();
820: return (id[0] == this.id[0] &&
821: id[1] == this.id[1]);
822: }
823:
824: public int hashCode()
825: {
826: return 0xFFFF0000 | (id[0] & 0xFF) << 8 | (id[1] & 0xFF);
827: }
828:
829: public String toString (String prefix)
830: {
831: return toString ();
832: }
833:
834: public String toString()
835: {
836: if (name == null)
837: {
838: return "{ " + (id[0] & 0xFF) + ", " + (id[1] & 0xFF) + " }";
839: }
840: return name;
841: }
842:
843: public boolean isCBCMode()
844: {
845: return isCBCMode;
846: }
847:
848: }