< prev index next >

src/java.base/share/classes/sun/security/ssl/CipherSuite.java

Print this page




  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 package sun.security.ssl;
  27 
  28 import java.util.ArrayList;
  29 import java.util.Arrays;
  30 import java.util.Collection;
  31 import java.util.Collections;
  32 import java.util.LinkedList;
  33 import java.util.List;
  34 import static sun.security.ssl.CipherSuite.HashAlg.*;
  35 import static sun.security.ssl.CipherSuite.KeyExchange.*;
  36 import static sun.security.ssl.CipherSuite.MacAlg.*;
  37 import static sun.security.ssl.SSLCipher.*;
  38 import sun.security.ssl.NamedGroup.NamedGroupType;
  39 import static sun.security.ssl.NamedGroup.NamedGroupType.*;
  40 
  41 /**
  42  * Enum for SSL/(D)TLS cipher suites.
  43  *
  44  * Please refer to the "TLS Cipher Suite Registry" section for more details
  45  * about each cipher suite:
  46  *     https://www.iana.org/assignments/tls-parameters/tls-parameters.xml
  47  */
  48 enum CipherSuite {
  49     //
  50     // in preference order
  51     //
  52 
  53     // Definition of the CipherSuites that are enabled by default.
  54     //
  55     // They are listed in preference order, most preferred first, using
  56     // the following criteria:
  57     // 1. Prefer Suite B compliant cipher suites, see RFC6460 (To be
  58     //    changed later, see below).
  59     // 2. Prefer forward secrecy cipher suites.


 167     TLS_DHE_RSA_WITH_AES_256_CBC_SHA256(
 168             0x006B, true, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256", "",
 169             ProtocolVersion.PROTOCOLS_OF_12,
 170             K_DHE_RSA, B_AES_256, M_SHA256, H_SHA256),
 171     TLS_DHE_DSS_WITH_AES_256_CBC_SHA256(
 172             0x006A, true, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256", "",
 173             ProtocolVersion.PROTOCOLS_OF_12,
 174             K_DHE_DSS, B_AES_256, M_SHA256, H_SHA256),
 175 
 176     // AES_128(CBC) - DHE
 177     TLS_DHE_RSA_WITH_AES_128_CBC_SHA256(
 178             0x0067, true, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256", "",
 179             ProtocolVersion.PROTOCOLS_OF_12,
 180             K_DHE_RSA, B_AES_128, M_SHA256, H_SHA256),
 181     TLS_DHE_DSS_WITH_AES_128_CBC_SHA256(
 182             0x0040, true, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256", "",
 183             ProtocolVersion.PROTOCOLS_OF_12,
 184             K_DHE_DSS, B_AES_128, M_SHA256, H_SHA256),
 185 
 186     //
 187     // not forward secret cipher suites.
 188     //
 189 
 190     // AES_256(GCM)
 191     TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384(
 192             0xC02E, true, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384", "",
 193             ProtocolVersion.PROTOCOLS_OF_12,
 194             K_ECDH_ECDSA, B_AES_256_GCM, M_NULL, H_SHA384),
 195     TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384(
 196             0xC032, true, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384", "",
 197             ProtocolVersion.PROTOCOLS_OF_12,
 198             K_ECDH_RSA, B_AES_256_GCM, M_NULL, H_SHA384),
 199 
 200     // AES_128(GCM)
 201     TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256(
 202             0xC02D, true, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256", "",
 203             ProtocolVersion.PROTOCOLS_OF_12,
 204             K_ECDH_ECDSA, B_AES_128_GCM, M_NULL, H_SHA256),
 205     TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256(
 206             0xC031, true, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256", "",
 207             ProtocolVersion.PROTOCOLS_OF_12,


1089 
1090         return fragSize;
1091     }
1092 
1093     /**
1094      * An SSL/TLS key exchange algorithm.
1095      */
1096     static enum KeyExchange {
1097         K_NULL          ("NULL",           false, true,   NAMED_GROUP_NONE),
1098         K_RSA           ("RSA",            true,  false,  NAMED_GROUP_NONE),
1099         K_RSA_EXPORT    ("RSA_EXPORT",     true,  false,  NAMED_GROUP_NONE),
1100         K_DH_RSA        ("DH_RSA",         false, false,  NAMED_GROUP_NONE),
1101         K_DH_DSS        ("DH_DSS",         false, false,  NAMED_GROUP_NONE),
1102         K_DHE_DSS       ("DHE_DSS",        true,  false,  NAMED_GROUP_FFDHE),
1103         K_DHE_DSS_EXPORT("DHE_DSS_EXPORT", true,  false,  NAMED_GROUP_NONE),
1104         K_DHE_RSA       ("DHE_RSA",        true,  false,  NAMED_GROUP_FFDHE),
1105         K_DHE_RSA_EXPORT("DHE_RSA_EXPORT", true,  false,  NAMED_GROUP_NONE),
1106         K_DH_ANON       ("DH_anon",        true,  true,   NAMED_GROUP_FFDHE),
1107         K_DH_ANON_EXPORT("DH_anon_EXPORT", true,  true,   NAMED_GROUP_NONE),
1108 
1109         // These KeyExchanges can use either ECDHE/XDH, so we'll use a
1110         // varargs here.
1111         K_ECDH_ECDSA    ("ECDH_ECDSA",     JsseJce.ALLOW_ECC,  false,
1112                 NAMED_GROUP_ECDHE, NAMED_GROUP_XDH),
1113         K_ECDH_RSA      ("ECDH_RSA",       JsseJce.ALLOW_ECC,  false,
1114             NAMED_GROUP_ECDHE, NAMED_GROUP_XDH),
1115         K_ECDHE_ECDSA   ("ECDHE_ECDSA",    JsseJce.ALLOW_ECC,  false,
1116             NAMED_GROUP_ECDHE, NAMED_GROUP_XDH),
1117         K_ECDHE_RSA     ("ECDHE_RSA",      JsseJce.ALLOW_ECC,  false,
1118             NAMED_GROUP_ECDHE, NAMED_GROUP_XDH),
1119         K_ECDH_ANON     ("ECDH_anon",      JsseJce.ALLOW_ECC,  true,
1120             NAMED_GROUP_ECDHE, NAMED_GROUP_XDH),
1121 
1122         // renegotiation protection request signaling cipher suite
1123         K_SCSV          ("SCSV",           true,  true,   NAMED_GROUP_NONE);
1124 
1125         // name of the key exchange algorithm, e.g. DHE_DSS
1126         final String name;
1127         final boolean allowed;
1128         final NamedGroupType[] groupTypes;
1129         private final boolean alwaysAvailable;
1130         private final boolean isAnonymous;
1131 
1132         KeyExchange(String name, boolean allowed,
1133                 boolean isAnonymous, NamedGroupType... groupTypes) {
1134             this.name = name;
1135             this.groupTypes = groupTypes;
1136             this.allowed = allowed;
1137 



1138             this.alwaysAvailable = allowed && (!name.startsWith("EC"));
1139             this.isAnonymous = isAnonymous;
1140         }
1141 
1142         boolean isAvailable() {
1143             if (alwaysAvailable) {
1144                 return true;
1145             }
1146 
1147             if (NamedGroupType.arrayContains(
1148                     groupTypes, NamedGroupType.NAMED_GROUP_ECDHE)) {
1149                 return (allowed && JsseJce.isEcAvailable());
1150             } else {
1151                 return allowed;
1152             }
1153         }
1154 
1155         @Override
1156         public String toString() {
1157             return name;
1158         }
1159     }
1160 
1161     /**
1162      * An SSL/TLS key MAC algorithm.
1163      *
1164      * Also contains a factory method to obtain an initialized MAC
1165      * for this algorithm.
1166      */
1167     static enum MacAlg {
1168         M_NULL      ("NULL",     0,   0,   0),




  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 package sun.security.ssl;
  27 
  28 import java.util.ArrayList;
  29 import java.util.Arrays;
  30 import java.util.Collection;
  31 import java.util.Collections;
  32 import java.util.LinkedList;
  33 import java.util.List;
  34 import static sun.security.ssl.CipherSuite.HashAlg.*;
  35 import static sun.security.ssl.CipherSuite.KeyExchange.*;
  36 import static sun.security.ssl.CipherSuite.MacAlg.*;
  37 import static sun.security.ssl.SSLCipher.*;
  38 import sun.security.ssl.SupportedGroupsExtension.NamedGroupType;
  39 import static sun.security.ssl.SupportedGroupsExtension.NamedGroupType.*;
  40 
  41 /**
  42  * Enum for SSL/(D)TLS cipher suites.
  43  *
  44  * Please refer to the "TLS Cipher Suite Registry" section for more details
  45  * about each cipher suite:
  46  *     https://www.iana.org/assignments/tls-parameters/tls-parameters.xml
  47  */
  48 enum CipherSuite {
  49     //
  50     // in preference order
  51     //
  52 
  53     // Definition of the CipherSuites that are enabled by default.
  54     //
  55     // They are listed in preference order, most preferred first, using
  56     // the following criteria:
  57     // 1. Prefer Suite B compliant cipher suites, see RFC6460 (To be
  58     //    changed later, see below).
  59     // 2. Prefer forward secrecy cipher suites.


 167     TLS_DHE_RSA_WITH_AES_256_CBC_SHA256(
 168             0x006B, true, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256", "",
 169             ProtocolVersion.PROTOCOLS_OF_12,
 170             K_DHE_RSA, B_AES_256, M_SHA256, H_SHA256),
 171     TLS_DHE_DSS_WITH_AES_256_CBC_SHA256(
 172             0x006A, true, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256", "",
 173             ProtocolVersion.PROTOCOLS_OF_12,
 174             K_DHE_DSS, B_AES_256, M_SHA256, H_SHA256),
 175 
 176     // AES_128(CBC) - DHE
 177     TLS_DHE_RSA_WITH_AES_128_CBC_SHA256(
 178             0x0067, true, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256", "",
 179             ProtocolVersion.PROTOCOLS_OF_12,
 180             K_DHE_RSA, B_AES_128, M_SHA256, H_SHA256),
 181     TLS_DHE_DSS_WITH_AES_128_CBC_SHA256(
 182             0x0040, true, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256", "",
 183             ProtocolVersion.PROTOCOLS_OF_12,
 184             K_DHE_DSS, B_AES_128, M_SHA256, H_SHA256),
 185 
 186     //
 187     // not forward screcy cipher suites.
 188     //
 189 
 190     // AES_256(GCM)
 191     TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384(
 192             0xC02E, true, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384", "",
 193             ProtocolVersion.PROTOCOLS_OF_12,
 194             K_ECDH_ECDSA, B_AES_256_GCM, M_NULL, H_SHA384),
 195     TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384(
 196             0xC032, true, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384", "",
 197             ProtocolVersion.PROTOCOLS_OF_12,
 198             K_ECDH_RSA, B_AES_256_GCM, M_NULL, H_SHA384),
 199 
 200     // AES_128(GCM)
 201     TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256(
 202             0xC02D, true, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256", "",
 203             ProtocolVersion.PROTOCOLS_OF_12,
 204             K_ECDH_ECDSA, B_AES_128_GCM, M_NULL, H_SHA256),
 205     TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256(
 206             0xC031, true, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256", "",
 207             ProtocolVersion.PROTOCOLS_OF_12,


1089 
1090         return fragSize;
1091     }
1092 
1093     /**
1094      * An SSL/TLS key exchange algorithm.
1095      */
1096     static enum KeyExchange {
1097         K_NULL          ("NULL",           false, true,   NAMED_GROUP_NONE),
1098         K_RSA           ("RSA",            true,  false,  NAMED_GROUP_NONE),
1099         K_RSA_EXPORT    ("RSA_EXPORT",     true,  false,  NAMED_GROUP_NONE),
1100         K_DH_RSA        ("DH_RSA",         false, false,  NAMED_GROUP_NONE),
1101         K_DH_DSS        ("DH_DSS",         false, false,  NAMED_GROUP_NONE),
1102         K_DHE_DSS       ("DHE_DSS",        true,  false,  NAMED_GROUP_FFDHE),
1103         K_DHE_DSS_EXPORT("DHE_DSS_EXPORT", true,  false,  NAMED_GROUP_NONE),
1104         K_DHE_RSA       ("DHE_RSA",        true,  false,  NAMED_GROUP_FFDHE),
1105         K_DHE_RSA_EXPORT("DHE_RSA_EXPORT", true,  false,  NAMED_GROUP_NONE),
1106         K_DH_ANON       ("DH_anon",        true,  true,   NAMED_GROUP_FFDHE),
1107         K_DH_ANON_EXPORT("DH_anon_EXPORT", true,  true,   NAMED_GROUP_NONE),
1108 
1109         K_ECDH_ECDSA    ("ECDH_ECDSA",     true,  false,  NAMED_GROUP_ECDHE),
1110         K_ECDH_RSA      ("ECDH_RSA",       true,  false,  NAMED_GROUP_ECDHE),
1111         K_ECDHE_ECDSA   ("ECDHE_ECDSA",    true,  false,  NAMED_GROUP_ECDHE),
1112         K_ECDHE_RSA     ("ECDHE_RSA",      true,  false,  NAMED_GROUP_ECDHE),
1113         K_ECDH_ANON     ("ECDH_anon",      true,  true,   NAMED_GROUP_ECDHE),







1114 
1115         // renegotiation protection request signaling cipher suite
1116         K_SCSV          ("SCSV",           true,  true,   NAMED_GROUP_NONE);
1117 
1118         // name of the key exchange algorithm, e.g. DHE_DSS
1119         final String name;
1120         final boolean allowed;
1121         final NamedGroupType groupType;
1122         private final boolean alwaysAvailable;
1123         private final boolean isAnonymous;
1124 
1125         KeyExchange(String name, boolean allowed,
1126                 boolean isAnonymous, NamedGroupType groupType) {
1127             this.name = name;
1128             if (groupType == NAMED_GROUP_ECDHE) {
1129                 this.allowed = JsseJce.ALLOW_ECC;
1130             } else {
1131                 this.allowed = allowed;
1132             }
1133             this.groupType = groupType;
1134             this.alwaysAvailable = allowed && (!name.startsWith("EC"));
1135             this.isAnonymous = isAnonymous;
1136         }
1137 
1138         boolean isAvailable() {
1139             if (alwaysAvailable) {
1140                 return true;
1141             }
1142 
1143             if (groupType == NAMED_GROUP_ECDHE) {

1144                 return (allowed && JsseJce.isEcAvailable());
1145             } else {
1146                 return allowed;
1147             }
1148         }
1149 
1150         @Override
1151         public String toString() {
1152             return name;
1153         }
1154     }
1155 
1156     /**
1157      * An SSL/TLS key MAC algorithm.
1158      *
1159      * Also contains a factory method to obtain an initialized MAC
1160      * for this algorithm.
1161      */
1162     static enum MacAlg {
1163         M_NULL      ("NULL",     0,   0,   0),


< prev index next >