1 /*
   2  * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
   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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 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.
  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 import java.security.SecureRandom;
  34 import java.security.KeyManagementException;
  35 
  36 import javax.crypto.Cipher;
  37 import javax.crypto.SecretKey;
  38 import javax.crypto.spec.IvParameterSpec;
  39 import javax.crypto.spec.SecretKeySpec;
  40 
  41 import static sun.security.ssl.CipherSuite.KeyExchange.*;
  42 import static sun.security.ssl.CipherSuite.PRF.*;
  43 import static sun.security.ssl.CipherSuite.CipherType.*;
  44 import static sun.security.ssl.JsseJce.*;
  45 
  46 /**
  47  * An SSL/TLS CipherSuite. Constants for the standard key exchange, cipher,
  48  * and mac algorithms are also defined in this class.
  49  *
  50  * The CipherSuite class and the inner classes defined in this file roughly
  51  * follow the type safe enum pattern described in Effective Java. This means:
  52  *
  53  *  . instances are immutable, classes are final
  54  *
  55  *  . there is a unique instance of every value, i.e. there are never two
  56  *    instances representing the same CipherSuite, etc. This means equality
  57  *    tests can be performed using == instead of equals() (although that works
  58  *    as well). [A minor exception are *unsupported* CipherSuites read from a
  59  *    handshake message, but this is usually irrelevant]
  60  *
  61  *  . instances are obtained using the static valueOf() factory methods.
  62  *
  63  *  . properties are defined as final variables and made available as
  64  *    package private variables without method accessors
  65  *
  66  *  . if the member variable allowed is false, the given algorithm is either
  67  *    unavailable or disabled at compile time
  68  *
  69  */
  70 final class CipherSuite implements Comparable<CipherSuite> {
  71 
  72     // minimum priority for supported CipherSuites
  73     final static int SUPPORTED_SUITES_PRIORITY = 1;
  74 
  75     // minimum priority for default enabled CipherSuites
  76     final static int DEFAULT_SUITES_PRIORITY = 300;
  77 
  78     private final static boolean ALLOW_ECC = Debug.getBooleanProperty
  79         ("com.sun.net.ssl.enableECC", true);
  80 
  81     // Map Integer(id) -> CipherSuite
  82     // contains all known CipherSuites
  83     private final static Map<Integer,CipherSuite> idMap;
  84 
  85     // Map String(name) -> CipherSuite
  86     // contains only supported CipherSuites (i.e. allowed == true)
  87     private final static Map<String,CipherSuite> nameMap;
  88 
  89     // Protocol defined CipherSuite name, e.g. SSL_RSA_WITH_RC4_128_MD5
  90     // we use TLS_* only for new CipherSuites, still SSL_* for old ones
  91     final String name;
  92 
  93     // id in 16 bit MSB format, i.e. 0x0004 for SSL_RSA_WITH_RC4_128_MD5
  94     final int id;
  95 
  96     // priority for the internal default preference order. the higher the
  97     // better. Each supported CipherSuite *must* have a unique priority.
  98     // Ciphersuites with priority >= DEFAULT_SUITES_PRIORITY are enabled
  99     // by default
 100     final int priority;
 101 
 102     // key exchange, bulk cipher, mac and prf algorithms. See those
 103     // classes below.
 104     final KeyExchange keyExchange;
 105     final BulkCipher cipher;
 106     final MacAlg macAlg;
 107     final PRF prfAlg;
 108 
 109     // whether a CipherSuite qualifies as exportable under 512/40 bit rules.
 110     // TLS 1.1+ (RFC 4346) must not negotiate to these suites.
 111     final boolean exportable;
 112 
 113     // true iff implemented and enabled at compile time
 114     final boolean allowed;
 115 
 116     // obsoleted since protocol version
 117     final int obsoleted;
 118 
 119     // supported since protocol version
 120     final int supported;
 121 
 122     /**
 123      * Constructor for implemented CipherSuites.
 124      */
 125     private CipherSuite(String name, int id, int priority,
 126             KeyExchange keyExchange, BulkCipher cipher,
 127             boolean allowed, int obsoleted, int supported, PRF prfAlg) {
 128         this.name = name;
 129         this.id = id;
 130         this.priority = priority;
 131         this.keyExchange = keyExchange;
 132         this.cipher = cipher;
 133         this.exportable = cipher.exportable;
 134         if (cipher.cipherType == CipherType.AEAD_CIPHER) {
 135             macAlg = M_NULL;
 136         } else if (name.endsWith("_MD5")) {
 137             macAlg = M_MD5;
 138         } else if (name.endsWith("_SHA")) {
 139             macAlg = M_SHA;
 140         } else if (name.endsWith("_SHA256")) {
 141             macAlg = M_SHA256;
 142         } else if (name.endsWith("_SHA384")) {
 143             macAlg = M_SHA384;
 144         } else if (name.endsWith("_NULL")) {
 145             macAlg = M_NULL;
 146         } else if (name.endsWith("_SCSV")) {
 147             macAlg = M_NULL;
 148         } else {
 149             throw new IllegalArgumentException
 150                     ("Unknown MAC algorithm for ciphersuite " + name);
 151         }
 152 
 153         allowed &= keyExchange.allowed;
 154         allowed &= cipher.allowed;
 155         this.allowed = allowed;
 156         this.obsoleted = obsoleted;
 157         this.supported = supported;
 158         this.prfAlg = prfAlg;
 159     }
 160 
 161     /**
 162      * Constructor for unimplemented CipherSuites.
 163      */
 164     private CipherSuite(String name, int id) {
 165         this.name = name;
 166         this.id = id;
 167         this.allowed = false;
 168 
 169         this.priority = 0;
 170         this.keyExchange = null;
 171         this.cipher = null;
 172         this.macAlg = null;
 173         this.exportable = false;
 174         this.obsoleted = ProtocolVersion.LIMIT_MAX_VALUE;
 175         this.supported = ProtocolVersion.LIMIT_MIN_VALUE;
 176         this.prfAlg = P_NONE;
 177     }
 178 
 179     /**
 180      * Return whether this CipherSuite is available for use. A
 181      * CipherSuite may be unavailable even if it is supported
 182      * (i.e. allowed == true) if the required JCE cipher is not installed.
 183      */
 184     boolean isAvailable() {
 185         return allowed && keyExchange.isAvailable() && cipher.isAvailable();
 186     }
 187 
 188     boolean isNegotiable() {
 189         return this != C_SCSV && isAvailable();
 190     }
 191 
 192     /**
 193      * Compares CipherSuites based on their priority. Has the effect of
 194      * sorting CipherSuites when put in a sorted collection, which is
 195      * used by CipherSuiteList. Follows standard Comparable contract.
 196      *
 197      * Note that for unsupported CipherSuites parsed from a handshake
 198      * message we violate the equals() contract.
 199      */
 200     @Override
 201     public int compareTo(CipherSuite o) {
 202         return o.priority - priority;
 203     }
 204 
 205     /**
 206      * Returns this.name.
 207      */
 208     @Override
 209     public String toString() {
 210         return name;
 211     }
 212 
 213     /**
 214      * Return a CipherSuite for the given name. The returned CipherSuite
 215      * is supported by this implementation but may not actually be
 216      * currently useable. See isAvailable().
 217      *
 218      * @exception IllegalArgumentException if the CipherSuite is unknown or
 219      * unsupported.
 220      */
 221     static CipherSuite valueOf(String s) {
 222         if (s == null) {
 223             throw new IllegalArgumentException("Name must not be null");
 224         }
 225 
 226         CipherSuite c = nameMap.get(s);
 227         if ((c == null) || (c.allowed == false)) {
 228             throw new IllegalArgumentException("Unsupported ciphersuite " + s);
 229         }
 230 
 231         return c;
 232     }
 233 
 234     /**
 235      * Return a CipherSuite with the given ID. A temporary object is
 236      * constructed if the ID is unknown. Use isAvailable() to verify that
 237      * the CipherSuite can actually be used.
 238      */
 239     static CipherSuite valueOf(int id1, int id2) {
 240         id1 &= 0xff;
 241         id2 &= 0xff;
 242         int id = (id1 << 8) | id2;
 243         CipherSuite c = idMap.get(id);
 244         if (c == null) {
 245             String h1 = Integer.toString(id1, 16);
 246             String h2 = Integer.toString(id2, 16);
 247             c = new CipherSuite("Unknown 0x" + h1 + ":0x" + h2, id);
 248         }
 249         return c;
 250     }
 251 
 252     // for use by CipherSuiteList only
 253     static Collection<CipherSuite> allowedCipherSuites() {
 254         return nameMap.values();
 255     }
 256 
 257     /*
 258      * Use this method when all of the values need to be specified.
 259      * This is primarily used when defining a new ciphersuite for
 260      * TLS 1.2+ that doesn't use the "default" PRF.
 261      */
 262     private static void add(String name, int id, int priority,
 263             KeyExchange keyExchange, BulkCipher cipher,
 264             boolean allowed, int obsoleted, int supported, PRF prf) {
 265 
 266         CipherSuite c = new CipherSuite(name, id, priority, keyExchange,
 267             cipher, allowed, obsoleted, supported, prf);
 268         if (idMap.put(id, c) != null) {
 269             throw new RuntimeException("Duplicate ciphersuite definition: "
 270                                         + id + ", " + name);
 271         }
 272         if (c.allowed) {
 273             if (nameMap.put(name, c) != null) {
 274                 throw new RuntimeException("Duplicate ciphersuite definition: "
 275                                             + id + ", " + name);
 276             }
 277         }
 278     }
 279 
 280     /*
 281      * Use this method when there is no lower protocol limit where this
 282      * suite can be used, and the PRF is P_SHA256.  That is, the
 283      * existing ciphersuites.  From RFC 5246:
 284      *
 285      *     All cipher suites in this document use P_SHA256.
 286      */
 287     private static void add(String name, int id, int priority,
 288             KeyExchange keyExchange, BulkCipher cipher,
 289             boolean allowed, int obsoleted) {
 290         // If this is an obsoleted suite, then don't let the TLS 1.2
 291         // protocol have a valid PRF value.
 292         PRF prf = P_SHA256;
 293         if (obsoleted < ProtocolVersion.TLS12.v) {
 294             prf = P_NONE;
 295         }
 296 
 297         add(name, id, priority, keyExchange, cipher, allowed, obsoleted,
 298             ProtocolVersion.LIMIT_MIN_VALUE, prf);
 299     }
 300 
 301     /*
 302      * Use this method when there is no upper protocol limit.  That is,
 303      * suites which have not been obsoleted.
 304      */
 305     private static void add(String name, int id, int priority,
 306             KeyExchange keyExchange, BulkCipher cipher, boolean allowed) {
 307         add(name, id, priority, keyExchange,
 308             cipher, allowed, ProtocolVersion.LIMIT_MAX_VALUE);
 309     }
 310 
 311     /*
 312      * Use this method to define an unimplemented suite.  This provides
 313      * a number<->name mapping that can be used for debugging.
 314      */
 315     private static void add(String name, int id) {
 316         CipherSuite c = new CipherSuite(name, id);
 317         if (idMap.put(id, c) != null) {
 318             throw new RuntimeException("Duplicate ciphersuite definition: "
 319                                         + id + ", " + name);
 320         }
 321     }
 322 
 323     /**
 324      * An SSL/TLS key exchange algorithm.
 325      */
 326     static enum KeyExchange {
 327 
 328         // key exchange algorithms
 329         K_NULL       ("NULL",       false),
 330         K_RSA        ("RSA",        true),
 331         K_RSA_EXPORT ("RSA_EXPORT", true),
 332         K_DH_RSA     ("DH_RSA",     false),
 333         K_DH_DSS     ("DH_DSS",     false),
 334         K_DHE_DSS    ("DHE_DSS",    true),
 335         K_DHE_RSA    ("DHE_RSA",    true),
 336         K_DH_ANON    ("DH_anon",    true),
 337 
 338         K_ECDH_ECDSA ("ECDH_ECDSA",  ALLOW_ECC),
 339         K_ECDH_RSA   ("ECDH_RSA",    ALLOW_ECC),
 340         K_ECDHE_ECDSA("ECDHE_ECDSA", ALLOW_ECC),
 341         K_ECDHE_RSA  ("ECDHE_RSA",   ALLOW_ECC),
 342         K_ECDH_ANON  ("ECDH_anon",   ALLOW_ECC),
 343 
 344         // Kerberos cipher suites
 345         K_KRB5       ("KRB5", true),
 346         K_KRB5_EXPORT("KRB5_EXPORT", true),
 347 
 348         // renegotiation protection request signaling cipher suite
 349         K_SCSV       ("SCSV",        true);
 350 
 351         // name of the key exchange algorithm, e.g. DHE_DSS
 352         final String name;
 353         final boolean allowed;
 354         private final boolean alwaysAvailable;
 355 
 356         KeyExchange(String name, boolean allowed) {
 357             this.name = name;
 358             this.allowed = allowed;
 359             this.alwaysAvailable = allowed &&
 360                 (!name.startsWith("EC")) && (!name.startsWith("KRB"));
 361         }
 362 
 363         boolean isAvailable() {
 364             if (alwaysAvailable) {
 365                 return true;
 366             }
 367 
 368             if (name.startsWith("EC")) {
 369                 return (allowed && JsseJce.isEcAvailable());
 370             } else if (name.startsWith("KRB")) {
 371                 return (allowed && JsseJce.isKerberosAvailable());
 372             } else {
 373                 return allowed;
 374             }
 375         }
 376 
 377         @Override
 378         public String toString() {
 379             return name;
 380         }
 381     }
 382 
 383     static enum CipherType {
 384         STREAM_CIPHER,         // null or stream cipher
 385         BLOCK_CIPHER,          // block cipher in CBC mode
 386         AEAD_CIPHER            // AEAD cipher
 387     }
 388 
 389     /**
 390      * An SSL/TLS bulk cipher algorithm. One instance per combination of
 391      * cipher and key length.
 392      *
 393      * Also contains a factory method to obtain in initialized CipherBox
 394      * for this algorithm.
 395      */
 396     final static class BulkCipher {
 397 
 398         // descriptive name including key size, e.g. AES/128
 399         final String description;
 400 
 401         // JCE cipher transformation string, e.g. AES/CBC/NoPadding
 402         final String transformation;
 403 
 404         // algorithm name, e.g. AES
 405         final String algorithm;
 406 
 407         // supported and compile time enabled. Also see isAvailable()
 408         final boolean allowed;
 409 
 410         // number of bytes of entropy in the key
 411         final int keySize;
 412 
 413         // length of the actual cipher key in bytes.
 414         // for non-exportable ciphers, this is the same as keySize
 415         final int expandedKeySize;
 416 
 417         // size of the IV
 418         final int ivSize;
 419 
 420         // size of fixed IV
 421         //
 422         // record_iv_length = ivSize - fixedIvSize
 423         final int fixedIvSize;
 424 
 425         // exportable under 512/40 bit rules
 426         final boolean exportable;
 427 
 428         // Is the cipher algorithm of Cipher Block Chaining (CBC) mode?
 429         final CipherType cipherType;
 430 
 431         // size of the authentication tag, only applicable to cipher suites in
 432         // Galois Counter Mode (GCM)
 433         //
 434         // As far as we know, all supported GCM cipher suites use 128-bits
 435         // authentication tags.
 436         final int tagSize = 16;
 437 
 438         // The secure random used to detect the cipher availability.
 439         private final static SecureRandom secureRandom;
 440 
 441         // runtime availability
 442         private final boolean isAvailable;
 443 
 444         static {
 445             try {
 446                 secureRandom = JsseJce.getSecureRandom();
 447             } catch (KeyManagementException kme) {
 448                 throw new RuntimeException(kme);
 449             }
 450         }
 451 
 452         BulkCipher(String transformation, CipherType cipherType, int keySize,
 453                 int expandedKeySize, int ivSize,
 454                 int fixedIvSize, boolean allowed) {
 455 
 456             this.transformation = transformation;
 457             String[] splits = transformation.split("/");
 458             this.algorithm = splits[0];
 459             this.cipherType = cipherType;
 460             this.description = this.algorithm + "/" + (keySize << 3);
 461             this.keySize = keySize;
 462             this.ivSize = ivSize;
 463             this.fixedIvSize = fixedIvSize;
 464             this.allowed = allowed;
 465 
 466             this.expandedKeySize = expandedKeySize;
 467             this.exportable = true;
 468 
 469             // availability of this bulk cipher
 470             //
 471             // Currently all supported ciphers except AES are always available
 472             // via the JSSE internal implementations. We also assume AES/128 of
 473             // CBC mode is always available since it is shipped with the SunJCE
 474             // provider.  However, AES/256 is unavailable when the default JCE
 475             // policy jurisdiction files are installed because of key length
 476             // restrictions.
 477             this.isAvailable =
 478                     allowed ? isUnlimited(keySize, transformation) : false;
 479         }
 480 
 481         BulkCipher(String transformation, CipherType cipherType, int keySize,
 482                 int ivSize, int fixedIvSize, boolean allowed) {
 483             this.transformation = transformation;
 484             String[] splits = transformation.split("/");
 485             this.algorithm = splits[0];
 486             this.cipherType = cipherType;
 487             this.description = this.algorithm + "/" + (keySize << 3);
 488             this.keySize = keySize;
 489             this.ivSize = ivSize;
 490             this.fixedIvSize = fixedIvSize;
 491             this.allowed = allowed;
 492 
 493             this.expandedKeySize = keySize;
 494             this.exportable = false;
 495 
 496             // availability of this bulk cipher
 497             //
 498             // Currently all supported ciphers except AES are always available
 499             // via the JSSE internal implementations. We also assume AES/128 of
 500             // CBC mode is always available since it is shipped with the SunJCE
 501             // provider.  However, AES/256 is unavailable when the default JCE
 502             // policy jurisdiction files are installed because of key length
 503             // restrictions.
 504             this.isAvailable =
 505                     allowed ? isUnlimited(keySize, transformation) : false;
 506         }
 507 
 508         /**
 509          * Return an initialized CipherBox for this BulkCipher.
 510          * IV must be null for stream ciphers.
 511          *
 512          * @exception NoSuchAlgorithmException if anything goes wrong
 513          */
 514         CipherBox newCipher(ProtocolVersion version, SecretKey key,
 515                 IvParameterSpec iv, SecureRandom random,
 516                 boolean encrypt) throws NoSuchAlgorithmException {
 517             return CipherBox.newCipherBox(version, this,
 518                                             key, iv, random, encrypt);
 519         }
 520 
 521         /**
 522          * Test if this bulk cipher is available. For use by CipherSuite.
 523          */
 524         boolean isAvailable() {
 525             return this.isAvailable;
 526         }
 527 
 528         private static boolean isUnlimited(int keySize, String transformation) {
 529             int keySizeInBits = keySize * 8;
 530             if (keySizeInBits > 128) {    // need the JCE unlimited
 531                                           // strength jurisdiction policy
 532                 try {
 533                     if (Cipher.getMaxAllowedKeyLength(
 534                             transformation) < keySizeInBits) {
 535 
 536                         return false;
 537                     }
 538                 } catch (Exception e) {
 539                     return false;
 540                 }
 541             }
 542 
 543             return true;
 544         }
 545 
 546         @Override
 547         public String toString() {
 548             return description;
 549         }
 550     }
 551 
 552     /**
 553      * An SSL/TLS key MAC algorithm.
 554      *
 555      * Also contains a factory method to obtain an initialized MAC
 556      * for this algorithm.
 557      */
 558     final static class MacAlg {
 559 
 560         // descriptive name, e.g. MD5
 561         final String name;
 562 
 563         // size of the MAC value (and MAC key) in bytes
 564         final int size;
 565 
 566         // block size of the underlying hash algorithm
 567         final int hashBlockSize;
 568 
 569         // minimal padding size of the underlying hash algorithm
 570         final int minimalPaddingSize;
 571 
 572         MacAlg(String name, int size,
 573                 int hashBlockSize, int minimalPaddingSize) {
 574             this.name = name;
 575             this.size = size;
 576             this.hashBlockSize = hashBlockSize;
 577             this.minimalPaddingSize = minimalPaddingSize;
 578         }
 579 
 580         /**
 581          * Return an initialized MAC for this MacAlg. ProtocolVersion
 582          * must either be SSL30 (SSLv3 custom MAC) or TLS10 (std. HMAC).
 583          *
 584          * @exception NoSuchAlgorithmException if anything goes wrong
 585          */
 586         MAC newMac(ProtocolVersion protocolVersion, SecretKey secret)
 587                 throws NoSuchAlgorithmException, InvalidKeyException {
 588             return new MAC(this, protocolVersion, secret);
 589         }
 590 
 591         @Override
 592         public String toString() {
 593             return name;
 594         }
 595     }
 596 
 597     // export strength ciphers
 598     final static BulkCipher B_NULL    =
 599         new BulkCipher("NULL",          STREAM_CIPHER,    0,  0,  0, 0, true);
 600     final static BulkCipher B_RC4_40  =
 601         new BulkCipher(CIPHER_RC4,      STREAM_CIPHER,    5, 16,  0, 0, true);
 602     final static BulkCipher B_RC2_40  =
 603         new BulkCipher("RC2",           BLOCK_CIPHER,     5, 16,  8, 0, false);
 604     final static BulkCipher B_DES_40  =
 605         new BulkCipher(CIPHER_DES,      BLOCK_CIPHER,     5,  8,  8, 0, true);
 606 
 607     // domestic strength ciphers
 608     final static BulkCipher B_RC4_128 =
 609         new BulkCipher(CIPHER_RC4,      STREAM_CIPHER,   16,  0,  0, true);
 610     final static BulkCipher B_DES     =
 611         new BulkCipher(CIPHER_DES,      BLOCK_CIPHER,     8,  8,  0, true);
 612     final static BulkCipher B_3DES    =
 613         new BulkCipher(CIPHER_3DES,     BLOCK_CIPHER,    24,  8,  0, true);
 614     final static BulkCipher B_IDEA    =
 615         new BulkCipher("IDEA",          BLOCK_CIPHER,    16,  8,  0, false);
 616     final static BulkCipher B_AES_128 =
 617         new BulkCipher(CIPHER_AES,      BLOCK_CIPHER,    16, 16,  0, true);
 618     final static BulkCipher B_AES_256 =
 619         new BulkCipher(CIPHER_AES,      BLOCK_CIPHER,    32, 16,  0, true);
 620     final static BulkCipher B_AES_128_GCM =
 621         new BulkCipher(CIPHER_AES_GCM,  AEAD_CIPHER,     16, 12,  4, true);
 622     final static BulkCipher B_AES_256_GCM =
 623         new BulkCipher(CIPHER_AES_GCM,  AEAD_CIPHER,     32, 12,  4, true);
 624 
 625     // MACs
 626     final static MacAlg M_NULL    = new MacAlg("NULL",     0,   0,   0);
 627     final static MacAlg M_MD5     = new MacAlg("MD5",     16,  64,   9);
 628     final static MacAlg M_SHA     = new MacAlg("SHA",     20,  64,   9);
 629     final static MacAlg M_SHA256  = new MacAlg("SHA256",  32,  64,   9);
 630     final static MacAlg M_SHA384  = new MacAlg("SHA384",  48, 128,  17);
 631 
 632     /**
 633      * PRFs (PseudoRandom Function) from TLS specifications.
 634      *
 635      * TLS 1.1- uses a single MD5/SHA1-based PRF algorithm for generating
 636      * the necessary material.
 637      *
 638      * In TLS 1.2+, all existing/known CipherSuites use SHA256, however
 639      * new Ciphersuites (e.g. RFC 5288) can define specific PRF hash
 640      * algorithms.
 641      */
 642     static enum PRF {
 643 
 644         // PRF algorithms
 645         P_NONE(     "NONE",  0,   0),
 646         P_SHA256("SHA-256", 32,  64),
 647         P_SHA384("SHA-384", 48, 128),
 648         P_SHA512("SHA-512", 64, 128);  // not currently used.
 649 
 650         // PRF characteristics
 651         private final String prfHashAlg;
 652         private final int prfHashLength;
 653         private final int prfBlockSize;
 654 
 655         PRF(String prfHashAlg, int prfHashLength, int prfBlockSize) {
 656             this.prfHashAlg = prfHashAlg;
 657             this.prfHashLength = prfHashLength;
 658             this.prfBlockSize = prfBlockSize;
 659         }
 660 
 661         String getPRFHashAlg() {
 662             return prfHashAlg;
 663         }
 664 
 665         int getPRFHashLength() {
 666             return prfHashLength;
 667         }
 668 
 669         int getPRFBlockSize() {
 670             return prfBlockSize;
 671         }
 672     }
 673 
 674     static {
 675         idMap = new HashMap<Integer,CipherSuite>();
 676         nameMap = new HashMap<String,CipherSuite>();
 677 
 678         final boolean F = false;
 679         final boolean T = true;
 680         // N: ciphersuites only allowed if we are not in FIPS mode
 681         final boolean N = (SunJSSE.isFIPS() == false);
 682 
 683         /*
 684          * TLS Cipher Suite Registry, as of August 2010.
 685          *
 686          * http://www.iana.org/assignments/tls-parameters/tls-parameters.xml
 687          *
 688          * Range      Registration Procedures   Notes
 689          * 000-191    Standards Action          Refers to value of first byte
 690          * 192-254    Specification Required    Refers to value of first byte
 691          * 255        Reserved for Private Use  Refers to value of first byte
 692          *
 693          * Value      Description                               Reference
 694          * 0x00,0x00  TLS_NULL_WITH_NULL_NULL                   [RFC5246]
 695          * 0x00,0x01  TLS_RSA_WITH_NULL_MD5                     [RFC5246]
 696          * 0x00,0x02  TLS_RSA_WITH_NULL_SHA                     [RFC5246]
 697          * 0x00,0x03  TLS_RSA_EXPORT_WITH_RC4_40_MD5            [RFC4346]
 698          * 0x00,0x04  TLS_RSA_WITH_RC4_128_MD5                  [RFC5246]
 699          * 0x00,0x05  TLS_RSA_WITH_RC4_128_SHA                  [RFC5246]
 700          * 0x00,0x06  TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5        [RFC4346]
 701          * 0x00,0x07  TLS_RSA_WITH_IDEA_CBC_SHA                 [RFC5469]
 702          * 0x00,0x08  TLS_RSA_EXPORT_WITH_DES40_CBC_SHA         [RFC4346]
 703          * 0x00,0x09  TLS_RSA_WITH_DES_CBC_SHA                  [RFC5469]
 704          * 0x00,0x0A  TLS_RSA_WITH_3DES_EDE_CBC_SHA             [RFC5246]
 705          * 0x00,0x0B  TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA      [RFC4346]
 706          * 0x00,0x0C  TLS_DH_DSS_WITH_DES_CBC_SHA               [RFC5469]
 707          * 0x00,0x0D  TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA          [RFC5246]
 708          * 0x00,0x0E  TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA      [RFC4346]
 709          * 0x00,0x0F  TLS_DH_RSA_WITH_DES_CBC_SHA               [RFC5469]
 710          * 0x00,0x10  TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA          [RFC5246]
 711          * 0x00,0x11  TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA     [RFC4346]
 712          * 0x00,0x12  TLS_DHE_DSS_WITH_DES_CBC_SHA              [RFC5469]
 713          * 0x00,0x13  TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA         [RFC5246]
 714          * 0x00,0x14  TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA     [RFC4346]
 715          * 0x00,0x15  TLS_DHE_RSA_WITH_DES_CBC_SHA              [RFC5469]
 716          * 0x00,0x16  TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA         [RFC5246]
 717          * 0x00,0x17  TLS_DH_anon_EXPORT_WITH_RC4_40_MD5        [RFC4346]
 718          * 0x00,0x18  TLS_DH_anon_WITH_RC4_128_MD5              [RFC5246]
 719          * 0x00,0x19  TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA     [RFC4346]
 720          * 0x00,0x1A  TLS_DH_anon_WITH_DES_CBC_SHA              [RFC5469]
 721          * 0x00,0x1B  TLS_DH_anon_WITH_3DES_EDE_CBC_SHA         [RFC5246]
 722          * 0x00,0x1C-1D Reserved to avoid conflicts with SSLv3  [RFC5246]
 723          * 0x00,0x1E  TLS_KRB5_WITH_DES_CBC_SHA                 [RFC2712]
 724          * 0x00,0x1F  TLS_KRB5_WITH_3DES_EDE_CBC_SHA            [RFC2712]
 725          * 0x00,0x20  TLS_KRB5_WITH_RC4_128_SHA                 [RFC2712]
 726          * 0x00,0x21  TLS_KRB5_WITH_IDEA_CBC_SHA                [RFC2712]
 727          * 0x00,0x22  TLS_KRB5_WITH_DES_CBC_MD5                 [RFC2712]
 728          * 0x00,0x23  TLS_KRB5_WITH_3DES_EDE_CBC_MD5            [RFC2712]
 729          * 0x00,0x24  TLS_KRB5_WITH_RC4_128_MD5                 [RFC2712]
 730          * 0x00,0x25  TLS_KRB5_WITH_IDEA_CBC_MD5                [RFC2712]
 731          * 0x00,0x26  TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA       [RFC2712]
 732          * 0x00,0x27  TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA       [RFC2712]
 733          * 0x00,0x28  TLS_KRB5_EXPORT_WITH_RC4_40_SHA           [RFC2712]
 734          * 0x00,0x29  TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5       [RFC2712]
 735          * 0x00,0x2A  TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5       [RFC2712]
 736          * 0x00,0x2B  TLS_KRB5_EXPORT_WITH_RC4_40_MD5           [RFC2712]
 737          * 0x00,0x2C  TLS_PSK_WITH_NULL_SHA                     [RFC4785]
 738          * 0x00,0x2D  TLS_DHE_PSK_WITH_NULL_SHA                 [RFC4785]
 739          * 0x00,0x2E  TLS_RSA_PSK_WITH_NULL_SHA                 [RFC4785]
 740          * 0x00,0x2F  TLS_RSA_WITH_AES_128_CBC_SHA              [RFC5246]
 741          * 0x00,0x30  TLS_DH_DSS_WITH_AES_128_CBC_SHA           [RFC5246]
 742          * 0x00,0x31  TLS_DH_RSA_WITH_AES_128_CBC_SHA           [RFC5246]
 743          * 0x00,0x32  TLS_DHE_DSS_WITH_AES_128_CBC_SHA          [RFC5246]
 744          * 0x00,0x33  TLS_DHE_RSA_WITH_AES_128_CBC_SHA          [RFC5246]
 745          * 0x00,0x34  TLS_DH_anon_WITH_AES_128_CBC_SHA          [RFC5246]
 746          * 0x00,0x35  TLS_RSA_WITH_AES_256_CBC_SHA              [RFC5246]
 747          * 0x00,0x36  TLS_DH_DSS_WITH_AES_256_CBC_SHA           [RFC5246]
 748          * 0x00,0x37  TLS_DH_RSA_WITH_AES_256_CBC_SHA           [RFC5246]
 749          * 0x00,0x38  TLS_DHE_DSS_WITH_AES_256_CBC_SHA          [RFC5246]
 750          * 0x00,0x39  TLS_DHE_RSA_WITH_AES_256_CBC_SHA          [RFC5246]
 751          * 0x00,0x3A  TLS_DH_anon_WITH_AES_256_CBC_SHA          [RFC5246]
 752          * 0x00,0x3B  TLS_RSA_WITH_NULL_SHA256                  [RFC5246]
 753          * 0x00,0x3C  TLS_RSA_WITH_AES_128_CBC_SHA256           [RFC5246]
 754          * 0x00,0x3D  TLS_RSA_WITH_AES_256_CBC_SHA256           [RFC5246]
 755          * 0x00,0x3E  TLS_DH_DSS_WITH_AES_128_CBC_SHA256        [RFC5246]
 756          * 0x00,0x3F  TLS_DH_RSA_WITH_AES_128_CBC_SHA256        [RFC5246]
 757          * 0x00,0x40  TLS_DHE_DSS_WITH_AES_128_CBC_SHA256       [RFC5246]
 758          * 0x00,0x41  TLS_RSA_WITH_CAMELLIA_128_CBC_SHA         [RFC5932]
 759          * 0x00,0x42  TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA      [RFC5932]
 760          * 0x00,0x43  TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA      [RFC5932]
 761          * 0x00,0x44  TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA     [RFC5932]
 762          * 0x00,0x45  TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA     [RFC5932]
 763          * 0x00,0x46  TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA     [RFC5932]
 764          * 0x00,0x47-4F Reserved to avoid conflicts with
 765          *            deployed implementations                  [Pasi_Eronen]
 766          * 0x00,0x50-58 Reserved to avoid conflicts             [Pasi Eronen]
 767          * 0x00,0x59-5C Reserved to avoid conflicts with
 768          *            deployed implementations                  [Pasi_Eronen]
 769          * 0x00,0x5D-5F Unassigned
 770          * 0x00,0x60-66 Reserved to avoid conflicts with widely
 771          *            deployed implementations                  [Pasi_Eronen]
 772          * 0x00,0x67  TLS_DHE_RSA_WITH_AES_128_CBC_SHA256       [RFC5246]
 773          * 0x00,0x68  TLS_DH_DSS_WITH_AES_256_CBC_SHA256        [RFC5246]
 774          * 0x00,0x69  TLS_DH_RSA_WITH_AES_256_CBC_SHA256        [RFC5246]
 775          * 0x00,0x6A  TLS_DHE_DSS_WITH_AES_256_CBC_SHA256       [RFC5246]
 776          * 0x00,0x6B  TLS_DHE_RSA_WITH_AES_256_CBC_SHA256       [RFC5246]
 777          * 0x00,0x6C  TLS_DH_anon_WITH_AES_128_CBC_SHA256       [RFC5246]
 778          * 0x00,0x6D  TLS_DH_anon_WITH_AES_256_CBC_SHA256       [RFC5246]
 779          * 0x00,0x6E-83 Unassigned
 780          * 0x00,0x84  TLS_RSA_WITH_CAMELLIA_256_CBC_SHA         [RFC5932]
 781          * 0x00,0x85  TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA      [RFC5932]
 782          * 0x00,0x86  TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA      [RFC5932]
 783          * 0x00,0x87  TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA     [RFC5932]
 784          * 0x00,0x88  TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA     [RFC5932]
 785          * 0x00,0x89  TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA     [RFC5932]
 786          * 0x00,0x8A  TLS_PSK_WITH_RC4_128_SHA                  [RFC4279]
 787          * 0x00,0x8B  TLS_PSK_WITH_3DES_EDE_CBC_SHA             [RFC4279]
 788          * 0x00,0x8C  TLS_PSK_WITH_AES_128_CBC_SHA              [RFC4279]
 789          * 0x00,0x8D  TLS_PSK_WITH_AES_256_CBC_SHA              [RFC4279]
 790          * 0x00,0x8E  TLS_DHE_PSK_WITH_RC4_128_SHA              [RFC4279]
 791          * 0x00,0x8F  TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA         [RFC4279]
 792          * 0x00,0x90  TLS_DHE_PSK_WITH_AES_128_CBC_SHA          [RFC4279]
 793          * 0x00,0x91  TLS_DHE_PSK_WITH_AES_256_CBC_SHA          [RFC4279]
 794          * 0x00,0x92  TLS_RSA_PSK_WITH_RC4_128_SHA              [RFC4279]
 795          * 0x00,0x93  TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA         [RFC4279]
 796          * 0x00,0x94  TLS_RSA_PSK_WITH_AES_128_CBC_SHA          [RFC4279]
 797          * 0x00,0x95  TLS_RSA_PSK_WITH_AES_256_CBC_SHA          [RFC4279]
 798          * 0x00,0x96  TLS_RSA_WITH_SEED_CBC_SHA                 [RFC4162]
 799          * 0x00,0x97  TLS_DH_DSS_WITH_SEED_CBC_SHA              [RFC4162]
 800          * 0x00,0x98  TLS_DH_RSA_WITH_SEED_CBC_SHA              [RFC4162]
 801          * 0x00,0x99  TLS_DHE_DSS_WITH_SEED_CBC_SHA             [RFC4162]
 802          * 0x00,0x9A  TLS_DHE_RSA_WITH_SEED_CBC_SHA             [RFC4162]
 803          * 0x00,0x9B  TLS_DH_anon_WITH_SEED_CBC_SHA             [RFC4162]
 804          * 0x00,0x9C  TLS_RSA_WITH_AES_128_GCM_SHA256           [RFC5288]
 805          * 0x00,0x9D  TLS_RSA_WITH_AES_256_GCM_SHA384           [RFC5288]
 806          * 0x00,0x9E  TLS_DHE_RSA_WITH_AES_128_GCM_SHA256       [RFC5288]
 807          * 0x00,0x9F  TLS_DHE_RSA_WITH_AES_256_GCM_SHA384       [RFC5288]
 808          * 0x00,0xA0  TLS_DH_RSA_WITH_AES_128_GCM_SHA256        [RFC5288]
 809          * 0x00,0xA1  TLS_DH_RSA_WITH_AES_256_GCM_SHA384        [RFC5288]
 810          * 0x00,0xA2  TLS_DHE_DSS_WITH_AES_128_GCM_SHA256       [RFC5288]
 811          * 0x00,0xA3  TLS_DHE_DSS_WITH_AES_256_GCM_SHA384       [RFC5288]
 812          * 0x00,0xA4  TLS_DH_DSS_WITH_AES_128_GCM_SHA256        [RFC5288]
 813          * 0x00,0xA5  TLS_DH_DSS_WITH_AES_256_GCM_SHA384        [RFC5288]
 814          * 0x00,0xA6  TLS_DH_anon_WITH_AES_128_GCM_SHA256       [RFC5288]
 815          * 0x00,0xA7  TLS_DH_anon_WITH_AES_256_GCM_SHA384       [RFC5288]
 816          * 0x00,0xA8  TLS_PSK_WITH_AES_128_GCM_SHA256           [RFC5487]
 817          * 0x00,0xA9  TLS_PSK_WITH_AES_256_GCM_SHA384           [RFC5487]
 818          * 0x00,0xAA  TLS_DHE_PSK_WITH_AES_128_GCM_SHA256       [RFC5487]
 819          * 0x00,0xAB  TLS_DHE_PSK_WITH_AES_256_GCM_SHA384       [RFC5487]
 820          * 0x00,0xAC  TLS_RSA_PSK_WITH_AES_128_GCM_SHA256       [RFC5487]
 821          * 0x00,0xAD  TLS_RSA_PSK_WITH_AES_256_GCM_SHA384       [RFC5487]
 822          * 0x00,0xAE  TLS_PSK_WITH_AES_128_CBC_SHA256           [RFC5487]
 823          * 0x00,0xAF  TLS_PSK_WITH_AES_256_CBC_SHA384           [RFC5487]
 824          * 0x00,0xB0  TLS_PSK_WITH_NULL_SHA256                  [RFC5487]
 825          * 0x00,0xB1  TLS_PSK_WITH_NULL_SHA384                  [RFC5487]
 826          * 0x00,0xB2  TLS_DHE_PSK_WITH_AES_128_CBC_SHA256       [RFC5487]
 827          * 0x00,0xB3  TLS_DHE_PSK_WITH_AES_256_CBC_SHA384       [RFC5487]
 828          * 0x00,0xB4  TLS_DHE_PSK_WITH_NULL_SHA256              [RFC5487]
 829          * 0x00,0xB5  TLS_DHE_PSK_WITH_NULL_SHA384              [RFC5487]
 830          * 0x00,0xB6  TLS_RSA_PSK_WITH_AES_128_CBC_SHA256       [RFC5487]
 831          * 0x00,0xB7  TLS_RSA_PSK_WITH_AES_256_CBC_SHA384       [RFC5487]
 832          * 0x00,0xB8  TLS_RSA_PSK_WITH_NULL_SHA256              [RFC5487]
 833          * 0x00,0xB9  TLS_RSA_PSK_WITH_NULL_SHA384              [RFC5487]
 834          * 0x00,0xBA  TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256      [RFC5932]
 835          * 0x00,0xBB  TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256   [RFC5932]
 836          * 0x00,0xBC  TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256   [RFC5932]
 837          * 0x00,0xBD  TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256  [RFC5932]
 838          * 0x00,0xBE  TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256  [RFC5932]
 839          * 0x00,0xBF  TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256  [RFC5932]
 840          * 0x00,0xC0  TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256      [RFC5932]
 841          * 0x00,0xC1  TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256   [RFC5932]
 842          * 0x00,0xC2  TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256   [RFC5932]
 843          * 0x00,0xC3  TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256  [RFC5932]
 844          * 0x00,0xC4  TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256  [RFC5932]
 845          * 0x00,0xC5  TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256  [RFC5932]
 846          * 0x00,0xC6-FE         Unassigned
 847          * 0x00,0xFF  TLS_EMPTY_RENEGOTIATION_INFO_SCSV         [RFC5746]
 848          * 0x01-BF,*  Unassigned
 849          * 0xC0,0x01  TLS_ECDH_ECDSA_WITH_NULL_SHA              [RFC4492]
 850          * 0xC0,0x02  TLS_ECDH_ECDSA_WITH_RC4_128_SHA           [RFC4492]
 851          * 0xC0,0x03  TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA      [RFC4492]
 852          * 0xC0,0x04  TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA       [RFC4492]
 853          * 0xC0,0x05  TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA       [RFC4492]
 854          * 0xC0,0x06  TLS_ECDHE_ECDSA_WITH_NULL_SHA             [RFC4492]
 855          * 0xC0,0x07  TLS_ECDHE_ECDSA_WITH_RC4_128_SHA          [RFC4492]
 856          * 0xC0,0x08  TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA     [RFC4492]
 857          * 0xC0,0x09  TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA      [RFC4492]
 858          * 0xC0,0x0A  TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA      [RFC4492]
 859          * 0xC0,0x0B  TLS_ECDH_RSA_WITH_NULL_SHA                [RFC4492]
 860          * 0xC0,0x0C  TLS_ECDH_RSA_WITH_RC4_128_SHA             [RFC4492]
 861          * 0xC0,0x0D  TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA        [RFC4492]
 862          * 0xC0,0x0E  TLS_ECDH_RSA_WITH_AES_128_CBC_SHA         [RFC4492]
 863          * 0xC0,0x0F  TLS_ECDH_RSA_WITH_AES_256_CBC_SHA         [RFC4492]
 864          * 0xC0,0x10  TLS_ECDHE_RSA_WITH_NULL_SHA               [RFC4492]
 865          * 0xC0,0x11  TLS_ECDHE_RSA_WITH_RC4_128_SHA            [RFC4492]
 866          * 0xC0,0x12  TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA       [RFC4492]
 867          * 0xC0,0x13  TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA        [RFC4492]
 868          * 0xC0,0x14  TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA        [RFC4492]
 869          * 0xC0,0x15  TLS_ECDH_anon_WITH_NULL_SHA               [RFC4492]
 870          * 0xC0,0x16  TLS_ECDH_anon_WITH_RC4_128_SHA            [RFC4492]
 871          * 0xC0,0x17  TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA       [RFC4492]
 872          * 0xC0,0x18  TLS_ECDH_anon_WITH_AES_128_CBC_SHA        [RFC4492]
 873          * 0xC0,0x19  TLS_ECDH_anon_WITH_AES_256_CBC_SHA        [RFC4492]
 874          * 0xC0,0x1A  TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA         [RFC5054]
 875          * 0xC0,0x1B  TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA     [RFC5054]
 876          * 0xC0,0x1C  TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA     [RFC5054]
 877          * 0xC0,0x1D  TLS_SRP_SHA_WITH_AES_128_CBC_SHA          [RFC5054]
 878          * 0xC0,0x1E  TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA      [RFC5054]
 879          * 0xC0,0x1F  TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA      [RFC5054]
 880          * 0xC0,0x20  TLS_SRP_SHA_WITH_AES_256_CBC_SHA          [RFC5054]
 881          * 0xC0,0x21  TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA      [RFC5054]
 882          * 0xC0,0x22  TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA      [RFC5054]
 883          * 0xC0,0x23  TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256   [RFC5289]
 884          * 0xC0,0x24  TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384   [RFC5289]
 885          * 0xC0,0x25  TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256    [RFC5289]
 886          * 0xC0,0x26  TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384    [RFC5289]
 887          * 0xC0,0x27  TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256     [RFC5289]
 888          * 0xC0,0x28  TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384     [RFC5289]
 889          * 0xC0,0x29  TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256      [RFC5289]
 890          * 0xC0,0x2A  TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384      [RFC5289]
 891          * 0xC0,0x2B  TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256   [RFC5289]
 892          * 0xC0,0x2C  TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384   [RFC5289]
 893          * 0xC0,0x2D  TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256    [RFC5289]
 894          * 0xC0,0x2E  TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384    [RFC5289]
 895          * 0xC0,0x2F  TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256     [RFC5289]
 896          * 0xC0,0x30  TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384     [RFC5289]
 897          * 0xC0,0x31  TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256      [RFC5289]
 898          * 0xC0,0x32  TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384      [RFC5289]
 899          * 0xC0,0x33  TLS_ECDHE_PSK_WITH_RC4_128_SHA            [RFC5489]
 900          * 0xC0,0x34  TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA       [RFC5489]
 901          * 0xC0,0x35  TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA        [RFC5489]
 902          * 0xC0,0x36  TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA        [RFC5489]
 903          * 0xC0,0x37  TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256     [RFC5489]
 904          * 0xC0,0x38  TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384     [RFC5489]
 905          * 0xC0,0x39  TLS_ECDHE_PSK_WITH_NULL_SHA               [RFC5489]
 906          * 0xC0,0x3A  TLS_ECDHE_PSK_WITH_NULL_SHA256            [RFC5489]
 907          * 0xC0,0x3B  TLS_ECDHE_PSK_WITH_NULL_SHA384            [RFC5489]
 908          * 0xC0,0x3C-FF Unassigned
 909          * 0xC1-FD,*  Unassigned
 910          * 0xFE,0x00-FD Unassigned
 911          * 0xFE,0xFE-FF Reserved to avoid conflicts with widely
 912          *            deployed implementations                  [Pasi_Eronen]
 913          * 0xFF,0x00-FF Reserved for Private Use                [RFC5246]
 914          */
 915 
 916         add("SSL_NULL_WITH_NULL_NULL",
 917                               0x0000,   1, K_NULL,       B_NULL,    F);
 918 
 919         /*
 920          * Definition of the CipherSuites that are enabled by default.
 921          * They are listed in preference order, most preferred first, using
 922          * the following criteria:
 923          * 1. Prefer Suite B compliant cipher suites, see RFC6460 (To be
 924          *    changed later, see below).
 925          * 2. Prefer the stronger bulk cipher, in the order of AES_256(GCM),
 926          *    AES_128(GCM), AES_256, AES_128, 3DES-EDE.
 927          * 3. Prefer the stronger MAC algorithm, in the order of SHA384,
 928          *    SHA256, SHA, MD5.
 929          * 4. Prefer the better performance of key exchange and digital
 930          *    signature algorithm, in the order of ECDHE-ECDSA, ECDHE-RSA,
 931          *    RSA, ECDH-ECDSA, ECDH-RSA, DHE-RSA, DHE-DSS.
 932          */
 933         int p = DEFAULT_SUITES_PRIORITY * 2;
 934 
 935         // shorten names to fit the following table cleanly.
 936         int max = ProtocolVersion.LIMIT_MAX_VALUE;
 937         int tls11 = ProtocolVersion.TLS11.v;
 938         int tls12 = ProtocolVersion.TLS12.v;
 939 
 940         //  ID           Key Exchange   Cipher     A  obs  suprt  PRF
 941         //  ======       ============   =========  =  ===  =====  ========
 942 
 943 
 944         // Placeholder for cipher suites in GCM mode.
 945         //
 946         // For better compatibility and interoperability, we decrease the
 947         // priority of cipher suites in GCM mode for a while as GCM
 948         // technologies mature in the industry.  Eventually we'll move
 949         // the GCM suites here.
 950 
 951         // AES_256(CBC)
 952         add("TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
 953             0xc024, --p, K_ECDHE_ECDSA, B_AES_256, T, max, tls12, P_SHA384);
 954         add("TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
 955             0xc028, --p, K_ECDHE_RSA,   B_AES_256, T, max, tls12, P_SHA384);
 956         add("TLS_RSA_WITH_AES_256_CBC_SHA256",
 957             0x003d, --p, K_RSA,         B_AES_256, T, max, tls12, P_SHA256);
 958         add("TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384",
 959             0xc026, --p, K_ECDH_ECDSA,  B_AES_256, T, max, tls12, P_SHA384);
 960         add("TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384",
 961             0xc02a, --p, K_ECDH_RSA,    B_AES_256, T, max, tls12, P_SHA384);
 962         add("TLS_DHE_RSA_WITH_AES_256_CBC_SHA256",
 963             0x006b, --p, K_DHE_RSA,     B_AES_256, T, max, tls12, P_SHA256);
 964         add("TLS_DHE_DSS_WITH_AES_256_CBC_SHA256",
 965             0x006a, --p, K_DHE_DSS,     B_AES_256, T, max, tls12, P_SHA256);
 966 
 967         add("TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
 968             0xC00A, --p, K_ECDHE_ECDSA, B_AES_256, T);
 969         add("TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
 970             0xC014, --p, K_ECDHE_RSA,   B_AES_256, T);
 971         add("TLS_RSA_WITH_AES_256_CBC_SHA",
 972             0x0035, --p, K_RSA,         B_AES_256, T);
 973         add("TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA",
 974             0xC005, --p, K_ECDH_ECDSA,  B_AES_256, T);
 975         add("TLS_ECDH_RSA_WITH_AES_256_CBC_SHA",
 976             0xC00F, --p, K_ECDH_RSA,    B_AES_256, T);
 977         add("TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
 978             0x0039, --p, K_DHE_RSA,     B_AES_256, T);
 979         add("TLS_DHE_DSS_WITH_AES_256_CBC_SHA",
 980             0x0038, --p, K_DHE_DSS,     B_AES_256, T);
 981 
 982         // AES_128(CBC)
 983         add("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
 984             0xc023, --p, K_ECDHE_ECDSA, B_AES_128, T, max, tls12, P_SHA256);
 985         add("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
 986             0xc027, --p, K_ECDHE_RSA,   B_AES_128, T, max, tls12, P_SHA256);
 987         add("TLS_RSA_WITH_AES_128_CBC_SHA256",
 988             0x003c, --p, K_RSA,         B_AES_128, T, max, tls12, P_SHA256);
 989         add("TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256",
 990             0xc025, --p, K_ECDH_ECDSA,  B_AES_128, T, max, tls12, P_SHA256);
 991         add("TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256",
 992             0xc029, --p, K_ECDH_RSA,    B_AES_128, T, max, tls12, P_SHA256);
 993         add("TLS_DHE_RSA_WITH_AES_128_CBC_SHA256",
 994             0x0067, --p, K_DHE_RSA,     B_AES_128, T, max, tls12, P_SHA256);
 995         add("TLS_DHE_DSS_WITH_AES_128_CBC_SHA256",
 996             0x0040, --p, K_DHE_DSS,     B_AES_128, T, max, tls12, P_SHA256);
 997 
 998         add("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
 999             0xC009, --p, K_ECDHE_ECDSA, B_AES_128, T);
1000         add("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
1001             0xC013, --p, K_ECDHE_RSA,   B_AES_128, T);
1002         add("TLS_RSA_WITH_AES_128_CBC_SHA",
1003             0x002f, --p, K_RSA,         B_AES_128, T);
1004         add("TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA",
1005             0xC004, --p, K_ECDH_ECDSA,  B_AES_128, T);
1006         add("TLS_ECDH_RSA_WITH_AES_128_CBC_SHA",
1007             0xC00E, --p, K_ECDH_RSA,    B_AES_128, T);
1008         add("TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
1009             0x0033, --p, K_DHE_RSA,     B_AES_128, T);
1010         add("TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
1011             0x0032, --p, K_DHE_DSS,     B_AES_128, T);
1012 
1013         // Cipher suites in GCM mode, see RFC 5288/5289.
1014         //
1015         // We may increase the priority of cipher suites in GCM mode when
1016         // GCM technologies become mature in the industry.
1017 
1018         // Suite B compliant cipher suites, see RFC 6460.
1019         //
1020         // Note that, at present this provider is not Suite B compliant. The
1021         // preference order of the GCM cipher suites does not follow the spec
1022         // of RFC 6460.
1023         add("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
1024             0xc02c, --p, K_ECDHE_ECDSA, B_AES_256_GCM, T, max, tls12, P_SHA384);
1025         add("TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
1026             0xc02b, --p, K_ECDHE_ECDSA, B_AES_128_GCM, T, max, tls12, P_SHA256);
1027 
1028         // AES_256(GCM)
1029         add("TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
1030             0xc030, --p, K_ECDHE_RSA,   B_AES_256_GCM, T, max, tls12, P_SHA384);
1031         add("TLS_RSA_WITH_AES_256_GCM_SHA384",
1032             0x009d, --p, K_RSA,         B_AES_256_GCM, T, max, tls12, P_SHA384);
1033         add("TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384",
1034             0xc02e, --p, K_ECDH_ECDSA,  B_AES_256_GCM, T, max, tls12, P_SHA384);
1035         add("TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384",
1036             0xc032, --p, K_ECDH_RSA,    B_AES_256_GCM, T, max, tls12, P_SHA384);
1037         add("TLS_DHE_RSA_WITH_AES_256_GCM_SHA384",
1038             0x009f, --p, K_DHE_RSA,     B_AES_256_GCM, T, max, tls12, P_SHA384);
1039         add("TLS_DHE_DSS_WITH_AES_256_GCM_SHA384",
1040             0x00a3, --p, K_DHE_DSS,     B_AES_256_GCM, T, max, tls12, P_SHA384);
1041 
1042         // AES_128(GCM)
1043         add("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
1044             0xc02f, --p, K_ECDHE_RSA,   B_AES_128_GCM, T, max, tls12, P_SHA256);
1045         add("TLS_RSA_WITH_AES_128_GCM_SHA256",
1046             0x009c, --p, K_RSA,         B_AES_128_GCM, T, max, tls12, P_SHA256);
1047         add("TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256",
1048             0xc02d, --p, K_ECDH_ECDSA,  B_AES_128_GCM, T, max, tls12, P_SHA256);
1049         add("TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256",
1050             0xc031, --p, K_ECDH_RSA,    B_AES_128_GCM, T, max, tls12, P_SHA256);
1051         add("TLS_DHE_RSA_WITH_AES_128_GCM_SHA256",
1052             0x009e, --p, K_DHE_RSA,     B_AES_128_GCM, T, max, tls12, P_SHA256);
1053         add("TLS_DHE_DSS_WITH_AES_128_GCM_SHA256",
1054             0x00a2, --p, K_DHE_DSS,     B_AES_128_GCM, T, max, tls12, P_SHA256);
1055         // End of cipher suites in GCM mode.
1056 
1057         // 3DES_EDE
1058         add("TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA",
1059             0xC008, --p, K_ECDHE_ECDSA, B_3DES,    T);
1060         add("TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
1061             0xC012, --p, K_ECDHE_RSA,   B_3DES,    T);
1062         add("SSL_RSA_WITH_3DES_EDE_CBC_SHA",
1063             0x000a, --p, K_RSA,         B_3DES,    T);
1064         add("TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA",
1065             0xC003, --p, K_ECDH_ECDSA,  B_3DES,    T);
1066         add("TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA",
1067             0xC00D, --p, K_ECDH_RSA,    B_3DES,    T);
1068         add("SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
1069             0x0016, --p, K_DHE_RSA,     B_3DES,    T);
1070         add("SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA",
1071             0x0013, --p, K_DHE_DSS,     B_3DES,    N);
1072 
1073         // Renegotiation protection request Signalling Cipher Suite Value (SCSV)
1074         add("TLS_EMPTY_RENEGOTIATION_INFO_SCSV",
1075             0x00ff, --p, K_SCSV,        B_NULL,    T);
1076 
1077         /*
1078          * Definition of the CipherSuites that are supported but not enabled
1079          * by default.
1080          * They are listed in preference order, preferred first, using the
1081          * following criteria:
1082          * 1. CipherSuites for KRB5 need additional KRB5 service
1083          *    configuration, and these suites are not common in practice,
1084          *    so we put KRB5 based cipher suites at the end of the supported
1085          *    list.
1086          * 2. If a cipher suite has been obsoleted, we put it at the end of
1087          *    the list.
1088          * 3. Prefer the stronger bulk cipher, in the order of AES_256,
1089          *    AES_128, 3DES-EDE, RC-4, DES, DES40, RC4_40, NULL.
1090          * 4. Prefer the stronger MAC algorithm, in the order of SHA384,
1091          *    SHA256, SHA, MD5.
1092          * 5. Prefer the better performance of key exchange and digital
1093          *    signature algorithm, in the order of ECDHE-ECDSA, ECDHE-RSA,
1094          *    RSA, ECDH-ECDSA, ECDH-RSA, DHE-RSA, DHE-DSS, anonymous.
1095          */
1096         p = DEFAULT_SUITES_PRIORITY;
1097 
1098         add("TLS_DH_anon_WITH_AES_256_GCM_SHA384",
1099             0x00a7, --p, K_DH_ANON,     B_AES_256_GCM, N, max, tls12, P_SHA384);
1100         add("TLS_DH_anon_WITH_AES_128_GCM_SHA256",
1101             0x00a6, --p, K_DH_ANON,     B_AES_128_GCM, N, max, tls12, P_SHA256);
1102 
1103         add("TLS_DH_anon_WITH_AES_256_CBC_SHA256",
1104             0x006d, --p, K_DH_ANON,     B_AES_256, N, max, tls12, P_SHA256);
1105         add("TLS_ECDH_anon_WITH_AES_256_CBC_SHA",
1106             0xC019, --p, K_ECDH_ANON,   B_AES_256, N);
1107         add("TLS_DH_anon_WITH_AES_256_CBC_SHA",
1108             0x003a, --p, K_DH_ANON,     B_AES_256, N);
1109 
1110         add("TLS_DH_anon_WITH_AES_128_CBC_SHA256",
1111             0x006c, --p, K_DH_ANON,     B_AES_128, N, max, tls12, P_SHA256);
1112         add("TLS_ECDH_anon_WITH_AES_128_CBC_SHA",
1113             0xC018, --p, K_ECDH_ANON,   B_AES_128, N);
1114         add("TLS_DH_anon_WITH_AES_128_CBC_SHA",
1115             0x0034, --p, K_DH_ANON,     B_AES_128, N);
1116 
1117         add("TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA",
1118             0xC017, --p, K_ECDH_ANON,   B_3DES,    N);
1119         add("SSL_DH_anon_WITH_3DES_EDE_CBC_SHA",
1120             0x001b, --p, K_DH_ANON,     B_3DES,    N);
1121 
1122         // RC-4
1123         add("TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
1124             0xC007, --p, K_ECDHE_ECDSA, B_RC4_128, N);
1125         add("TLS_ECDHE_RSA_WITH_RC4_128_SHA",
1126             0xC011, --p, K_ECDHE_RSA,   B_RC4_128, N);
1127         add("SSL_RSA_WITH_RC4_128_SHA",
1128             0x0005, --p, K_RSA,         B_RC4_128, N);
1129         add("TLS_ECDH_ECDSA_WITH_RC4_128_SHA",
1130             0xC002, --p, K_ECDH_ECDSA,  B_RC4_128, N);
1131         add("TLS_ECDH_RSA_WITH_RC4_128_SHA",
1132             0xC00C, --p, K_ECDH_RSA,    B_RC4_128, N);
1133         add("SSL_RSA_WITH_RC4_128_MD5",
1134             0x0004, --p, K_RSA,         B_RC4_128, N);
1135 
1136         add("TLS_ECDH_anon_WITH_RC4_128_SHA",
1137             0xC016, --p, K_ECDH_ANON,   B_RC4_128, N);
1138         add("SSL_DH_anon_WITH_RC4_128_MD5",
1139             0x0018, --p, K_DH_ANON,     B_RC4_128, N);
1140 
1141         // weak cipher suites obsoleted in TLS 1.2
1142         add("SSL_RSA_WITH_DES_CBC_SHA",
1143             0x0009, --p, K_RSA,         B_DES,     N, tls12);
1144         add("SSL_DHE_RSA_WITH_DES_CBC_SHA",
1145             0x0015, --p, K_DHE_RSA,     B_DES,     N, tls12);
1146         add("SSL_DHE_DSS_WITH_DES_CBC_SHA",
1147             0x0012, --p, K_DHE_DSS,     B_DES,     N, tls12);
1148         add("SSL_DH_anon_WITH_DES_CBC_SHA",
1149             0x001a, --p, K_DH_ANON,     B_DES,     N, tls12);
1150 
1151         // weak cipher suites obsoleted in TLS 1.1
1152         add("SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
1153             0x0008, --p, K_RSA_EXPORT,  B_DES_40,  N, tls11);
1154         add("SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
1155             0x0014, --p, K_DHE_RSA,     B_DES_40,  N, tls11);
1156         add("SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA",
1157             0x0011, --p, K_DHE_DSS,     B_DES_40,  N, tls11);
1158         add("SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA",
1159             0x0019, --p, K_DH_ANON,     B_DES_40,  N, tls11);
1160 
1161         add("SSL_RSA_EXPORT_WITH_RC4_40_MD5",
1162             0x0003, --p, K_RSA_EXPORT,  B_RC4_40,  N, tls11);
1163         add("SSL_DH_anon_EXPORT_WITH_RC4_40_MD5",
1164             0x0017, --p, K_DH_ANON,     B_RC4_40,  N, tls11);
1165 
1166         add("TLS_RSA_WITH_NULL_SHA256",
1167             0x003b, --p, K_RSA,         B_NULL,    N, max, tls12, P_SHA256);
1168         add("TLS_ECDHE_ECDSA_WITH_NULL_SHA",
1169             0xC006, --p, K_ECDHE_ECDSA, B_NULL,    N);
1170         add("TLS_ECDHE_RSA_WITH_NULL_SHA",
1171             0xC010, --p, K_ECDHE_RSA,   B_NULL,    N);
1172         add("SSL_RSA_WITH_NULL_SHA",
1173             0x0002, --p, K_RSA,         B_NULL,    N);
1174         add("TLS_ECDH_ECDSA_WITH_NULL_SHA",
1175             0xC001, --p, K_ECDH_ECDSA,  B_NULL,    N);
1176         add("TLS_ECDH_RSA_WITH_NULL_SHA",
1177             0xC00B, --p, K_ECDH_RSA,    B_NULL,    N);
1178         add("TLS_ECDH_anon_WITH_NULL_SHA",
1179             0xC015, --p, K_ECDH_ANON,   B_NULL,    N);
1180         add("SSL_RSA_WITH_NULL_MD5",
1181             0x0001, --p, K_RSA,         B_NULL,    N);
1182 
1183         // Supported Kerberos ciphersuites from RFC2712
1184         add("TLS_KRB5_WITH_3DES_EDE_CBC_SHA",
1185             0x001f, --p, K_KRB5,        B_3DES,    N);
1186         add("TLS_KRB5_WITH_3DES_EDE_CBC_MD5",
1187             0x0023, --p, K_KRB5,        B_3DES,    N);
1188         add("TLS_KRB5_WITH_RC4_128_SHA",
1189             0x0020, --p, K_KRB5,        B_RC4_128, N);
1190         add("TLS_KRB5_WITH_RC4_128_MD5",
1191             0x0024, --p, K_KRB5,        B_RC4_128, N);
1192         add("TLS_KRB5_WITH_DES_CBC_SHA",
1193             0x001e, --p, K_KRB5,        B_DES,     N, tls12);
1194         add("TLS_KRB5_WITH_DES_CBC_MD5",
1195             0x0022, --p, K_KRB5,        B_DES,     N, tls12);
1196         add("TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA",
1197             0x0026, --p, K_KRB5_EXPORT, B_DES_40,  N, tls11);
1198         add("TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5",
1199             0x0029, --p, K_KRB5_EXPORT, B_DES_40,  N, tls11);
1200         add("TLS_KRB5_EXPORT_WITH_RC4_40_SHA",
1201             0x0028, --p, K_KRB5_EXPORT, B_RC4_40,  N, tls11);
1202         add("TLS_KRB5_EXPORT_WITH_RC4_40_MD5",
1203             0x002b, --p, K_KRB5_EXPORT, B_RC4_40,  N, tls11);
1204 
1205         /*
1206          * Other values from the TLS Cipher Suite Registry, as of August 2010.
1207          *
1208          * http://www.iana.org/assignments/tls-parameters/tls-parameters.xml
1209          *
1210          * Range      Registration Procedures   Notes
1211          * 000-191    Standards Action          Refers to value of first byte
1212          * 192-254    Specification Required    Refers to value of first byte
1213          * 255        Reserved for Private Use  Refers to value of first byte
1214          */
1215 
1216         // Register the names of a few additional CipherSuites.
1217         // Makes them show up as names instead of numbers in
1218         // the debug output.
1219 
1220         // remaining unsupported ciphersuites defined in RFC2246.
1221         add("SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5",          0x0006);
1222         add("SSL_RSA_WITH_IDEA_CBC_SHA",                   0x0007);
1223         add("SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA",        0x000b);
1224         add("SSL_DH_DSS_WITH_DES_CBC_SHA",                 0x000c);
1225         add("SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA",            0x000d);
1226         add("SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA",        0x000e);
1227         add("SSL_DH_RSA_WITH_DES_CBC_SHA",                 0x000f);
1228         add("SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA",            0x0010);
1229 
1230         // SSL 3.0 Fortezza ciphersuites
1231         add("SSL_FORTEZZA_DMS_WITH_NULL_SHA",              0x001c);
1232         add("SSL_FORTEZZA_DMS_WITH_FORTEZZA_CBC_SHA",      0x001d);
1233 
1234         // 1024/56 bit exportable ciphersuites from expired internet draft
1235         add("SSL_RSA_EXPORT1024_WITH_DES_CBC_SHA",         0x0062);
1236         add("SSL_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA",     0x0063);
1237         add("SSL_RSA_EXPORT1024_WITH_RC4_56_SHA",          0x0064);
1238         add("SSL_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA",      0x0065);
1239         add("SSL_DHE_DSS_WITH_RC4_128_SHA",                0x0066);
1240 
1241         // Netscape old and new SSL 3.0 FIPS ciphersuites
1242         // see http://www.mozilla.org/projects/security/pki/nss/ssl/fips-ssl-ciphersuites.html
1243         add("NETSCAPE_RSA_FIPS_WITH_3DES_EDE_CBC_SHA",     0xffe0);
1244         add("NETSCAPE_RSA_FIPS_WITH_DES_CBC_SHA",          0xffe1);
1245         add("SSL_RSA_FIPS_WITH_DES_CBC_SHA",               0xfefe);
1246         add("SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA",          0xfeff);
1247 
1248         // Unsupported Kerberos cipher suites from RFC 2712
1249         add("TLS_KRB5_WITH_IDEA_CBC_SHA",                  0x0021);
1250         add("TLS_KRB5_WITH_IDEA_CBC_MD5",                  0x0025);
1251         add("TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA",         0x0027);
1252         add("TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5",         0x002a);
1253 
1254         // Unsupported cipher suites from RFC 4162
1255         add("TLS_RSA_WITH_SEED_CBC_SHA",                   0x0096);
1256         add("TLS_DH_DSS_WITH_SEED_CBC_SHA",                0x0097);
1257         add("TLS_DH_RSA_WITH_SEED_CBC_SHA",                0x0098);
1258         add("TLS_DHE_DSS_WITH_SEED_CBC_SHA",               0x0099);
1259         add("TLS_DHE_RSA_WITH_SEED_CBC_SHA",               0x009a);
1260         add("TLS_DH_anon_WITH_SEED_CBC_SHA",               0x009b);
1261 
1262         // Unsupported cipher suites from RFC 4279
1263         add("TLS_PSK_WITH_RC4_128_SHA",                    0x008a);
1264         add("TLS_PSK_WITH_3DES_EDE_CBC_SHA",               0x008b);
1265         add("TLS_PSK_WITH_AES_128_CBC_SHA",                0x008c);
1266         add("TLS_PSK_WITH_AES_256_CBC_SHA",                0x008d);
1267         add("TLS_DHE_PSK_WITH_RC4_128_SHA",                0x008e);
1268         add("TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA",           0x008f);
1269         add("TLS_DHE_PSK_WITH_AES_128_CBC_SHA",            0x0090);
1270         add("TLS_DHE_PSK_WITH_AES_256_CBC_SHA",            0x0091);
1271         add("TLS_RSA_PSK_WITH_RC4_128_SHA",                0x0092);
1272         add("TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA",           0x0093);
1273         add("TLS_RSA_PSK_WITH_AES_128_CBC_SHA",            0x0094);
1274         add("TLS_RSA_PSK_WITH_AES_256_CBC_SHA",            0x0095);
1275 
1276         // Unsupported cipher suites from RFC 4785
1277         add("TLS_PSK_WITH_NULL_SHA",                       0x002c);
1278         add("TLS_DHE_PSK_WITH_NULL_SHA",                   0x002d);
1279         add("TLS_RSA_PSK_WITH_NULL_SHA",                   0x002e);
1280 
1281         // Unsupported cipher suites from RFC 5246
1282         add("TLS_DH_DSS_WITH_AES_128_CBC_SHA",             0x0030);
1283         add("TLS_DH_RSA_WITH_AES_128_CBC_SHA",             0x0031);
1284         add("TLS_DH_DSS_WITH_AES_256_CBC_SHA",             0x0036);
1285         add("TLS_DH_RSA_WITH_AES_256_CBC_SHA",             0x0037);
1286         add("TLS_DH_DSS_WITH_AES_128_CBC_SHA256",          0x003e);
1287         add("TLS_DH_RSA_WITH_AES_128_CBC_SHA256",          0x003f);
1288         add("TLS_DH_DSS_WITH_AES_256_CBC_SHA256",          0x0068);
1289         add("TLS_DH_RSA_WITH_AES_256_CBC_SHA256",          0x0069);
1290 
1291         // Unsupported cipher suites from RFC 5288
1292         add("TLS_DH_RSA_WITH_AES_128_GCM_SHA256",          0x00a0);
1293         add("TLS_DH_RSA_WITH_AES_256_GCM_SHA384",          0x00a1);
1294         add("TLS_DH_DSS_WITH_AES_128_GCM_SHA256",          0x00a4);
1295         add("TLS_DH_DSS_WITH_AES_256_GCM_SHA384",          0x00a5);
1296 
1297         // Unsupported cipher suites from RFC 5487
1298         add("TLS_PSK_WITH_AES_128_GCM_SHA256",             0x00a8);
1299         add("TLS_PSK_WITH_AES_256_GCM_SHA384",             0x00a9);
1300         add("TLS_DHE_PSK_WITH_AES_128_GCM_SHA256",         0x00aa);
1301         add("TLS_DHE_PSK_WITH_AES_256_GCM_SHA384",         0x00ab);
1302         add("TLS_RSA_PSK_WITH_AES_128_GCM_SHA256",         0x00ac);
1303         add("TLS_RSA_PSK_WITH_AES_256_GCM_SHA384",         0x00ad);
1304         add("TLS_PSK_WITH_AES_128_CBC_SHA256",             0x00ae);
1305         add("TLS_PSK_WITH_AES_256_CBC_SHA384",             0x00af);
1306         add("TLS_PSK_WITH_NULL_SHA256",                    0x00b0);
1307         add("TLS_PSK_WITH_NULL_SHA384",                    0x00b1);
1308         add("TLS_DHE_PSK_WITH_AES_128_CBC_SHA256",         0x00b2);
1309         add("TLS_DHE_PSK_WITH_AES_256_CBC_SHA384",         0x00b3);
1310         add("TLS_DHE_PSK_WITH_NULL_SHA256",                0x00b4);
1311         add("TLS_DHE_PSK_WITH_NULL_SHA384",                0x00b5);
1312         add("TLS_RSA_PSK_WITH_AES_128_CBC_SHA256",         0x00b6);
1313         add("TLS_RSA_PSK_WITH_AES_256_CBC_SHA384",         0x00b7);
1314         add("TLS_RSA_PSK_WITH_NULL_SHA256",                0x00b8);
1315         add("TLS_RSA_PSK_WITH_NULL_SHA384",                0x00b9);
1316 
1317         // Unsupported cipher suites from RFC 5932
1318         add("TLS_RSA_WITH_CAMELLIA_128_CBC_SHA",           0x0041);
1319         add("TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA",        0x0042);
1320         add("TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA",        0x0043);
1321         add("TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA",       0x0044);
1322         add("TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA",       0x0045);
1323         add("TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA",       0x0046);
1324         add("TLS_RSA_WITH_CAMELLIA_256_CBC_SHA",           0x0084);
1325         add("TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA",        0x0085);
1326         add("TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA",        0x0086);
1327         add("TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA",       0x0087);
1328         add("TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA",       0x0088);
1329         add("TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA",       0x0089);
1330         add("TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256",        0x00ba);
1331         add("TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256",     0x00bb);
1332         add("TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256",     0x00bc);
1333         add("TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256",    0x00bd);
1334         add("TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256",    0x00be);
1335         add("TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256",    0x00bf);
1336         add("TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256",        0x00c0);
1337         add("TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256",     0x00c1);
1338         add("TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256",     0x00c2);
1339         add("TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256",    0x00c3);
1340         add("TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256",    0x00c4);
1341         add("TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256",    0x00c5);
1342 
1343         // Unsupported cipher suites from RFC 5054
1344         add("TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA",           0xc01a);
1345         add("TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA",       0xc01b);
1346         add("TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA",       0xc01c);
1347         add("TLS_SRP_SHA_WITH_AES_128_CBC_SHA",            0xc01d);
1348         add("TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA",        0xc01e);
1349         add("TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA",        0xc01f);
1350         add("TLS_SRP_SHA_WITH_AES_256_CBC_SHA",            0xc020);
1351         add("TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA",        0xc021);
1352         add("TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA",        0xc022);
1353 
1354         // Unsupported cipher suites from RFC 5489
1355         add("TLS_ECDHE_PSK_WITH_RC4_128_SHA",              0xc033);
1356         add("TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA",         0xc034);
1357         add("TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA",          0xc035);
1358         add("TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA",          0xc036);
1359         add("TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256",       0xc037);
1360         add("TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384",       0xc038);
1361         add("TLS_ECDHE_PSK_WITH_NULL_SHA",                 0xc039);
1362         add("TLS_ECDHE_PSK_WITH_NULL_SHA256",              0xc03a);
1363         add("TLS_ECDHE_PSK_WITH_NULL_SHA384",              0xc03b);
1364     }
1365 
1366     // ciphersuite SSL_NULL_WITH_NULL_NULL
1367     final static CipherSuite C_NULL = CipherSuite.valueOf(0, 0);
1368 
1369     // ciphersuite TLS_EMPTY_RENEGOTIATION_INFO_SCSV
1370     final static CipherSuite C_SCSV = CipherSuite.valueOf(0x00, 0xff);
1371 }