CipherSuite.java 65.1 KB
Newer Older
D
duke 已提交
1
/*
A
asmotrak 已提交
2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.  Oracle designates this
D
duke 已提交
8
 * particular file as subject to the "Classpath" exception as provided
9
 * by Oracle in the LICENSE file that accompanied this code.
D
duke 已提交
10 11 12 13 14 15 16 17 18 19 20
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
21 22 23
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
24 25 26 27 28 29 30 31 32
 */


package sun.security.ssl;

import java.util.*;

import java.security.NoSuchAlgorithmException;
import java.security.InvalidKeyException;
X
xuelei 已提交
33
import java.security.SecureRandom;
34
import java.security.KeyManagementException;
D
duke 已提交
35

36
import javax.crypto.Cipher;
D
duke 已提交
37 38 39 40 41
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import static sun.security.ssl.CipherSuite.KeyExchange.*;
X
xuelei 已提交
42
import static sun.security.ssl.CipherSuite.PRF.*;
43
import static sun.security.ssl.CipherSuite.CipherType.*;
D
duke 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
import static sun.security.ssl.JsseJce.*;

/**
 * An SSL/TLS CipherSuite. Constants for the standard key exchange, cipher,
 * and mac algorithms are also defined in this class.
 *
 * The CipherSuite class and the inner classes defined in this file roughly
 * follow the type safe enum pattern described in Effective Java. This means:
 *
 *  . instances are immutable, classes are final
 *
 *  . there is a unique instance of every value, i.e. there are never two
 *    instances representing the same CipherSuite, etc. This means equality
 *    tests can be performed using == instead of equals() (although that works
 *    as well). [A minor exception are *unsupported* CipherSuites read from a
 *    handshake message, but this is usually irrelevant]
 *
 *  . instances are obtained using the static valueOf() factory methods.
 *
 *  . properties are defined as final variables and made available as
 *    package private variables without method accessors
 *
 *  . if the member variable allowed is false, the given algorithm is either
 *    unavailable or disabled at compile time
 *
 */
70
final class CipherSuite implements Comparable<CipherSuite> {
D
duke 已提交
71 72 73 74 75 76 77 78 79 80

    // minimum priority for supported CipherSuites
    final static int SUPPORTED_SUITES_PRIORITY = 1;

    // minimum priority for default enabled CipherSuites
    final static int DEFAULT_SUITES_PRIORITY = 300;

    // Flag indicating if CipherSuite availability can change dynamically.
    // This is the case when we rely on a JCE cipher implementation that
    // may not be available in the installed JCE providers.
81
    // It is true because we might not have an ECC implementation.
D
duke 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    final static boolean DYNAMIC_AVAILABILITY = true;

    private final static boolean ALLOW_ECC = Debug.getBooleanProperty
        ("com.sun.net.ssl.enableECC", true);

    // Map Integer(id) -> CipherSuite
    // contains all known CipherSuites
    private final static Map<Integer,CipherSuite> idMap;

    // Map String(name) -> CipherSuite
    // contains only supported CipherSuites (i.e. allowed == true)
    private final static Map<String,CipherSuite> nameMap;

    // Protocol defined CipherSuite name, e.g. SSL_RSA_WITH_RC4_128_MD5
    // we use TLS_* only for new CipherSuites, still SSL_* for old ones
    final String name;

    // id in 16 bit MSB format, i.e. 0x0004 for SSL_RSA_WITH_RC4_128_MD5
    final int id;

    // priority for the internal default preference order. the higher the
    // better. Each supported CipherSuite *must* have a unique priority.
    // Ciphersuites with priority >= DEFAULT_SUITES_PRIORITY are enabled
    // by default
    final int priority;

X
xuelei 已提交
108 109
    // key exchange, bulk cipher, mac and prf algorithms. See those
    // classes below.
D
duke 已提交
110 111 112
    final KeyExchange keyExchange;
    final BulkCipher cipher;
    final MacAlg macAlg;
X
xuelei 已提交
113
    final PRF prfAlg;
D
duke 已提交
114 115

    // whether a CipherSuite qualifies as exportable under 512/40 bit rules.
X
xuelei 已提交
116
    // TLS 1.1+ (RFC 4346) must not negotiate to these suites.
D
duke 已提交
117 118 119 120 121
    final boolean exportable;

    // true iff implemented and enabled at compile time
    final boolean allowed;

X
xuelei 已提交
122 123 124
    // obsoleted since protocol version
    final int obsoleted;

X
xuelei 已提交
125 126 127 128 129 130
    // supported since protocol version
    final int supported;

    /**
     * Constructor for implemented CipherSuites.
     */
D
duke 已提交
131
    private CipherSuite(String name, int id, int priority,
X
xuelei 已提交
132
            KeyExchange keyExchange, BulkCipher cipher,
X
xuelei 已提交
133
            boolean allowed, int obsoleted, int supported, PRF prfAlg) {
D
duke 已提交
134 135 136 137 138 139
        this.name = name;
        this.id = id;
        this.priority = priority;
        this.keyExchange = keyExchange;
        this.cipher = cipher;
        this.exportable = cipher.exportable;
140 141 142
        if (cipher.cipherType == CipherType.AEAD_CIPHER) {
            macAlg = M_NULL;
        } else if (name.endsWith("_MD5")) {
D
duke 已提交
143 144 145
            macAlg = M_MD5;
        } else if (name.endsWith("_SHA")) {
            macAlg = M_SHA;
X
xuelei 已提交
146 147 148 149
        } else if (name.endsWith("_SHA256")) {
            macAlg = M_SHA256;
        } else if (name.endsWith("_SHA384")) {
            macAlg = M_SHA384;
D
duke 已提交
150 151
        } else if (name.endsWith("_NULL")) {
            macAlg = M_NULL;
152 153
        } else if (name.endsWith("_SCSV")) {
            macAlg = M_NULL;
D
duke 已提交
154 155 156 157 158 159 160 161
        } else {
            throw new IllegalArgumentException
                    ("Unknown MAC algorithm for ciphersuite " + name);
        }

        allowed &= keyExchange.allowed;
        allowed &= cipher.allowed;
        this.allowed = allowed;
X
xuelei 已提交
162
        this.obsoleted = obsoleted;
X
xuelei 已提交
163 164
        this.supported = supported;
        this.prfAlg = prfAlg;
D
duke 已提交
165 166
    }

X
xuelei 已提交
167 168 169
    /**
     * Constructor for unimplemented CipherSuites.
     */
D
duke 已提交
170 171 172 173 174 175 176 177 178 179
    private CipherSuite(String name, int id) {
        this.name = name;
        this.id = id;
        this.allowed = false;

        this.priority = 0;
        this.keyExchange = null;
        this.cipher = null;
        this.macAlg = null;
        this.exportable = false;
X
xuelei 已提交
180
        this.obsoleted = ProtocolVersion.LIMIT_MAX_VALUE;
X
xuelei 已提交
181 182
        this.supported = ProtocolVersion.LIMIT_MIN_VALUE;
        this.prfAlg = P_NONE;
D
duke 已提交
183 184 185 186 187 188 189 190 191 192 193 194 195 196
    }

    /**
     * Return whether this CipherSuite is available for use. A
     * CipherSuite may be unavailable even if it is supported
     * (i.e. allowed == true) if the required JCE cipher is not installed.
     * In some configuration, this situation may change over time, call
     * CipherSuiteList.clearAvailableCache() before this method to obtain
     * the most current status.
     */
    boolean isAvailable() {
        return allowed && keyExchange.isAvailable() && cipher.isAvailable();
    }

197 198 199 200
    boolean isNegotiable() {
        return this != C_SCSV && isAvailable();
    }

D
duke 已提交
201 202 203 204 205 206 207 208
    /**
     * Compares CipherSuites based on their priority. Has the effect of
     * sorting CipherSuites when put in a sorted collection, which is
     * used by CipherSuiteList. Follows standard Comparable contract.
     *
     * Note that for unsupported CipherSuites parsed from a handshake
     * message we violate the equals() contract.
     */
209
    @Override
210 211
    public int compareTo(CipherSuite o) {
        return o.priority - priority;
D
duke 已提交
212 213 214 215 216
    }

    /**
     * Returns this.name.
     */
217
    @Override
D
duke 已提交
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
    public String toString() {
        return name;
    }

    /**
     * Return a CipherSuite for the given name. The returned CipherSuite
     * is supported by this implementation but may not actually be
     * currently useable. See isAvailable().
     *
     * @exception IllegalArgumentException if the CipherSuite is unknown or
     * unsupported.
     */
    static CipherSuite valueOf(String s) {
        if (s == null) {
            throw new IllegalArgumentException("Name must not be null");
        }
X
xuelei 已提交
234

235
        CipherSuite c = nameMap.get(s);
D
duke 已提交
236 237 238
        if ((c == null) || (c.allowed == false)) {
            throw new IllegalArgumentException("Unsupported ciphersuite " + s);
        }
X
xuelei 已提交
239

D
duke 已提交
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
        return c;
    }

    /**
     * Return a CipherSuite with the given ID. A temporary object is
     * constructed if the ID is unknown. Use isAvailable() to verify that
     * the CipherSuite can actually be used.
     */
    static CipherSuite valueOf(int id1, int id2) {
        id1 &= 0xff;
        id2 &= 0xff;
        int id = (id1 << 8) | id2;
        CipherSuite c = idMap.get(id);
        if (c == null) {
            String h1 = Integer.toString(id1, 16);
            String h2 = Integer.toString(id2, 16);
            c = new CipherSuite("Unknown 0x" + h1 + ":0x" + h2, id);
        }
        return c;
    }

    // for use by CipherSuiteList only
    static Collection<CipherSuite> allowedCipherSuites() {
        return nameMap.values();
    }

X
xuelei 已提交
266 267 268 269 270
    /*
     * Use this method when all of the values need to be specified.
     * This is primarily used when defining a new ciphersuite for
     * TLS 1.2+ that doesn't use the "default" PRF.
     */
D
duke 已提交
271
    private static void add(String name, int id, int priority,
X
xuelei 已提交
272
            KeyExchange keyExchange, BulkCipher cipher,
X
xuelei 已提交
273
            boolean allowed, int obsoleted, int supported, PRF prf) {
X
xuelei 已提交
274

D
duke 已提交
275
        CipherSuite c = new CipherSuite(name, id, priority, keyExchange,
X
xuelei 已提交
276
            cipher, allowed, obsoleted, supported, prf);
D
duke 已提交
277 278 279 280 281 282 283 284 285 286 287 288
        if (idMap.put(id, c) != null) {
            throw new RuntimeException("Duplicate ciphersuite definition: "
                                        + id + ", " + name);
        }
        if (c.allowed) {
            if (nameMap.put(name, c) != null) {
                throw new RuntimeException("Duplicate ciphersuite definition: "
                                            + id + ", " + name);
            }
        }
    }

X
xuelei 已提交
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
    /*
     * Use this method when there is no lower protocol limit where this
     * suite can be used, and the PRF is P_SHA256.  That is, the
     * existing ciphersuites.  From RFC 5246:
     *
     *     All cipher suites in this document use P_SHA256.
     */
    private static void add(String name, int id, int priority,
            KeyExchange keyExchange, BulkCipher cipher,
            boolean allowed, int obsoleted) {
        // If this is an obsoleted suite, then don't let the TLS 1.2
        // protocol have a valid PRF value.
        PRF prf = P_SHA256;
        if (obsoleted < ProtocolVersion.TLS12.v) {
            prf = P_NONE;
        }

        add(name, id, priority, keyExchange, cipher, allowed, obsoleted,
            ProtocolVersion.LIMIT_MIN_VALUE, prf);
    }

    /*
     * Use this method when there is no upper protocol limit.  That is,
     * suites which have not been obsoleted.
     */
X
xuelei 已提交
314 315 316 317 318 319
    private static void add(String name, int id, int priority,
            KeyExchange keyExchange, BulkCipher cipher, boolean allowed) {
        add(name, id, priority, keyExchange,
            cipher, allowed, ProtocolVersion.LIMIT_MAX_VALUE);
    }

X
xuelei 已提交
320 321 322 323
    /*
     * Use this method to define an unimplemented suite.  This provides
     * a number<->name mapping that can be used for debugging.
     */
D
duke 已提交
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
    private static void add(String name, int id) {
        CipherSuite c = new CipherSuite(name, id);
        if (idMap.put(id, c) != null) {
            throw new RuntimeException("Duplicate ciphersuite definition: "
                                        + id + ", " + name);
        }
    }

    /**
     * An SSL/TLS key exchange algorithm.
     */
    static enum KeyExchange {

        // key exchange algorithms
        K_NULL       ("NULL",       false),
        K_RSA        ("RSA",        true),
        K_RSA_EXPORT ("RSA_EXPORT", true),
        K_DH_RSA     ("DH_RSA",     false),
        K_DH_DSS     ("DH_DSS",     false),
        K_DHE_DSS    ("DHE_DSS",    true),
        K_DHE_RSA    ("DHE_RSA",    true),
        K_DH_ANON    ("DH_anon",    true),

        K_ECDH_ECDSA ("ECDH_ECDSA",  ALLOW_ECC),
        K_ECDH_RSA   ("ECDH_RSA",    ALLOW_ECC),
        K_ECDHE_ECDSA("ECDHE_ECDSA", ALLOW_ECC),
        K_ECDHE_RSA  ("ECDHE_RSA",   ALLOW_ECC),
        K_ECDH_ANON  ("ECDH_anon",   ALLOW_ECC),

        // Kerberos cipher suites
        K_KRB5       ("KRB5", true),
355 356 357 358
        K_KRB5_EXPORT("KRB5_EXPORT", true),

        // renegotiation protection request signaling cipher suite
        K_SCSV       ("SCSV",        true);
D
duke 已提交
359 360 361 362 363 364 365 366 367

        // name of the key exchange algorithm, e.g. DHE_DSS
        final String name;
        final boolean allowed;
        private final boolean alwaysAvailable;

        KeyExchange(String name, boolean allowed) {
            this.name = name;
            this.allowed = allowed;
368 369
            this.alwaysAvailable = allowed &&
                (!name.startsWith("EC")) && (!name.startsWith("KRB"));
D
duke 已提交
370 371 372 373 374 375
        }

        boolean isAvailable() {
            if (alwaysAvailable) {
                return true;
            }
376 377 378 379 380 381 382 383

            if (name.startsWith("EC")) {
                return (allowed && JsseJce.isEcAvailable());
            } else if (name.startsWith("KRB")) {
                return (allowed && JsseJce.isKerberosAvailable());
            } else {
                return allowed;
            }
D
duke 已提交
384 385
        }

386
        @Override
D
duke 已提交
387 388 389 390 391
        public String toString() {
            return name;
        }
    }

392 393 394 395 396 397
    static enum CipherType {
        STREAM_CIPHER,         // null or stream cipher
        BLOCK_CIPHER,          // block cipher in CBC mode
        AEAD_CIPHER            // AEAD cipher
    }

D
duke 已提交
398 399 400 401 402 403 404 405 406 407 408
    /**
     * An SSL/TLS bulk cipher algorithm. One instance per combination of
     * cipher and key length.
     *
     * Also contains a factory method to obtain in initialized CipherBox
     * for this algorithm.
     */
    final static class BulkCipher {

        // Map BulkCipher -> Boolean(available)
        private final static Map<BulkCipher,Boolean> availableCache =
S
smarks 已提交
409
                                            new HashMap<>(8);
D
duke 已提交
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429

        // descriptive name including key size, e.g. AES/128
        final String description;

        // JCE cipher transformation string, e.g. AES/CBC/NoPadding
        final String transformation;

        // algorithm name, e.g. AES
        final String algorithm;

        // supported and compile time enabled. Also see isAvailable()
        final boolean allowed;

        // number of bytes of entropy in the key
        final int keySize;

        // length of the actual cipher key in bytes.
        // for non-exportable ciphers, this is the same as keySize
        final int expandedKeySize;

430
        // size of the IV
D
duke 已提交
431 432
        final int ivSize;

433 434 435 436 437
        // size of fixed IV
        //
        // record_iv_length = ivSize - fixedIvSize
        final int fixedIvSize;

D
duke 已提交
438 439 440
        // exportable under 512/40 bit rules
        final boolean exportable;

X
xuelei 已提交
441
        // Is the cipher algorithm of Cipher Block Chaining (CBC) mode?
442 443 444 445 446 447 448 449
        final CipherType cipherType;

        // size of the authentication tag, only applicable to cipher suites in
        // Galois Counter Mode (GCM)
        //
        // As far as we know, all supported GCM cipher suites use 128-bits
        // authentication tags.
        final int tagSize = 16;
X
xuelei 已提交
450

451 452 453 454 455 456 457 458 459 460 461
        // The secure random used to detect the cipher availability.
        private final static SecureRandom secureRandom;

        static {
            try {
                secureRandom = JsseJce.getSecureRandom();
            } catch (KeyManagementException kme) {
                throw new RuntimeException(kme);
            }
        }

462 463 464 465
        BulkCipher(String transformation, CipherType cipherType, int keySize,
                int expandedKeySize, int ivSize,
                int fixedIvSize, boolean allowed) {

D
duke 已提交
466
            this.transformation = transformation;
X
xuelei 已提交
467 468
            String[] splits = transformation.split("/");
            this.algorithm = splits[0];
469
            this.cipherType = cipherType;
D
duke 已提交
470 471 472
            this.description = this.algorithm + "/" + (keySize << 3);
            this.keySize = keySize;
            this.ivSize = ivSize;
473
            this.fixedIvSize = fixedIvSize;
D
duke 已提交
474 475 476 477 478 479
            this.allowed = allowed;

            this.expandedKeySize = expandedKeySize;
            this.exportable = true;
        }

480 481
        BulkCipher(String transformation, CipherType cipherType, int keySize,
                int ivSize, int fixedIvSize, boolean allowed) {
D
duke 已提交
482
            this.transformation = transformation;
X
xuelei 已提交
483 484
            String[] splits = transformation.split("/");
            this.algorithm = splits[0];
485
            this.cipherType = cipherType;
D
duke 已提交
486 487 488
            this.description = this.algorithm + "/" + (keySize << 3);
            this.keySize = keySize;
            this.ivSize = ivSize;
489
            this.fixedIvSize = fixedIvSize;
D
duke 已提交
490 491 492 493 494 495 496 497 498 499 500 501
            this.allowed = allowed;

            this.expandedKeySize = keySize;
            this.exportable = false;
        }

        /**
         * Return an initialized CipherBox for this BulkCipher.
         * IV must be null for stream ciphers.
         *
         * @exception NoSuchAlgorithmException if anything goes wrong
         */
X
xuelei 已提交
502 503
        CipherBox newCipher(ProtocolVersion version, SecretKey key,
                IvParameterSpec iv, SecureRandom random,
D
duke 已提交
504
                boolean encrypt) throws NoSuchAlgorithmException {
X
xuelei 已提交
505 506
            return CipherBox.newCipherBox(version, this,
                                            key, iv, random, encrypt);
D
duke 已提交
507 508 509 510 511 512
        }

        /**
         * Test if this bulk cipher is available. For use by CipherSuite.
         *
         * Currently all supported ciphers except AES are always available
513 514 515 516 517 518
         * via the JSSE internal implementations. We also assume AES/128 of
         * CBC mode is always available since it is shipped with the SunJCE
         * provider.  However, AES/256 is unavailable when the default JCE
         * policy jurisdiction files are installed because of key length
         * restrictions, and AEAD is unavailable when the underlying providers
         * do not support AEAD/GCM mode.
D
duke 已提交
519 520 521 522 523
         */
        boolean isAvailable() {
            if (allowed == false) {
                return false;
            }
524 525 526

            if ((this == B_AES_256) ||
                    (this.cipherType == CipherType.AEAD_CIPHER)) {
D
duke 已提交
527 528
                return isAvailable(this);
            }
X
xuelei 已提交
529

D
duke 已提交
530 531 532 533 534 535 536 537 538 539 540 541
            // always available
            return true;
        }

        // for use by CipherSuiteList.clearAvailableCache();
        static synchronized void clearAvailableCache() {
            if (DYNAMIC_AVAILABILITY) {
                availableCache.clear();
            }
        }

        private static synchronized boolean isAvailable(BulkCipher cipher) {
542
            Boolean b = availableCache.get(cipher);
D
duke 已提交
543
            if (b == null) {
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
                int keySizeInBits = cipher.keySize * 8;
                if (keySizeInBits > 128) {    // need the JCE unlimited
                                               // strength jurisdiction policy
                    try {
                        if (Cipher.getMaxAllowedKeyLength(
                                cipher.transformation) < keySizeInBits) {
                            b = Boolean.FALSE;
                        }
                    } catch (Exception e) {
                        b = Boolean.FALSE;
                    }
                }

                if (b == null) {
                    b = Boolean.FALSE;          // may be reset to TRUE if
                                                // the cipher is available
                    CipherBox temporary = null;
                    try {
                        SecretKey key = new SecretKeySpec(
                                            new byte[cipher.expandedKeySize],
                                            cipher.algorithm);
                        IvParameterSpec iv;
                        if (cipher.cipherType == CipherType.AEAD_CIPHER) {
                            iv = new IvParameterSpec(
                                            new byte[cipher.fixedIvSize]);
                        } else {
                            iv = new IvParameterSpec(new byte[cipher.ivSize]);
                        }
                        temporary = cipher.newCipher(
                                            ProtocolVersion.DEFAULT,
574
                                            key, iv, secureRandom, true);
575 576 577 578 579 580 581 582
                        b = temporary.isAvailable();
                    } catch (NoSuchAlgorithmException e) {
                        // not available
                    } finally {
                        if (temporary != null) {
                            temporary.dispose();
                        }
                    }
D
duke 已提交
583
                }
584

D
duke 已提交
585 586
                availableCache.put(cipher, b);
            }
587

D
duke 已提交
588 589 590
            return b.booleanValue();
        }

591
        @Override
D
duke 已提交
592 593 594 595 596 597 598 599
        public String toString() {
            return description;
        }
    }

    /**
     * An SSL/TLS key MAC algorithm.
     *
X
xuelei 已提交
600
     * Also contains a factory method to obtain an initialized MAC
D
duke 已提交
601 602 603 604 605 606 607 608 609 610
     * for this algorithm.
     */
    final static class MacAlg {

        // descriptive name, e.g. MD5
        final String name;

        // size of the MAC value (and MAC key) in bytes
        final int size;

611 612 613 614 615 616 617 618
        // block size of the underlying hash algorithm
        final int hashBlockSize;

        // minimal padding size of the underlying hash algorithm
        final int minimalPaddingSize;

        MacAlg(String name, int size,
                int hashBlockSize, int minimalPaddingSize) {
D
duke 已提交
619 620
            this.name = name;
            this.size = size;
621 622
            this.hashBlockSize = hashBlockSize;
            this.minimalPaddingSize = minimalPaddingSize;
D
duke 已提交
623 624 625 626 627 628 629 630 631 632 633 634 635
        }

        /**
         * Return an initialized MAC for this MacAlg. ProtocolVersion
         * must either be SSL30 (SSLv3 custom MAC) or TLS10 (std. HMAC).
         *
         * @exception NoSuchAlgorithmException if anything goes wrong
         */
        MAC newMac(ProtocolVersion protocolVersion, SecretKey secret)
                throws NoSuchAlgorithmException, InvalidKeyException {
            return new MAC(this, protocolVersion, secret);
        }

636
        @Override
D
duke 已提交
637 638 639 640 641 642
        public String toString() {
            return name;
        }
    }

    // export strength ciphers
643
    final static BulkCipher B_NULL    =
644
        new BulkCipher("NULL",          STREAM_CIPHER,    0,  0,  0, 0, true);
645
    final static BulkCipher B_RC4_40  =
646
        new BulkCipher(CIPHER_RC4,      STREAM_CIPHER,    5, 16,  0, 0, true);
647
    final static BulkCipher B_RC2_40  =
648
        new BulkCipher("RC2",           BLOCK_CIPHER,     5, 16,  8, 0, false);
649
    final static BulkCipher B_DES_40  =
650
        new BulkCipher(CIPHER_DES,      BLOCK_CIPHER,     5,  8,  8, 0, true);
D
duke 已提交
651 652

    // domestic strength ciphers
653
    final static BulkCipher B_RC4_128 =
654
        new BulkCipher(CIPHER_RC4,      STREAM_CIPHER,   16,  0,  0, true);
655
    final static BulkCipher B_DES     =
656
        new BulkCipher(CIPHER_DES,      BLOCK_CIPHER,     8,  8,  0, true);
657
    final static BulkCipher B_3DES    =
658
        new BulkCipher(CIPHER_3DES,     BLOCK_CIPHER,    24,  8,  0, true);
659
    final static BulkCipher B_IDEA    =
660
        new BulkCipher("IDEA",          BLOCK_CIPHER,    16,  8,  0, false);
661
    final static BulkCipher B_AES_128 =
662
        new BulkCipher(CIPHER_AES,      BLOCK_CIPHER,    16, 16,  0, true);
663
    final static BulkCipher B_AES_256 =
664 665 666 667 668
        new BulkCipher(CIPHER_AES,      BLOCK_CIPHER,    32, 16,  0, true);
    final static BulkCipher B_AES_128_GCM =
        new BulkCipher(CIPHER_AES_GCM,  AEAD_CIPHER,     16, 12,  4, true);
    final static BulkCipher B_AES_256_GCM =
        new BulkCipher(CIPHER_AES_GCM,  AEAD_CIPHER,     32, 12,  4, true);
D
duke 已提交
669 670

    // MACs
671 672 673 674 675
    final static MacAlg M_NULL    = new MacAlg("NULL",     0,   0,   0);
    final static MacAlg M_MD5     = new MacAlg("MD5",     16,  64,   9);
    final static MacAlg M_SHA     = new MacAlg("SHA",     20,  64,   9);
    final static MacAlg M_SHA256  = new MacAlg("SHA256",  32,  64,   9);
    final static MacAlg M_SHA384  = new MacAlg("SHA384",  48, 128,  17);
X
xuelei 已提交
676

677 678 679 680 681 682 683 684 685 686
    /**
     * PRFs (PseudoRandom Function) from TLS specifications.
     *
     * TLS 1.1- uses a single MD5/SHA1-based PRF algorithm for generating
     * the necessary material.
     *
     * In TLS 1.2+, all existing/known CipherSuites use SHA256, however
     * new Ciphersuites (e.g. RFC 5288) can define specific PRF hash
     * algorithms.
     */
X
xuelei 已提交
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
    static enum PRF {

        // PRF algorithms
        P_NONE(     "NONE",  0,   0),
        P_SHA256("SHA-256", 32,  64),
        P_SHA384("SHA-384", 48, 128),
        P_SHA512("SHA-512", 64, 128);  // not currently used.

        // PRF characteristics
        private final String prfHashAlg;
        private final int prfHashLength;
        private final int prfBlockSize;

        PRF(String prfHashAlg, int prfHashLength, int prfBlockSize) {
            this.prfHashAlg = prfHashAlg;
            this.prfHashLength = prfHashLength;
            this.prfBlockSize = prfBlockSize;
        }

        String getPRFHashAlg() {
            return prfHashAlg;
        }

        int getPRFHashLength() {
            return prfHashLength;
        }

        int getPRFBlockSize() {
            return prfBlockSize;
        }
    }
D
duke 已提交
718 719 720 721 722 723 724 725 726 727

    static {
        idMap = new HashMap<Integer,CipherSuite>();
        nameMap = new HashMap<String,CipherSuite>();

        final boolean F = false;
        final boolean T = true;
        // N: ciphersuites only allowed if we are not in FIPS mode
        final boolean N = (SunJSSE.isFIPS() == false);

X
xuelei 已提交
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
        /*
         * TLS Cipher Suite Registry, as of August 2010.
         *
         * http://www.iana.org/assignments/tls-parameters/tls-parameters.xml
         *
         * Range      Registration Procedures   Notes
         * 000-191    Standards Action          Refers to value of first byte
         * 192-254    Specification Required    Refers to value of first byte
         * 255        Reserved for Private Use  Refers to value of first byte
         *
         * Value      Description                               Reference
         * 0x00,0x00  TLS_NULL_WITH_NULL_NULL                   [RFC5246]
         * 0x00,0x01  TLS_RSA_WITH_NULL_MD5                     [RFC5246]
         * 0x00,0x02  TLS_RSA_WITH_NULL_SHA                     [RFC5246]
         * 0x00,0x03  TLS_RSA_EXPORT_WITH_RC4_40_MD5            [RFC4346]
         * 0x00,0x04  TLS_RSA_WITH_RC4_128_MD5                  [RFC5246]
         * 0x00,0x05  TLS_RSA_WITH_RC4_128_SHA                  [RFC5246]
         * 0x00,0x06  TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5        [RFC4346]
         * 0x00,0x07  TLS_RSA_WITH_IDEA_CBC_SHA                 [RFC5469]
         * 0x00,0x08  TLS_RSA_EXPORT_WITH_DES40_CBC_SHA         [RFC4346]
         * 0x00,0x09  TLS_RSA_WITH_DES_CBC_SHA                  [RFC5469]
         * 0x00,0x0A  TLS_RSA_WITH_3DES_EDE_CBC_SHA             [RFC5246]
         * 0x00,0x0B  TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA      [RFC4346]
         * 0x00,0x0C  TLS_DH_DSS_WITH_DES_CBC_SHA               [RFC5469]
         * 0x00,0x0D  TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA          [RFC5246]
         * 0x00,0x0E  TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA      [RFC4346]
         * 0x00,0x0F  TLS_DH_RSA_WITH_DES_CBC_SHA               [RFC5469]
         * 0x00,0x10  TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA          [RFC5246]
         * 0x00,0x11  TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA     [RFC4346]
         * 0x00,0x12  TLS_DHE_DSS_WITH_DES_CBC_SHA              [RFC5469]
         * 0x00,0x13  TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA         [RFC5246]
         * 0x00,0x14  TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA     [RFC4346]
         * 0x00,0x15  TLS_DHE_RSA_WITH_DES_CBC_SHA              [RFC5469]
         * 0x00,0x16  TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA         [RFC5246]
         * 0x00,0x17  TLS_DH_anon_EXPORT_WITH_RC4_40_MD5        [RFC4346]
         * 0x00,0x18  TLS_DH_anon_WITH_RC4_128_MD5              [RFC5246]
         * 0x00,0x19  TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA     [RFC4346]
         * 0x00,0x1A  TLS_DH_anon_WITH_DES_CBC_SHA              [RFC5469]
         * 0x00,0x1B  TLS_DH_anon_WITH_3DES_EDE_CBC_SHA         [RFC5246]
         * 0x00,0x1C-1D Reserved to avoid conflicts with SSLv3  [RFC5246]
         * 0x00,0x1E  TLS_KRB5_WITH_DES_CBC_SHA                 [RFC2712]
         * 0x00,0x1F  TLS_KRB5_WITH_3DES_EDE_CBC_SHA            [RFC2712]
         * 0x00,0x20  TLS_KRB5_WITH_RC4_128_SHA                 [RFC2712]
         * 0x00,0x21  TLS_KRB5_WITH_IDEA_CBC_SHA                [RFC2712]
         * 0x00,0x22  TLS_KRB5_WITH_DES_CBC_MD5                 [RFC2712]
         * 0x00,0x23  TLS_KRB5_WITH_3DES_EDE_CBC_MD5            [RFC2712]
         * 0x00,0x24  TLS_KRB5_WITH_RC4_128_MD5                 [RFC2712]
         * 0x00,0x25  TLS_KRB5_WITH_IDEA_CBC_MD5                [RFC2712]
         * 0x00,0x26  TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA       [RFC2712]
         * 0x00,0x27  TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA       [RFC2712]
         * 0x00,0x28  TLS_KRB5_EXPORT_WITH_RC4_40_SHA           [RFC2712]
         * 0x00,0x29  TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5       [RFC2712]
         * 0x00,0x2A  TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5       [RFC2712]
         * 0x00,0x2B  TLS_KRB5_EXPORT_WITH_RC4_40_MD5           [RFC2712]
         * 0x00,0x2C  TLS_PSK_WITH_NULL_SHA                     [RFC4785]
         * 0x00,0x2D  TLS_DHE_PSK_WITH_NULL_SHA                 [RFC4785]
         * 0x00,0x2E  TLS_RSA_PSK_WITH_NULL_SHA                 [RFC4785]
         * 0x00,0x2F  TLS_RSA_WITH_AES_128_CBC_SHA              [RFC5246]
         * 0x00,0x30  TLS_DH_DSS_WITH_AES_128_CBC_SHA           [RFC5246]
         * 0x00,0x31  TLS_DH_RSA_WITH_AES_128_CBC_SHA           [RFC5246]
         * 0x00,0x32  TLS_DHE_DSS_WITH_AES_128_CBC_SHA          [RFC5246]
         * 0x00,0x33  TLS_DHE_RSA_WITH_AES_128_CBC_SHA          [RFC5246]
         * 0x00,0x34  TLS_DH_anon_WITH_AES_128_CBC_SHA          [RFC5246]
         * 0x00,0x35  TLS_RSA_WITH_AES_256_CBC_SHA              [RFC5246]
         * 0x00,0x36  TLS_DH_DSS_WITH_AES_256_CBC_SHA           [RFC5246]
         * 0x00,0x37  TLS_DH_RSA_WITH_AES_256_CBC_SHA           [RFC5246]
         * 0x00,0x38  TLS_DHE_DSS_WITH_AES_256_CBC_SHA          [RFC5246]
         * 0x00,0x39  TLS_DHE_RSA_WITH_AES_256_CBC_SHA          [RFC5246]
         * 0x00,0x3A  TLS_DH_anon_WITH_AES_256_CBC_SHA          [RFC5246]
         * 0x00,0x3B  TLS_RSA_WITH_NULL_SHA256                  [RFC5246]
         * 0x00,0x3C  TLS_RSA_WITH_AES_128_CBC_SHA256           [RFC5246]
         * 0x00,0x3D  TLS_RSA_WITH_AES_256_CBC_SHA256           [RFC5246]
         * 0x00,0x3E  TLS_DH_DSS_WITH_AES_128_CBC_SHA256        [RFC5246]
         * 0x00,0x3F  TLS_DH_RSA_WITH_AES_128_CBC_SHA256        [RFC5246]
         * 0x00,0x40  TLS_DHE_DSS_WITH_AES_128_CBC_SHA256       [RFC5246]
         * 0x00,0x41  TLS_RSA_WITH_CAMELLIA_128_CBC_SHA         [RFC5932]
         * 0x00,0x42  TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA      [RFC5932]
         * 0x00,0x43  TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA      [RFC5932]
         * 0x00,0x44  TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA     [RFC5932]
         * 0x00,0x45  TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA     [RFC5932]
         * 0x00,0x46  TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA     [RFC5932]
         * 0x00,0x47-4F Reserved to avoid conflicts with
         *            deployed implementations                  [Pasi_Eronen]
         * 0x00,0x50-58 Reserved to avoid conflicts             [Pasi Eronen]
         * 0x00,0x59-5C Reserved to avoid conflicts with
         *            deployed implementations                  [Pasi_Eronen]
         * 0x00,0x5D-5F Unassigned
         * 0x00,0x60-66 Reserved to avoid conflicts with widely
         *            deployed implementations                  [Pasi_Eronen]
         * 0x00,0x67  TLS_DHE_RSA_WITH_AES_128_CBC_SHA256       [RFC5246]
         * 0x00,0x68  TLS_DH_DSS_WITH_AES_256_CBC_SHA256        [RFC5246]
         * 0x00,0x69  TLS_DH_RSA_WITH_AES_256_CBC_SHA256        [RFC5246]
         * 0x00,0x6A  TLS_DHE_DSS_WITH_AES_256_CBC_SHA256       [RFC5246]
         * 0x00,0x6B  TLS_DHE_RSA_WITH_AES_256_CBC_SHA256       [RFC5246]
         * 0x00,0x6C  TLS_DH_anon_WITH_AES_128_CBC_SHA256       [RFC5246]
         * 0x00,0x6D  TLS_DH_anon_WITH_AES_256_CBC_SHA256       [RFC5246]
         * 0x00,0x6E-83 Unassigned
         * 0x00,0x84  TLS_RSA_WITH_CAMELLIA_256_CBC_SHA         [RFC5932]
         * 0x00,0x85  TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA      [RFC5932]
         * 0x00,0x86  TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA      [RFC5932]
         * 0x00,0x87  TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA     [RFC5932]
         * 0x00,0x88  TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA     [RFC5932]
         * 0x00,0x89  TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA     [RFC5932]
         * 0x00,0x8A  TLS_PSK_WITH_RC4_128_SHA                  [RFC4279]
         * 0x00,0x8B  TLS_PSK_WITH_3DES_EDE_CBC_SHA             [RFC4279]
         * 0x00,0x8C  TLS_PSK_WITH_AES_128_CBC_SHA              [RFC4279]
         * 0x00,0x8D  TLS_PSK_WITH_AES_256_CBC_SHA              [RFC4279]
         * 0x00,0x8E  TLS_DHE_PSK_WITH_RC4_128_SHA              [RFC4279]
         * 0x00,0x8F  TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA         [RFC4279]
         * 0x00,0x90  TLS_DHE_PSK_WITH_AES_128_CBC_SHA          [RFC4279]
         * 0x00,0x91  TLS_DHE_PSK_WITH_AES_256_CBC_SHA          [RFC4279]
         * 0x00,0x92  TLS_RSA_PSK_WITH_RC4_128_SHA              [RFC4279]
         * 0x00,0x93  TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA         [RFC4279]
         * 0x00,0x94  TLS_RSA_PSK_WITH_AES_128_CBC_SHA          [RFC4279]
         * 0x00,0x95  TLS_RSA_PSK_WITH_AES_256_CBC_SHA          [RFC4279]
         * 0x00,0x96  TLS_RSA_WITH_SEED_CBC_SHA                 [RFC4162]
         * 0x00,0x97  TLS_DH_DSS_WITH_SEED_CBC_SHA              [RFC4162]
         * 0x00,0x98  TLS_DH_RSA_WITH_SEED_CBC_SHA              [RFC4162]
         * 0x00,0x99  TLS_DHE_DSS_WITH_SEED_CBC_SHA             [RFC4162]
         * 0x00,0x9A  TLS_DHE_RSA_WITH_SEED_CBC_SHA             [RFC4162]
         * 0x00,0x9B  TLS_DH_anon_WITH_SEED_CBC_SHA             [RFC4162]
         * 0x00,0x9C  TLS_RSA_WITH_AES_128_GCM_SHA256           [RFC5288]
         * 0x00,0x9D  TLS_RSA_WITH_AES_256_GCM_SHA384           [RFC5288]
         * 0x00,0x9E  TLS_DHE_RSA_WITH_AES_128_GCM_SHA256       [RFC5288]
         * 0x00,0x9F  TLS_DHE_RSA_WITH_AES_256_GCM_SHA384       [RFC5288]
         * 0x00,0xA0  TLS_DH_RSA_WITH_AES_128_GCM_SHA256        [RFC5288]
         * 0x00,0xA1  TLS_DH_RSA_WITH_AES_256_GCM_SHA384        [RFC5288]
         * 0x00,0xA2  TLS_DHE_DSS_WITH_AES_128_GCM_SHA256       [RFC5288]
         * 0x00,0xA3  TLS_DHE_DSS_WITH_AES_256_GCM_SHA384       [RFC5288]
         * 0x00,0xA4  TLS_DH_DSS_WITH_AES_128_GCM_SHA256        [RFC5288]
         * 0x00,0xA5  TLS_DH_DSS_WITH_AES_256_GCM_SHA384        [RFC5288]
         * 0x00,0xA6  TLS_DH_anon_WITH_AES_128_GCM_SHA256       [RFC5288]
         * 0x00,0xA7  TLS_DH_anon_WITH_AES_256_GCM_SHA384       [RFC5288]
         * 0x00,0xA8  TLS_PSK_WITH_AES_128_GCM_SHA256           [RFC5487]
         * 0x00,0xA9  TLS_PSK_WITH_AES_256_GCM_SHA384           [RFC5487]
         * 0x00,0xAA  TLS_DHE_PSK_WITH_AES_128_GCM_SHA256       [RFC5487]
         * 0x00,0xAB  TLS_DHE_PSK_WITH_AES_256_GCM_SHA384       [RFC5487]
         * 0x00,0xAC  TLS_RSA_PSK_WITH_AES_128_GCM_SHA256       [RFC5487]
         * 0x00,0xAD  TLS_RSA_PSK_WITH_AES_256_GCM_SHA384       [RFC5487]
         * 0x00,0xAE  TLS_PSK_WITH_AES_128_CBC_SHA256           [RFC5487]
         * 0x00,0xAF  TLS_PSK_WITH_AES_256_CBC_SHA384           [RFC5487]
         * 0x00,0xB0  TLS_PSK_WITH_NULL_SHA256                  [RFC5487]
         * 0x00,0xB1  TLS_PSK_WITH_NULL_SHA384                  [RFC5487]
         * 0x00,0xB2  TLS_DHE_PSK_WITH_AES_128_CBC_SHA256       [RFC5487]
         * 0x00,0xB3  TLS_DHE_PSK_WITH_AES_256_CBC_SHA384       [RFC5487]
         * 0x00,0xB4  TLS_DHE_PSK_WITH_NULL_SHA256              [RFC5487]
         * 0x00,0xB5  TLS_DHE_PSK_WITH_NULL_SHA384              [RFC5487]
         * 0x00,0xB6  TLS_RSA_PSK_WITH_AES_128_CBC_SHA256       [RFC5487]
         * 0x00,0xB7  TLS_RSA_PSK_WITH_AES_256_CBC_SHA384       [RFC5487]
         * 0x00,0xB8  TLS_RSA_PSK_WITH_NULL_SHA256              [RFC5487]
         * 0x00,0xB9  TLS_RSA_PSK_WITH_NULL_SHA384              [RFC5487]
         * 0x00,0xBA  TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256      [RFC5932]
         * 0x00,0xBB  TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256   [RFC5932]
         * 0x00,0xBC  TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256   [RFC5932]
         * 0x00,0xBD  TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256  [RFC5932]
         * 0x00,0xBE  TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256  [RFC5932]
         * 0x00,0xBF  TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256  [RFC5932]
         * 0x00,0xC0  TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256      [RFC5932]
         * 0x00,0xC1  TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256   [RFC5932]
         * 0x00,0xC2  TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256   [RFC5932]
         * 0x00,0xC3  TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256  [RFC5932]
         * 0x00,0xC4  TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256  [RFC5932]
         * 0x00,0xC5  TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256  [RFC5932]
         * 0x00,0xC6-FE         Unassigned
         * 0x00,0xFF  TLS_EMPTY_RENEGOTIATION_INFO_SCSV         [RFC5746]
         * 0x01-BF,*  Unassigned
         * 0xC0,0x01  TLS_ECDH_ECDSA_WITH_NULL_SHA              [RFC4492]
         * 0xC0,0x02  TLS_ECDH_ECDSA_WITH_RC4_128_SHA           [RFC4492]
         * 0xC0,0x03  TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA      [RFC4492]
         * 0xC0,0x04  TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA       [RFC4492]
         * 0xC0,0x05  TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA       [RFC4492]
         * 0xC0,0x06  TLS_ECDHE_ECDSA_WITH_NULL_SHA             [RFC4492]
         * 0xC0,0x07  TLS_ECDHE_ECDSA_WITH_RC4_128_SHA          [RFC4492]
         * 0xC0,0x08  TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA     [RFC4492]
         * 0xC0,0x09  TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA      [RFC4492]
         * 0xC0,0x0A  TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA      [RFC4492]
         * 0xC0,0x0B  TLS_ECDH_RSA_WITH_NULL_SHA                [RFC4492]
         * 0xC0,0x0C  TLS_ECDH_RSA_WITH_RC4_128_SHA             [RFC4492]
         * 0xC0,0x0D  TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA        [RFC4492]
         * 0xC0,0x0E  TLS_ECDH_RSA_WITH_AES_128_CBC_SHA         [RFC4492]
         * 0xC0,0x0F  TLS_ECDH_RSA_WITH_AES_256_CBC_SHA         [RFC4492]
         * 0xC0,0x10  TLS_ECDHE_RSA_WITH_NULL_SHA               [RFC4492]
         * 0xC0,0x11  TLS_ECDHE_RSA_WITH_RC4_128_SHA            [RFC4492]
         * 0xC0,0x12  TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA       [RFC4492]
         * 0xC0,0x13  TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA        [RFC4492]
         * 0xC0,0x14  TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA        [RFC4492]
         * 0xC0,0x15  TLS_ECDH_anon_WITH_NULL_SHA               [RFC4492]
         * 0xC0,0x16  TLS_ECDH_anon_WITH_RC4_128_SHA            [RFC4492]
         * 0xC0,0x17  TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA       [RFC4492]
         * 0xC0,0x18  TLS_ECDH_anon_WITH_AES_128_CBC_SHA        [RFC4492]
         * 0xC0,0x19  TLS_ECDH_anon_WITH_AES_256_CBC_SHA        [RFC4492]
         * 0xC0,0x1A  TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA         [RFC5054]
         * 0xC0,0x1B  TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA     [RFC5054]
         * 0xC0,0x1C  TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA     [RFC5054]
         * 0xC0,0x1D  TLS_SRP_SHA_WITH_AES_128_CBC_SHA          [RFC5054]
         * 0xC0,0x1E  TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA      [RFC5054]
         * 0xC0,0x1F  TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA      [RFC5054]
         * 0xC0,0x20  TLS_SRP_SHA_WITH_AES_256_CBC_SHA          [RFC5054]
         * 0xC0,0x21  TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA      [RFC5054]
         * 0xC0,0x22  TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA      [RFC5054]
         * 0xC0,0x23  TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256   [RFC5289]
         * 0xC0,0x24  TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384   [RFC5289]
         * 0xC0,0x25  TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256    [RFC5289]
         * 0xC0,0x26  TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384    [RFC5289]
         * 0xC0,0x27  TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256     [RFC5289]
         * 0xC0,0x28  TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384     [RFC5289]
         * 0xC0,0x29  TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256      [RFC5289]
         * 0xC0,0x2A  TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384      [RFC5289]
         * 0xC0,0x2B  TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256   [RFC5289]
         * 0xC0,0x2C  TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384   [RFC5289]
         * 0xC0,0x2D  TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256    [RFC5289]
         * 0xC0,0x2E  TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384    [RFC5289]
         * 0xC0,0x2F  TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256     [RFC5289]
         * 0xC0,0x30  TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384     [RFC5289]
         * 0xC0,0x31  TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256      [RFC5289]
         * 0xC0,0x32  TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384      [RFC5289]
         * 0xC0,0x33  TLS_ECDHE_PSK_WITH_RC4_128_SHA            [RFC5489]
         * 0xC0,0x34  TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA       [RFC5489]
         * 0xC0,0x35  TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA        [RFC5489]
         * 0xC0,0x36  TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA        [RFC5489]
         * 0xC0,0x37  TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256     [RFC5489]
         * 0xC0,0x38  TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384     [RFC5489]
         * 0xC0,0x39  TLS_ECDHE_PSK_WITH_NULL_SHA               [RFC5489]
         * 0xC0,0x3A  TLS_ECDHE_PSK_WITH_NULL_SHA256            [RFC5489]
         * 0xC0,0x3B  TLS_ECDHE_PSK_WITH_NULL_SHA384            [RFC5489]
         * 0xC0,0x3C-FF Unassigned
         * 0xC1-FD,*  Unassigned
         * 0xFE,0x00-FD Unassigned
         * 0xFE,0xFE-FF Reserved to avoid conflicts with widely
         *            deployed implementations                  [Pasi_Eronen]
         * 0xFF,0x00-FF Reserved for Private Use                [RFC5246]
         */

961 962
        add("SSL_NULL_WITH_NULL_NULL",
                              0x0000,   1, K_NULL,       B_NULL,    F);
D
duke 已提交
963

964 965 966 967
        /*
         * Definition of the CipherSuites that are enabled by default.
         * They are listed in preference order, most preferred first, using
         * the following criteria:
968 969 970
         * 1. Prefer Suite B compliant cipher suites, see RFC6460 (To be
         *    changed later, see below).
         * 2. Prefer the stronger bulk cipher, in the order of AES_256(GCM),
A
asmotrak 已提交
971
         *    AES_128(GCM), AES_256, AES_128, 3DES-EDE.
972
         * 3. Prefer the stronger MAC algorithm, in the order of SHA384,
973
         *    SHA256, SHA, MD5.
974
         * 4. Prefer the better performance of key exchange and digital
975 976 977
         *    signature algorithm, in the order of ECDHE-ECDSA, ECDHE-RSA,
         *    RSA, ECDH-ECDSA, ECDH-RSA, DHE-RSA, DHE-DSS.
         */
D
duke 已提交
978 979
        int p = DEFAULT_SUITES_PRIORITY * 2;

X
xuelei 已提交
980 981 982 983 984 985 986
        // shorten names to fit the following table cleanly.
        int max = ProtocolVersion.LIMIT_MAX_VALUE;
        int tls11 = ProtocolVersion.TLS11.v;
        int tls12 = ProtocolVersion.TLS12.v;

        //  ID           Key Exchange   Cipher     A  obs  suprt  PRF
        //  ======       ============   =========  =  ===  =====  ========
987 988 989 990 991 992 993 994 995 996


        // Placeholder for cipher suites in GCM mode.
        //
        // For better compatibility and interoperability, we decrease the
        // priority of cipher suites in GCM mode for a while as GCM
        // technologies mature in the industry.  Eventually we'll move
        // the GCM suites here.

        // AES_256(CBC)
997 998 999 1000
        add("TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
            0xc024, --p, K_ECDHE_ECDSA, B_AES_256, T, max, tls12, P_SHA384);
        add("TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
            0xc028, --p, K_ECDHE_RSA,   B_AES_256, T, max, tls12, P_SHA384);
X
xuelei 已提交
1001 1002
        add("TLS_RSA_WITH_AES_256_CBC_SHA256",
            0x003d, --p, K_RSA,         B_AES_256, T, max, tls12, P_SHA256);
1003 1004 1005 1006
        add("TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384",
            0xc026, --p, K_ECDH_ECDSA,  B_AES_256, T, max, tls12, P_SHA384);
        add("TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384",
            0xc02a, --p, K_ECDH_RSA,    B_AES_256, T, max, tls12, P_SHA384);
X
xuelei 已提交
1007 1008
        add("TLS_DHE_RSA_WITH_AES_256_CBC_SHA256",
            0x006b, --p, K_DHE_RSA,     B_AES_256, T, max, tls12, P_SHA256);
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
        add("TLS_DHE_DSS_WITH_AES_256_CBC_SHA256",
            0x006a, --p, K_DHE_DSS,     B_AES_256, T, max, tls12, P_SHA256);

        add("TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
            0xC00A, --p, K_ECDHE_ECDSA, B_AES_256, T);
        add("TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
            0xC014, --p, K_ECDHE_RSA,   B_AES_256, T);
        add("TLS_RSA_WITH_AES_256_CBC_SHA",
            0x0035, --p, K_RSA,         B_AES_256, T);
        add("TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA",
            0xC005, --p, K_ECDH_ECDSA,  B_AES_256, T);
        add("TLS_ECDH_RSA_WITH_AES_256_CBC_SHA",
            0xC00F, --p, K_ECDH_RSA,    B_AES_256, T);
        add("TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
            0x0039, --p, K_DHE_RSA,     B_AES_256, T);
        add("TLS_DHE_DSS_WITH_AES_256_CBC_SHA",
            0x0038, --p, K_DHE_DSS,     B_AES_256, T);
X
xuelei 已提交
1026

1027
        // AES_128(CBC)
X
xuelei 已提交
1028 1029 1030 1031
        add("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
            0xc023, --p, K_ECDHE_ECDSA, B_AES_128, T, max, tls12, P_SHA256);
        add("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
            0xc027, --p, K_ECDHE_RSA,   B_AES_128, T, max, tls12, P_SHA256);
1032 1033 1034 1035
        add("TLS_RSA_WITH_AES_128_CBC_SHA256",
            0x003c, --p, K_RSA,         B_AES_128, T, max, tls12, P_SHA256);
        add("TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256",
            0xc025, --p, K_ECDH_ECDSA,  B_AES_128, T, max, tls12, P_SHA256);
X
xuelei 已提交
1036 1037
        add("TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256",
            0xc029, --p, K_ECDH_RSA,    B_AES_128, T, max, tls12, P_SHA256);
1038 1039 1040 1041
        add("TLS_DHE_RSA_WITH_AES_128_CBC_SHA256",
            0x0067, --p, K_DHE_RSA,     B_AES_128, T, max, tls12, P_SHA256);
        add("TLS_DHE_DSS_WITH_AES_128_CBC_SHA256",
            0x0040, --p, K_DHE_DSS,     B_AES_128, T, max, tls12, P_SHA256);
X
xuelei 已提交
1042

1043 1044 1045 1046
        add("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
            0xC009, --p, K_ECDHE_ECDSA, B_AES_128, T);
        add("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
            0xC013, --p, K_ECDHE_RSA,   B_AES_128, T);
1047
        add("TLS_RSA_WITH_AES_128_CBC_SHA",
X
xuelei 已提交
1048
            0x002f, --p, K_RSA,         B_AES_128, T);
1049
        add("TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA",
X
xuelei 已提交
1050
            0xC004, --p, K_ECDH_ECDSA,  B_AES_128, T);
1051
        add("TLS_ECDH_RSA_WITH_AES_128_CBC_SHA",
X
xuelei 已提交
1052
            0xC00E, --p, K_ECDH_RSA,    B_AES_128, T);
1053 1054 1055 1056
        add("TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
            0x0033, --p, K_DHE_RSA,     B_AES_128, T);
        add("TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
            0x0032, --p, K_DHE_DSS,     B_AES_128, T);
1057

1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102
        // Cipher suites in GCM mode, see RFC 5288/5289.
        //
        // We may increase the priority of cipher suites in GCM mode when
        // GCM technologies become mature in the industry.

        // Suite B compliant cipher suites, see RFC 6460.
        //
        // Note that, at present this provider is not Suite B compliant. The
        // preference order of the GCM cipher suites does not follow the spec
        // of RFC 6460.
        add("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
            0xc02c, --p, K_ECDHE_ECDSA, B_AES_256_GCM, T, max, tls12, P_SHA384);
        add("TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
            0xc02b, --p, K_ECDHE_ECDSA, B_AES_128_GCM, T, max, tls12, P_SHA256);

        // AES_256(GCM)
        add("TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
            0xc030, --p, K_ECDHE_RSA,   B_AES_256_GCM, T, max, tls12, P_SHA384);
        add("TLS_RSA_WITH_AES_256_GCM_SHA384",
            0x009d, --p, K_RSA,         B_AES_256_GCM, T, max, tls12, P_SHA384);
        add("TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384",
            0xc02e, --p, K_ECDH_ECDSA,  B_AES_256_GCM, T, max, tls12, P_SHA384);
        add("TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384",
            0xc032, --p, K_ECDH_RSA,    B_AES_256_GCM, T, max, tls12, P_SHA384);
        add("TLS_DHE_RSA_WITH_AES_256_GCM_SHA384",
            0x009f, --p, K_DHE_RSA,     B_AES_256_GCM, T, max, tls12, P_SHA384);
        add("TLS_DHE_DSS_WITH_AES_256_GCM_SHA384",
            0x00a3, --p, K_DHE_DSS,     B_AES_256_GCM, T, max, tls12, P_SHA384);

        // AES_128(GCM)
        add("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
            0xc02f, --p, K_ECDHE_RSA,   B_AES_128_GCM, T, max, tls12, P_SHA256);
        add("TLS_RSA_WITH_AES_128_GCM_SHA256",
            0x009c, --p, K_RSA,         B_AES_128_GCM, T, max, tls12, P_SHA256);
        add("TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256",
            0xc02d, --p, K_ECDH_ECDSA,  B_AES_128_GCM, T, max, tls12, P_SHA256);
        add("TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256",
            0xc031, --p, K_ECDH_RSA,    B_AES_128_GCM, T, max, tls12, P_SHA256);
        add("TLS_DHE_RSA_WITH_AES_128_GCM_SHA256",
            0x009e, --p, K_DHE_RSA,     B_AES_128_GCM, T, max, tls12, P_SHA256);
        add("TLS_DHE_DSS_WITH_AES_128_GCM_SHA256",
            0x00a2, --p, K_DHE_DSS,     B_AES_128_GCM, T, max, tls12, P_SHA256);
        // End of cipher suites in GCM mode.

        // 3DES_EDE
1103 1104 1105 1106
        add("TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA",
            0xC008, --p, K_ECDHE_ECDSA, B_3DES,    T);
        add("TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
            0xC012, --p, K_ECDHE_RSA,   B_3DES,    T);
1107
        add("SSL_RSA_WITH_3DES_EDE_CBC_SHA",
X
xuelei 已提交
1108
            0x000a, --p, K_RSA,         B_3DES,    T);
1109
        add("TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA",
X
xuelei 已提交
1110
            0xC003, --p, K_ECDH_ECDSA,  B_3DES,    T);
1111
        add("TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA",
X
xuelei 已提交
1112
            0xC00D, --p, K_ECDH_RSA,    B_3DES,    T);
1113
        add("SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
X
xuelei 已提交
1114
            0x0016, --p, K_DHE_RSA,     B_3DES,    T);
1115
        add("SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA",
X
xuelei 已提交
1116
            0x0013, --p, K_DHE_DSS,     B_3DES,    N);
1117 1118 1119

        // Renegotiation protection request Signalling Cipher Suite Value (SCSV)
        add("TLS_EMPTY_RENEGOTIATION_INFO_SCSV",
X
xuelei 已提交
1120
            0x00ff, --p, K_SCSV,        B_NULL,    T);
D
duke 已提交
1121

1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
        /*
         * Definition of the CipherSuites that are supported but not enabled
         * by default.
         * They are listed in preference order, preferred first, using the
         * following criteria:
         * 1. CipherSuites for KRB5 need additional KRB5 service
         *    configuration, and these suites are not common in practice,
         *    so we put KRB5 based cipher suites at the end of the supported
         *    list.
         * 2. If a cipher suite has been obsoleted, we put it at the end of
         *    the list.
         * 3. Prefer the stronger bulk cipher, in the order of AES_256,
1134
         *    AES_128, 3DES-EDE, RC-4, DES, DES40, RC4_40, NULL.
1135 1136 1137 1138 1139 1140
         * 4. Prefer the stronger MAC algorithm, in the order of SHA384,
         *    SHA256, SHA, MD5.
         * 5. Prefer the better performance of key exchange and digital
         *    signature algorithm, in the order of ECDHE-ECDSA, ECDHE-RSA,
         *    RSA, ECDH-ECDSA, ECDH-RSA, DHE-RSA, DHE-DSS, anonymous.
         */
D
duke 已提交
1141 1142
        p = DEFAULT_SUITES_PRIORITY;

1143 1144 1145 1146 1147
        add("TLS_DH_anon_WITH_AES_256_GCM_SHA384",
            0x00a7, --p, K_DH_ANON,     B_AES_256_GCM, N, max, tls12, P_SHA384);
        add("TLS_DH_anon_WITH_AES_128_GCM_SHA256",
            0x00a6, --p, K_DH_ANON,     B_AES_128_GCM, N, max, tls12, P_SHA256);

1148 1149 1150
        add("TLS_DH_anon_WITH_AES_256_CBC_SHA256",
            0x006d, --p, K_DH_ANON,     B_AES_256, N, max, tls12, P_SHA256);
        add("TLS_ECDH_anon_WITH_AES_256_CBC_SHA",
1151
            0xC019, --p, K_ECDH_ANON,   B_AES_256, N);
1152
        add("TLS_DH_anon_WITH_AES_256_CBC_SHA",
X
xuelei 已提交
1153 1154 1155 1156
            0x003a, --p, K_DH_ANON,     B_AES_256, N);

        add("TLS_DH_anon_WITH_AES_128_CBC_SHA256",
            0x006c, --p, K_DH_ANON,     B_AES_128, N, max, tls12, P_SHA256);
1157
        add("TLS_ECDH_anon_WITH_AES_128_CBC_SHA",
1158
            0xC018, --p, K_ECDH_ANON,   B_AES_128, N);
1159 1160
        add("TLS_DH_anon_WITH_AES_128_CBC_SHA",
            0x0034, --p, K_DH_ANON,     B_AES_128, N);
1161 1162

        add("TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA",
1163
            0xC017, --p, K_ECDH_ANON,   B_3DES,    N);
1164 1165
        add("SSL_DH_anon_WITH_3DES_EDE_CBC_SHA",
            0x001b, --p, K_DH_ANON,     B_3DES,    N);
1166

A
asmotrak 已提交
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
        // RC-4
        add("TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
            0xC007, --p, K_ECDHE_ECDSA, B_RC4_128, N);
        add("TLS_ECDHE_RSA_WITH_RC4_128_SHA",
            0xC011, --p, K_ECDHE_RSA,   B_RC4_128, N);
        add("SSL_RSA_WITH_RC4_128_SHA",
            0x0005, --p, K_RSA,         B_RC4_128, N);
        add("TLS_ECDH_ECDSA_WITH_RC4_128_SHA",
            0xC002, --p, K_ECDH_ECDSA,  B_RC4_128, N);
        add("TLS_ECDH_RSA_WITH_RC4_128_SHA",
            0xC00C, --p, K_ECDH_RSA,    B_RC4_128, N);
        add("SSL_RSA_WITH_RC4_128_MD5",
            0x0004, --p, K_RSA,         B_RC4_128, N);

1181 1182 1183 1184
        add("TLS_ECDH_anon_WITH_RC4_128_SHA",
            0xC016, --p, K_ECDH_ANON,   B_RC4_128, N);
        add("SSL_DH_anon_WITH_RC4_128_MD5",
            0x0018, --p, K_DH_ANON,     B_RC4_128, N);
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194

        // weak cipher suites obsoleted in TLS 1.2
        add("SSL_RSA_WITH_DES_CBC_SHA",
            0x0009, --p, K_RSA,         B_DES,     N, tls12);
        add("SSL_DHE_RSA_WITH_DES_CBC_SHA",
            0x0015, --p, K_DHE_RSA,     B_DES,     N, tls12);
        add("SSL_DHE_DSS_WITH_DES_CBC_SHA",
            0x0012, --p, K_DHE_DSS,     B_DES,     N, tls12);
        add("SSL_DH_anon_WITH_DES_CBC_SHA",
            0x001a, --p, K_DH_ANON,     B_DES,     N, tls12);
X
xuelei 已提交
1195

1196
        // weak cipher suites obsoleted in TLS 1.1
X
xuelei 已提交
1197 1198 1199 1200 1201 1202
        add("SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
            0x0008, --p, K_RSA_EXPORT,  B_DES_40,  N, tls11);
        add("SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
            0x0014, --p, K_DHE_RSA,     B_DES_40,  N, tls11);
        add("SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA",
            0x0011, --p, K_DHE_DSS,     B_DES_40,  N, tls11);
1203 1204
        add("SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA",
            0x0019, --p, K_DH_ANON,     B_DES_40,  N, tls11);
1205

1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227
        add("SSL_RSA_EXPORT_WITH_RC4_40_MD5",
            0x0003, --p, K_RSA_EXPORT,  B_RC4_40,  N, tls11);
        add("SSL_DH_anon_EXPORT_WITH_RC4_40_MD5",
            0x0017, --p, K_DH_ANON,     B_RC4_40,  N, tls11);

        add("TLS_RSA_WITH_NULL_SHA256",
            0x003b, --p, K_RSA,         B_NULL,    N, max, tls12, P_SHA256);
        add("TLS_ECDHE_ECDSA_WITH_NULL_SHA",
            0xC006, --p, K_ECDHE_ECDSA, B_NULL,    N);
        add("TLS_ECDHE_RSA_WITH_NULL_SHA",
            0xC010, --p, K_ECDHE_RSA,   B_NULL,    N);
        add("SSL_RSA_WITH_NULL_SHA",
            0x0002, --p, K_RSA,         B_NULL,    N);
        add("TLS_ECDH_ECDSA_WITH_NULL_SHA",
            0xC001, --p, K_ECDH_ECDSA,  B_NULL,    N);
        add("TLS_ECDH_RSA_WITH_NULL_SHA",
            0xC00B, --p, K_ECDH_RSA,    B_NULL,    N);
        add("TLS_ECDH_anon_WITH_NULL_SHA",
            0xC015, --p, K_ECDH_ANON,   B_NULL,    N);
        add("SSL_RSA_WITH_NULL_MD5",
            0x0001, --p, K_RSA,         B_NULL,    N);

1228 1229
        // Supported Kerberos ciphersuites from RFC2712
        add("TLS_KRB5_WITH_3DES_EDE_CBC_SHA",
X
xuelei 已提交
1230
            0x001f, --p, K_KRB5,        B_3DES,    N);
1231
        add("TLS_KRB5_WITH_3DES_EDE_CBC_MD5",
X
xuelei 已提交
1232
            0x0023, --p, K_KRB5,        B_3DES,    N);
1233 1234 1235 1236
        add("TLS_KRB5_WITH_RC4_128_SHA",
            0x0020, --p, K_KRB5,        B_RC4_128, N);
        add("TLS_KRB5_WITH_RC4_128_MD5",
            0x0024, --p, K_KRB5,        B_RC4_128, N);
1237
        add("TLS_KRB5_WITH_DES_CBC_SHA",
X
xuelei 已提交
1238
            0x001e, --p, K_KRB5,        B_DES,     N, tls12);
1239
        add("TLS_KRB5_WITH_DES_CBC_MD5",
X
xuelei 已提交
1240
            0x0022, --p, K_KRB5,        B_DES,     N, tls12);
1241
        add("TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA",
X
xuelei 已提交
1242
            0x0026, --p, K_KRB5_EXPORT, B_DES_40,  N, tls11);
1243
        add("TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5",
X
xuelei 已提交
1244
            0x0029, --p, K_KRB5_EXPORT, B_DES_40,  N, tls11);
1245 1246 1247 1248
        add("TLS_KRB5_EXPORT_WITH_RC4_40_SHA",
            0x0028, --p, K_KRB5_EXPORT, B_RC4_40,  N, tls11);
        add("TLS_KRB5_EXPORT_WITH_RC4_40_MD5",
            0x002b, --p, K_KRB5_EXPORT, B_RC4_40,  N, tls11);
X
xuelei 已提交
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259

        /*
         * Other values from the TLS Cipher Suite Registry, as of August 2010.
         *
         * http://www.iana.org/assignments/tls-parameters/tls-parameters.xml
         *
         * Range      Registration Procedures   Notes
         * 000-191    Standards Action          Refers to value of first byte
         * 192-254    Specification Required    Refers to value of first byte
         * 255        Reserved for Private Use  Refers to value of first byte
         */
D
duke 已提交
1260 1261 1262 1263 1264 1265

        // Register the names of a few additional CipherSuites.
        // Makes them show up as names instead of numbers in
        // the debug output.

        // remaining unsupported ciphersuites defined in RFC2246.
X
xuelei 已提交
1266 1267 1268 1269 1270 1271 1272 1273
        add("SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5",          0x0006);
        add("SSL_RSA_WITH_IDEA_CBC_SHA",                   0x0007);
        add("SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA",        0x000b);
        add("SSL_DH_DSS_WITH_DES_CBC_SHA",                 0x000c);
        add("SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA",            0x000d);
        add("SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA",        0x000e);
        add("SSL_DH_RSA_WITH_DES_CBC_SHA",                 0x000f);
        add("SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA",            0x0010);
D
duke 已提交
1274 1275

        // SSL 3.0 Fortezza ciphersuites
X
xuelei 已提交
1276 1277
        add("SSL_FORTEZZA_DMS_WITH_NULL_SHA",              0x001c);
        add("SSL_FORTEZZA_DMS_WITH_FORTEZZA_CBC_SHA",      0x001d);
D
duke 已提交
1278 1279

        // 1024/56 bit exportable ciphersuites from expired internet draft
X
xuelei 已提交
1280 1281 1282 1283 1284
        add("SSL_RSA_EXPORT1024_WITH_DES_CBC_SHA",         0x0062);
        add("SSL_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA",     0x0063);
        add("SSL_RSA_EXPORT1024_WITH_RC4_56_SHA",          0x0064);
        add("SSL_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA",      0x0065);
        add("SSL_DHE_DSS_WITH_RC4_128_SHA",                0x0066);
D
duke 已提交
1285 1286 1287

        // Netscape old and new SSL 3.0 FIPS ciphersuites
        // see http://www.mozilla.org/projects/security/pki/nss/ssl/fips-ssl-ciphersuites.html
X
xuelei 已提交
1288 1289 1290 1291
        add("NETSCAPE_RSA_FIPS_WITH_3DES_EDE_CBC_SHA",     0xffe0);
        add("NETSCAPE_RSA_FIPS_WITH_DES_CBC_SHA",          0xffe1);
        add("SSL_RSA_FIPS_WITH_DES_CBC_SHA",               0xfefe);
        add("SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA",          0xfeff);
D
duke 已提交
1292 1293

        // Unsupported Kerberos cipher suites from RFC 2712
X
xuelei 已提交
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408
        add("TLS_KRB5_WITH_IDEA_CBC_SHA",                  0x0021);
        add("TLS_KRB5_WITH_IDEA_CBC_MD5",                  0x0025);
        add("TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA",         0x0027);
        add("TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5",         0x002a);

        // Unsupported cipher suites from RFC 4162
        add("TLS_RSA_WITH_SEED_CBC_SHA",                   0x0096);
        add("TLS_DH_DSS_WITH_SEED_CBC_SHA",                0x0097);
        add("TLS_DH_RSA_WITH_SEED_CBC_SHA",                0x0098);
        add("TLS_DHE_DSS_WITH_SEED_CBC_SHA",               0x0099);
        add("TLS_DHE_RSA_WITH_SEED_CBC_SHA",               0x009a);
        add("TLS_DH_anon_WITH_SEED_CBC_SHA",               0x009b);

        // Unsupported cipher suites from RFC 4279
        add("TLS_PSK_WITH_RC4_128_SHA",                    0x008a);
        add("TLS_PSK_WITH_3DES_EDE_CBC_SHA",               0x008b);
        add("TLS_PSK_WITH_AES_128_CBC_SHA",                0x008c);
        add("TLS_PSK_WITH_AES_256_CBC_SHA",                0x008d);
        add("TLS_DHE_PSK_WITH_RC4_128_SHA",                0x008e);
        add("TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA",           0x008f);
        add("TLS_DHE_PSK_WITH_AES_128_CBC_SHA",            0x0090);
        add("TLS_DHE_PSK_WITH_AES_256_CBC_SHA",            0x0091);
        add("TLS_RSA_PSK_WITH_RC4_128_SHA",                0x0092);
        add("TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA",           0x0093);
        add("TLS_RSA_PSK_WITH_AES_128_CBC_SHA",            0x0094);
        add("TLS_RSA_PSK_WITH_AES_256_CBC_SHA",            0x0095);

        // Unsupported cipher suites from RFC 4785
        add("TLS_PSK_WITH_NULL_SHA",                       0x002c);
        add("TLS_DHE_PSK_WITH_NULL_SHA",                   0x002d);
        add("TLS_RSA_PSK_WITH_NULL_SHA",                   0x002e);

        // Unsupported cipher suites from RFC 5246
        add("TLS_DH_DSS_WITH_AES_128_CBC_SHA",             0x0030);
        add("TLS_DH_RSA_WITH_AES_128_CBC_SHA",             0x0031);
        add("TLS_DH_DSS_WITH_AES_256_CBC_SHA",             0x0036);
        add("TLS_DH_RSA_WITH_AES_256_CBC_SHA",             0x0037);
        add("TLS_DH_DSS_WITH_AES_128_CBC_SHA256",          0x003e);
        add("TLS_DH_RSA_WITH_AES_128_CBC_SHA256",          0x003f);
        add("TLS_DH_DSS_WITH_AES_256_CBC_SHA256",          0x0068);
        add("TLS_DH_RSA_WITH_AES_256_CBC_SHA256",          0x0069);

        // Unsupported cipher suites from RFC 5288
        add("TLS_DH_RSA_WITH_AES_128_GCM_SHA256",          0x00a0);
        add("TLS_DH_RSA_WITH_AES_256_GCM_SHA384",          0x00a1);
        add("TLS_DH_DSS_WITH_AES_128_GCM_SHA256",          0x00a4);
        add("TLS_DH_DSS_WITH_AES_256_GCM_SHA384",          0x00a5);

        // Unsupported cipher suites from RFC 5487
        add("TLS_PSK_WITH_AES_128_GCM_SHA256",             0x00a8);
        add("TLS_PSK_WITH_AES_256_GCM_SHA384",             0x00a9);
        add("TLS_DHE_PSK_WITH_AES_128_GCM_SHA256",         0x00aa);
        add("TLS_DHE_PSK_WITH_AES_256_GCM_SHA384",         0x00ab);
        add("TLS_RSA_PSK_WITH_AES_128_GCM_SHA256",         0x00ac);
        add("TLS_RSA_PSK_WITH_AES_256_GCM_SHA384",         0x00ad);
        add("TLS_PSK_WITH_AES_128_CBC_SHA256",             0x00ae);
        add("TLS_PSK_WITH_AES_256_CBC_SHA384",             0x00af);
        add("TLS_PSK_WITH_NULL_SHA256",                    0x00b0);
        add("TLS_PSK_WITH_NULL_SHA384",                    0x00b1);
        add("TLS_DHE_PSK_WITH_AES_128_CBC_SHA256",         0x00b2);
        add("TLS_DHE_PSK_WITH_AES_256_CBC_SHA384",         0x00b3);
        add("TLS_DHE_PSK_WITH_NULL_SHA256",                0x00b4);
        add("TLS_DHE_PSK_WITH_NULL_SHA384",                0x00b5);
        add("TLS_RSA_PSK_WITH_AES_128_CBC_SHA256",         0x00b6);
        add("TLS_RSA_PSK_WITH_AES_256_CBC_SHA384",         0x00b7);
        add("TLS_RSA_PSK_WITH_NULL_SHA256",                0x00b8);
        add("TLS_RSA_PSK_WITH_NULL_SHA384",                0x00b9);

        // Unsupported cipher suites from RFC 5932
        add("TLS_RSA_WITH_CAMELLIA_128_CBC_SHA",           0x0041);
        add("TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA",        0x0042);
        add("TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA",        0x0043);
        add("TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA",       0x0044);
        add("TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA",       0x0045);
        add("TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA",       0x0046);
        add("TLS_RSA_WITH_CAMELLIA_256_CBC_SHA",           0x0084);
        add("TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA",        0x0085);
        add("TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA",        0x0086);
        add("TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA",       0x0087);
        add("TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA",       0x0088);
        add("TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA",       0x0089);
        add("TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256",        0x00ba);
        add("TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256",     0x00bb);
        add("TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256",     0x00bc);
        add("TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256",    0x00bd);
        add("TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256",    0x00be);
        add("TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256",    0x00bf);
        add("TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256",        0x00c0);
        add("TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256",     0x00c1);
        add("TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256",     0x00c2);
        add("TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256",    0x00c3);
        add("TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256",    0x00c4);
        add("TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256",    0x00c5);

        // Unsupported cipher suites from RFC 5054
        add("TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA",           0xc01a);
        add("TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA",       0xc01b);
        add("TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA",       0xc01c);
        add("TLS_SRP_SHA_WITH_AES_128_CBC_SHA",            0xc01d);
        add("TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA",        0xc01e);
        add("TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA",        0xc01f);
        add("TLS_SRP_SHA_WITH_AES_256_CBC_SHA",            0xc020);
        add("TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA",        0xc021);
        add("TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA",        0xc022);

        // Unsupported cipher suites from RFC 5489
        add("TLS_ECDHE_PSK_WITH_RC4_128_SHA",              0xc033);
        add("TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA",         0xc034);
        add("TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA",          0xc035);
        add("TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA",          0xc036);
        add("TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256",       0xc037);
        add("TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384",       0xc038);
        add("TLS_ECDHE_PSK_WITH_NULL_SHA",                 0xc039);
        add("TLS_ECDHE_PSK_WITH_NULL_SHA256",              0xc03a);
        add("TLS_ECDHE_PSK_WITH_NULL_SHA384",              0xc03b);
D
duke 已提交
1409 1410 1411 1412 1413
    }

    // ciphersuite SSL_NULL_WITH_NULL_NULL
    final static CipherSuite C_NULL = CipherSuite.valueOf(0, 0);

1414 1415
    // ciphersuite TLS_EMPTY_RENEGOTIATION_INFO_SCSV
    final static CipherSuite C_SCSV = CipherSuite.valueOf(0x00, 0xff);
D
duke 已提交
1416
}