1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.conscrypt; 19 20 import java.security.GeneralSecurityException; 21 import java.util.Hashtable; 22 import javax.crypto.Cipher; 23 24 /** 25 * Represents Cipher Suite as defined in TLS 1.0 spec., 26 * A.5. The CipherSuite; 27 * C. CipherSuite definitions. 28 * @see <a href="http://www.ietf.org/rfc/rfc2246.txt">TLS 1.0 spec.</a> 29 * 30 */ 31 public class CipherSuite { 32 33 /** 34 * true if this cipher suite is supported 35 */ 36 boolean supported = true; 37 38 /** 39 * cipher suite key exchange 40 */ 41 final int keyExchange; 42 43 /** 44 * algorithm used for authentication ("RSA", "DSA", "DH", null for anonymous) 45 */ 46 final String authType; 47 48 /** 49 * cipher 50 */ 51 final String cipherName; 52 53 /** 54 * Cipher information 55 */ 56 final int keyMaterial; 57 final int expandedKeyMaterial; 58 final int effectiveKeyBytes; 59 final int ivSize; 60 final private int blockSize; 61 62 // cipher suite code 63 private final byte[] cipherSuiteCode; 64 65 // cipher suite name 66 private final String name; 67 68 // true if cipher suite is exportable 69 private final boolean isExportable; 70 71 // Hash algorithm 72 final private String hashName; 73 74 // MAC algorithm 75 final private String hmacName; 76 77 // Hash size 78 final private int hashSize; 79 80 /** 81 * key exchange values 82 */ 83 static final int KEY_EXCHANGE_RSA = 1; 84 static final int KEY_EXCHANGE_RSA_EXPORT = 2; 85 static final int KEY_EXCHANGE_DHE_DSS = 3; 86 static final int KEY_EXCHANGE_DHE_DSS_EXPORT = 4; 87 static final int KEY_EXCHANGE_DHE_RSA = 5; 88 static final int KEY_EXCHANGE_DHE_RSA_EXPORT = 6; 89 // BEGIN android-removed 90 // static final int KEY_EXCHANGE_DH_DSS = 7; 91 // static final int KEY_EXCHANGE_DH_RSA = 8; 92 // END android-removed 93 static final int KEY_EXCHANGE_DH_anon = 9; 94 static final int KEY_EXCHANGE_DH_anon_EXPORT = 10; 95 // BEGIN android-removed 96 // static final int KEY_EXCHANGE_DH_DSS_EXPORT = 11; 97 // static final int KEY_EXCHANGE_DH_RSA_EXPORT = 12; 98 // END android-removed 99 static final int KEY_EXCHANGE_ECDH_ECDSA = 13; 100 static final int KEY_EXCHANGE_ECDHE_ECDSA = 14; 101 static final int KEY_EXCHANGE_ECDH_RSA = 15; 102 static final int KEY_EXCHANGE_ECDHE_RSA = 16; 103 static final int KEY_EXCHANGE_ECDH_anon = 17; 104 105 /** 106 * TLS cipher suite codes 107 */ 108 static final byte[] CODE_SSL_NULL_WITH_NULL_NULL = { 0x00, 0x00 }; 109 static final byte[] CODE_SSL_RSA_WITH_NULL_MD5 = { 0x00, 0x01 }; 110 static final byte[] CODE_SSL_RSA_WITH_NULL_SHA = { 0x00, 0x02 }; 111 static final byte[] CODE_SSL_RSA_EXPORT_WITH_RC4_40_MD5 = { 0x00, 0x03 }; 112 static final byte[] CODE_SSL_RSA_WITH_RC4_128_MD5 = { 0x00, 0x04 }; 113 static final byte[] CODE_SSL_RSA_WITH_RC4_128_SHA = { 0x00, 0x05 }; 114 static final byte[] CODE_SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5 = { 0x00, 0x06 }; 115 // BEGIN android-removed 116 // static final byte[] CODE_TLS_RSA_WITH_IDEA_CBC_SHA = { 0x00, 0x07 }; 117 // END android-removed 118 static final byte[] CODE_SSL_RSA_EXPORT_WITH_DES40_CBC_SHA = { 0x00, 0x08 }; 119 static final byte[] CODE_SSL_RSA_WITH_DES_CBC_SHA = { 0x00, 0x09 }; 120 static final byte[] CODE_SSL_RSA_WITH_3DES_EDE_CBC_SHA = { 0x00, 0x0A }; 121 // BEGIN android-removed 122 // static final byte[] CODE_SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA = { 0x00, 0x0B }; 123 // static final byte[] CODE_SSL_DH_DSS_WITH_DES_CBC_SHA = { 0x00, 0x0C }; 124 // static final byte[] CODE_SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA = { 0x00, 0x0D }; 125 // static final byte[] CODE_SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA = { 0x00, 0x0E }; 126 // static final byte[] CODE_SSL_DH_RSA_WITH_DES_CBC_SHA = { 0x00, 0x0F }; 127 // static final byte[] CODE_SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA = { 0x00, 0x10 }; 128 // END android-removed 129 static final byte[] CODE_SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA = { 0x00, 0x11 }; 130 static final byte[] CODE_SSL_DHE_DSS_WITH_DES_CBC_SHA = { 0x00, 0x12 }; 131 static final byte[] CODE_SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA = { 0x00, 0x13 }; 132 static final byte[] CODE_SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA = { 0x00, 0x14 }; 133 static final byte[] CODE_SSL_DHE_RSA_WITH_DES_CBC_SHA = { 0x00, 0x15 }; 134 static final byte[] CODE_SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA = { 0x00, 0x16 }; 135 static final byte[] CODE_SSL_DH_anon_EXPORT_WITH_RC4_40_MD5 = { 0x00, 0x17 }; 136 static final byte[] CODE_SSL_DH_anon_WITH_RC4_128_MD5 = { 0x00, 0x18 }; 137 static final byte[] CODE_SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA = { 0x00, 0x19 }; 138 static final byte[] CODE_SSL_DH_anon_WITH_DES_CBC_SHA = { 0x00, 0x1A }; 139 static final byte[] CODE_SSL_DH_anon_WITH_3DES_EDE_CBC_SHA = { 0x00, 0x1B }; 140 141 // AES Cipher Suites from RFC 3268 - http://www.ietf.org/rfc/rfc3268.txt 142 static final byte[] CODE_TLS_RSA_WITH_AES_128_CBC_SHA = { 0x00, 0x2F }; 143 //static final byte[] CODE_TLS_DH_DSS_WITH_AES_128_CBC_SHA = { 0x00, 0x30 }; 144 //static final byte[] CODE_TLS_DH_RSA_WITH_AES_128_CBC_SHA = { 0x00, 0x31 }; 145 static final byte[] CODE_TLS_DHE_DSS_WITH_AES_128_CBC_SHA = { 0x00, 0x32 }; 146 static final byte[] CODE_TLS_DHE_RSA_WITH_AES_128_CBC_SHA = { 0x00, 0x33 }; 147 static final byte[] CODE_TLS_DH_anon_WITH_AES_128_CBC_SHA = { 0x00, 0x34 }; 148 static final byte[] CODE_TLS_RSA_WITH_AES_256_CBC_SHA = { 0x00, 0x35 }; 149 //static final byte[] CODE_TLS_DH_DSS_WITH_AES_256_CBC_SHA = { 0x00, 0x36 }; 150 //static final byte[] CODE_TLS_DH_RSA_WITH_AES_256_CBC_SHA = { 0x00, 0x37 }; 151 static final byte[] CODE_TLS_DHE_DSS_WITH_AES_256_CBC_SHA = { 0x00, 0x38 }; 152 static final byte[] CODE_TLS_DHE_RSA_WITH_AES_256_CBC_SHA = { 0x00, 0x39 }; 153 static final byte[] CODE_TLS_DH_anon_WITH_AES_256_CBC_SHA = { 0x00, 0x3A }; 154 155 // EC Cipher Suites from RFC 4492 - http://www.ietf.org/rfc/rfc4492.txt 156 static final byte[] CODE_TLS_ECDH_ECDSA_WITH_NULL_SHA = { (byte) 0xc0, 0x01}; 157 static final byte[] CODE_TLS_ECDH_ECDSA_WITH_RC4_128_SHA = { (byte) 0xc0, 0x02}; 158 static final byte[] CODE_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA = { (byte) 0xc0, 0x03}; 159 static final byte[] CODE_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA = { (byte) 0xc0, 0x04}; 160 static final byte[] CODE_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA = { (byte) 0xc0, 0x05}; 161 static final byte[] CODE_TLS_ECDHE_ECDSA_WITH_NULL_SHA = { (byte) 0xc0, 0x06}; 162 static final byte[] CODE_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA = { (byte) 0xc0, 0x07}; 163 static final byte[] CODE_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA = { (byte) 0xc0, 0x08}; 164 static final byte[] CODE_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = { (byte) 0xc0, 0x09}; 165 static final byte[] CODE_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = { (byte) 0xc0, 0x0A}; 166 static final byte[] CODE_TLS_ECDH_RSA_WITH_NULL_SHA = { (byte) 0xc0, 0x0B}; 167 static final byte[] CODE_TLS_ECDH_RSA_WITH_RC4_128_SHA = { (byte) 0xc0, 0x0C}; 168 static final byte[] CODE_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA = { (byte) 0xc0, 0x0D}; 169 static final byte[] CODE_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA = { (byte) 0xc0, 0x0E}; 170 static final byte[] CODE_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA = { (byte) 0xc0, 0x0F}; 171 static final byte[] CODE_TLS_ECDHE_RSA_WITH_NULL_SHA = { (byte) 0xc0, 0x10}; 172 static final byte[] CODE_TLS_ECDHE_RSA_WITH_RC4_128_SHA = { (byte) 0xc0, 0x11}; 173 static final byte[] CODE_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA = { (byte) 0xc0, 0x12}; 174 static final byte[] CODE_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = { (byte) 0xc0, 0x13}; 175 static final byte[] CODE_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = { (byte) 0xc0, 0x14}; 176 static final byte[] CODE_TLS_ECDH_anon_WITH_NULL_SHA = { (byte) 0xc0, 0x15}; 177 static final byte[] CODE_TLS_ECDH_anon_WITH_RC4_128_SHA = { (byte) 0xc0, 0x16}; 178 static final byte[] CODE_TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA = { (byte) 0xc0, 0x17}; 179 static final byte[] CODE_TLS_ECDH_anon_WITH_AES_128_CBC_SHA = { (byte) 0xc0, 0x18}; 180 static final byte[] CODE_TLS_ECDH_anon_WITH_AES_256_CBC_SHA = { (byte) 0xc0, 0x19}; 181 182 static final CipherSuite SSL_NULL_WITH_NULL_NULL = new CipherSuite( 183 "SSL_NULL_WITH_NULL_NULL", true, 0, null, null, null, 184 CODE_SSL_NULL_WITH_NULL_NULL); 185 186 static final CipherSuite SSL_RSA_WITH_NULL_MD5 = new CipherSuite( 187 "SSL_RSA_WITH_NULL_MD5", true, KEY_EXCHANGE_RSA, "RSA", null, "MD5", 188 CODE_SSL_RSA_WITH_NULL_MD5); 189 190 static final CipherSuite SSL_RSA_WITH_NULL_SHA = new CipherSuite( 191 "SSL_RSA_WITH_NULL_SHA", true, KEY_EXCHANGE_RSA, "RSA", null, "SHA", 192 CODE_SSL_RSA_WITH_NULL_SHA); 193 194 static final CipherSuite SSL_RSA_EXPORT_WITH_RC4_40_MD5 = new CipherSuite( 195 "SSL_RSA_EXPORT_WITH_RC4_40_MD5", true, KEY_EXCHANGE_RSA_EXPORT, 196 "RSA", "RC4_40", "MD5", CODE_SSL_RSA_EXPORT_WITH_RC4_40_MD5); 197 198 static final CipherSuite SSL_RSA_WITH_RC4_128_MD5 = new CipherSuite( 199 "SSL_RSA_WITH_RC4_128_MD5", false, KEY_EXCHANGE_RSA, "RSA", "RC4_128", 200 "MD5", CODE_SSL_RSA_WITH_RC4_128_MD5); 201 202 static final CipherSuite SSL_RSA_WITH_RC4_128_SHA = new CipherSuite( 203 "SSL_RSA_WITH_RC4_128_SHA", false, KEY_EXCHANGE_RSA, "RSA", "RC4_128", 204 "SHA", CODE_SSL_RSA_WITH_RC4_128_SHA); 205 206 static final CipherSuite SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5 = new CipherSuite( 207 "SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5", true, KEY_EXCHANGE_RSA_EXPORT, 208 "RSA", "RC2_CBC_40", "MD5", CODE_SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5); 209 210 // BEGIN android-removed 211 // static final CipherSuite TLS_RSA_WITH_IDEA_CBC_SHA = new CipherSuite( 212 // "TLS_RSA_WITH_IDEA_CBC_SHA", false, KEY_EXCHANGE_RSA, "RSA", "IDEA_CBC", 213 // "SHA", CODE_TLS_RSA_WITH_IDEA_CBC_SHA); 214 // END android-removed 215 216 static final CipherSuite SSL_RSA_EXPORT_WITH_DES40_CBC_SHA = new CipherSuite( 217 "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", true, KEY_EXCHANGE_RSA_EXPORT, 218 "RSA", "DES40_CBC", "SHA", CODE_SSL_RSA_EXPORT_WITH_DES40_CBC_SHA); 219 220 static final CipherSuite SSL_RSA_WITH_DES_CBC_SHA = new CipherSuite( 221 "SSL_RSA_WITH_DES_CBC_SHA", false, KEY_EXCHANGE_RSA, "RSA", "DES_CBC", 222 "SHA", CODE_SSL_RSA_WITH_DES_CBC_SHA); 223 224 static final CipherSuite SSL_RSA_WITH_3DES_EDE_CBC_SHA = new CipherSuite( 225 "SSL_RSA_WITH_3DES_EDE_CBC_SHA", false, KEY_EXCHANGE_RSA, 226 "RSA", "3DES_EDE_CBC", "SHA", CODE_SSL_RSA_WITH_3DES_EDE_CBC_SHA); 227 228 // BEGIN android-removed 229 // static final CipherSuite SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA = new CipherSuite( 230 // "SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA", true, 231 // KEY_EXCHANGE_DH_DSS_EXPORT, "DH", "DES40_CBC", "SHA", 232 // CODE_SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA); 233 // 234 // static final CipherSuite SSL_DH_DSS_WITH_DES_CBC_SHA = new CipherSuite( 235 // "SSL_DH_DSS_WITH_DES_CBC_SHA", false, KEY_EXCHANGE_DH_DSS, 236 // "DH", "DES_CBC", "SHA", CODE_SSL_DH_DSS_WITH_DES_CBC_SHA); 237 // 238 // static final CipherSuite SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA = new CipherSuite( 239 // "SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA", false, KEY_EXCHANGE_DH_DSS, 240 // "DH", "3DES_EDE_CBC", "SHA", CODE_SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA); 241 // 242 // static final CipherSuite SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA = new CipherSuite( 243 // "SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA", true, 244 // KEY_EXCHANGE_DH_RSA_EXPORT, "DH", "DES40_CBC", "SHA", 245 // CODE_SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA); 246 // 247 // static final CipherSuite SSL_DH_RSA_WITH_DES_CBC_SHA = new CipherSuite( 248 // "SSL_DH_RSA_WITH_DES_CBC_SHA", false, KEY_EXCHANGE_DH_RSA, 249 // "DH", "DES_CBC", "SHA", CODE_SSL_DH_RSA_WITH_DES_CBC_SHA); 250 // 251 // static final CipherSuite SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA = new CipherSuite( 252 // "SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA", false, KEY_EXCHANGE_DH_RSA, 253 // "DH", "3DES_EDE_CBC", "SHA", CODE_SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA); 254 // END android-removed 255 256 static final CipherSuite SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA = new CipherSuite( 257 "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA", true, 258 KEY_EXCHANGE_DHE_DSS_EXPORT, "DSA", "DES40_CBC", "SHA", 259 CODE_SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA); 260 261 static final CipherSuite SSL_DHE_DSS_WITH_DES_CBC_SHA = new CipherSuite( 262 "SSL_DHE_DSS_WITH_DES_CBC_SHA", false, KEY_EXCHANGE_DHE_DSS, 263 "DSA", "DES_CBC", "SHA", CODE_SSL_DHE_DSS_WITH_DES_CBC_SHA); 264 265 static final CipherSuite SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA = new CipherSuite( 266 "SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA", false, KEY_EXCHANGE_DHE_DSS, 267 "DSA", "3DES_EDE_CBC", "SHA", CODE_SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA); 268 269 static final CipherSuite SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA = new CipherSuite( 270 "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", true, 271 KEY_EXCHANGE_DHE_RSA_EXPORT, "RSA", "DES40_CBC", "SHA", 272 CODE_SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA); 273 274 static final CipherSuite SSL_DHE_RSA_WITH_DES_CBC_SHA = new CipherSuite( 275 "SSL_DHE_RSA_WITH_DES_CBC_SHA", false, KEY_EXCHANGE_DHE_RSA, 276 "RSA", "DES_CBC", "SHA", CODE_SSL_DHE_RSA_WITH_DES_CBC_SHA); 277 278 static final CipherSuite SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA = new CipherSuite( 279 "SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA", false, KEY_EXCHANGE_DHE_RSA, 280 "RSA", "3DES_EDE_CBC", "SHA", CODE_SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA); 281 282 static final CipherSuite SSL_DH_anon_EXPORT_WITH_RC4_40_MD5 = new CipherSuite( 283 "SSL_DH_anon_EXPORT_WITH_RC4_40_MD5", true, 284 KEY_EXCHANGE_DH_anon_EXPORT, "DH", "RC4_40", "MD5", 285 CODE_SSL_DH_anon_EXPORT_WITH_RC4_40_MD5); 286 287 static final CipherSuite SSL_DH_anon_WITH_RC4_128_MD5 = new CipherSuite( 288 "SSL_DH_anon_WITH_RC4_128_MD5", false, KEY_EXCHANGE_DH_anon, 289 "DH", "RC4_128", "MD5", CODE_SSL_DH_anon_WITH_RC4_128_MD5); 290 291 static final CipherSuite SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA = new CipherSuite( 292 "SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA", true, 293 KEY_EXCHANGE_DH_anon_EXPORT, "DH", "DES40_CBC", "SHA", 294 CODE_SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA); 295 296 static final CipherSuite SSL_DH_anon_WITH_DES_CBC_SHA = new CipherSuite( 297 "SSL_DH_anon_WITH_DES_CBC_SHA", false, KEY_EXCHANGE_DH_anon, 298 "DH", "DES_CBC", "SHA", CODE_SSL_DH_anon_WITH_DES_CBC_SHA); 299 300 static final CipherSuite SSL_DH_anon_WITH_3DES_EDE_CBC_SHA = new CipherSuite( 301 "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA", false, KEY_EXCHANGE_DH_anon, 302 "DH", "3DES_EDE_CBC", "SHA", CODE_SSL_DH_anon_WITH_3DES_EDE_CBC_SHA); 303 304 static final CipherSuite TLS_RSA_WITH_AES_128_CBC_SHA 305 = new CipherSuite("TLS_RSA_WITH_AES_128_CBC_SHA", 306 false, 307 KEY_EXCHANGE_RSA, 308 "RSA", 309 "AES_128_CBC", 310 "SHA", 311 CODE_TLS_RSA_WITH_AES_128_CBC_SHA); 312 static final CipherSuite TLS_DHE_DSS_WITH_AES_128_CBC_SHA 313 = new CipherSuite("TLS_DHE_DSS_WITH_AES_128_CBC_SHA", 314 false, 315 KEY_EXCHANGE_DHE_DSS, 316 "DSA", 317 "AES_128_CBC", 318 "SHA", 319 CODE_TLS_DHE_DSS_WITH_AES_128_CBC_SHA); 320 static final CipherSuite TLS_DHE_RSA_WITH_AES_128_CBC_SHA 321 = new CipherSuite("TLS_DHE_RSA_WITH_AES_128_CBC_SHA", 322 false, 323 KEY_EXCHANGE_DHE_RSA, 324 "RSA", 325 "AES_128_CBC", 326 "SHA", 327 CODE_TLS_DHE_RSA_WITH_AES_128_CBC_SHA); 328 static final CipherSuite TLS_DH_anon_WITH_AES_128_CBC_SHA 329 = new CipherSuite("TLS_DH_anon_WITH_AES_128_CBC_SHA", 330 false, 331 KEY_EXCHANGE_DH_anon, 332 "DH", 333 "AES_128_CBC", 334 "SHA", 335 CODE_TLS_DH_anon_WITH_AES_128_CBC_SHA); 336 static final CipherSuite TLS_RSA_WITH_AES_256_CBC_SHA 337 = new CipherSuite("TLS_RSA_WITH_AES_256_CBC_SHA", 338 false, 339 KEY_EXCHANGE_RSA, 340 "RSA", 341 "AES_256_CBC", 342 "SHA", 343 CODE_TLS_RSA_WITH_AES_256_CBC_SHA); 344 static final CipherSuite TLS_DHE_DSS_WITH_AES_256_CBC_SHA 345 = new CipherSuite("TLS_DHE_DSS_WITH_AES_256_CBC_SHA", 346 false, 347 KEY_EXCHANGE_DHE_DSS, 348 "DSA", 349 "AES_256_CBC", 350 "SHA", 351 CODE_TLS_DHE_DSS_WITH_AES_256_CBC_SHA); 352 static final CipherSuite TLS_DHE_RSA_WITH_AES_256_CBC_SHA 353 = new CipherSuite("TLS_DHE_RSA_WITH_AES_256_CBC_SHA", 354 false, 355 KEY_EXCHANGE_DHE_RSA, 356 "RSA", 357 "AES_256_CBC", 358 "SHA", 359 CODE_TLS_DHE_RSA_WITH_AES_256_CBC_SHA); 360 static final CipherSuite TLS_DH_anon_WITH_AES_256_CBC_SHA 361 = new CipherSuite("TLS_DH_anon_WITH_AES_256_CBC_SHA", 362 false, 363 KEY_EXCHANGE_DH_anon, 364 "DH", 365 "AES_256_CBC", 366 "SHA", 367 CODE_TLS_DH_anon_WITH_AES_256_CBC_SHA); 368 369 static final CipherSuite TLS_ECDH_ECDSA_WITH_NULL_SHA 370 = new CipherSuite("TLS_ECDH_ECDSA_WITH_NULL_SHA", 371 false, 372 KEY_EXCHANGE_ECDH_ECDSA, 373 "EC", 374 null, 375 "SHA", 376 CODE_TLS_ECDH_ECDSA_WITH_NULL_SHA); 377 static final CipherSuite TLS_ECDH_ECDSA_WITH_RC4_128_SHA 378 = new CipherSuite("TLS_ECDH_ECDSA_WITH_RC4_128_SHA", 379 false, 380 KEY_EXCHANGE_ECDH_ECDSA, 381 "EC", 382 "RC4_128", 383 "SHA", 384 CODE_TLS_ECDH_ECDSA_WITH_RC4_128_SHA); 385 static final CipherSuite TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA 386 = new CipherSuite("TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA", 387 false, 388 KEY_EXCHANGE_ECDH_ECDSA, 389 "EC", 390 "3DES_EDE_CBC", 391 "SHA", 392 CODE_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA); 393 static final CipherSuite TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA 394 = new CipherSuite("TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA", 395 false, 396 KEY_EXCHANGE_ECDH_ECDSA, 397 "EC", 398 "AES_128_CBC", 399 "SHA", 400 CODE_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA); 401 static final CipherSuite TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA 402 = new CipherSuite("TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA", 403 false, 404 KEY_EXCHANGE_ECDH_ECDSA, 405 "EC", 406 "AES_256_CBC", 407 "SHA", 408 CODE_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA); 409 static final CipherSuite TLS_ECDHE_ECDSA_WITH_NULL_SHA 410 = new CipherSuite("TLS_ECDHE_ECDSA_WITH_NULL_SHA", 411 false, 412 KEY_EXCHANGE_ECDHE_ECDSA, 413 "EC", 414 null, 415 "SHA", 416 CODE_TLS_ECDHE_ECDSA_WITH_NULL_SHA); 417 static final CipherSuite TLS_ECDHE_ECDSA_WITH_RC4_128_SHA 418 = new CipherSuite("TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", 419 false, 420 KEY_EXCHANGE_ECDHE_ECDSA, 421 "EC", 422 "RC4_128", 423 "SHA", 424 CODE_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA); 425 static final CipherSuite TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA 426 = new CipherSuite("TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA", 427 false, 428 KEY_EXCHANGE_ECDHE_ECDSA, 429 "EC", 430 "3DES_EDE_CBC", 431 "SHA", 432 CODE_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA); 433 static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 434 = new CipherSuite("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", 435 false, 436 KEY_EXCHANGE_ECDHE_ECDSA, 437 "EC", 438 "AES_128_CBC", 439 "SHA", 440 CODE_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA); 441 static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 442 = new CipherSuite("TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", 443 false, 444 KEY_EXCHANGE_ECDHE_ECDSA, 445 "EC", 446 "AES_256_CBC", 447 "SHA", 448 CODE_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA); 449 static final CipherSuite TLS_ECDH_RSA_WITH_NULL_SHA 450 = new CipherSuite("TLS_ECDH_RSA_WITH_NULL_SHA", 451 false, 452 KEY_EXCHANGE_ECDH_RSA, 453 "EC", 454 null, 455 "SHA", 456 CODE_TLS_ECDH_RSA_WITH_NULL_SHA); 457 static final CipherSuite TLS_ECDH_RSA_WITH_RC4_128_SHA 458 = new CipherSuite("TLS_ECDH_RSA_WITH_RC4_128_SHA", 459 false, 460 KEY_EXCHANGE_ECDH_RSA, 461 "EC", 462 "RC4_128", 463 "SHA", 464 CODE_TLS_ECDH_RSA_WITH_RC4_128_SHA); 465 static final CipherSuite TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA 466 = new CipherSuite("TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA", 467 false, 468 KEY_EXCHANGE_ECDH_RSA, 469 "EC", 470 "3DES_EDE_CBC", 471 "SHA", 472 CODE_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA); 473 static final CipherSuite TLS_ECDH_RSA_WITH_AES_128_CBC_SHA 474 = new CipherSuite("TLS_ECDH_RSA_WITH_AES_128_CBC_SHA", 475 false, 476 KEY_EXCHANGE_ECDH_RSA, 477 "EC", 478 "AES_128_CBC", 479 "SHA", 480 CODE_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA); 481 static final CipherSuite TLS_ECDH_RSA_WITH_AES_256_CBC_SHA 482 = new CipherSuite("TLS_ECDH_RSA_WITH_AES_256_CBC_SHA", 483 false, 484 KEY_EXCHANGE_ECDH_RSA, 485 "EC", 486 "AES_256_CBC", 487 "SHA", 488 CODE_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA); 489 static final CipherSuite TLS_ECDHE_RSA_WITH_NULL_SHA 490 = new CipherSuite("TLS_ECDHE_RSA_WITH_NULL_SHA", 491 false, 492 KEY_EXCHANGE_ECDHE_RSA, 493 "EC", 494 null, 495 "SHA", 496 CODE_TLS_ECDHE_RSA_WITH_NULL_SHA); 497 static final CipherSuite TLS_ECDHE_RSA_WITH_RC4_128_SHA 498 = new CipherSuite("TLS_ECDHE_RSA_WITH_RC4_128_SHA", 499 false, 500 KEY_EXCHANGE_ECDHE_RSA, 501 "EC", 502 "RC4_128", 503 "SHA", 504 CODE_TLS_ECDHE_RSA_WITH_RC4_128_SHA); 505 static final CipherSuite TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA 506 = new CipherSuite("TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", 507 false, 508 KEY_EXCHANGE_ECDHE_RSA, 509 "EC", 510 "3DES_EDE_CBC", 511 "SHA", 512 CODE_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA); 513 static final CipherSuite TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA 514 = new CipherSuite("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", 515 false, 516 KEY_EXCHANGE_ECDHE_RSA, 517 "EC", 518 "AES_128_CBC", 519 "SHA", 520 CODE_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA); 521 static final CipherSuite TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 522 = new CipherSuite("TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", 523 false, 524 KEY_EXCHANGE_ECDHE_RSA, 525 "EC", 526 "AES_256_CBC", 527 "SHA", 528 CODE_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA); 529 static final CipherSuite TLS_ECDH_anon_WITH_NULL_SHA 530 = new CipherSuite("TLS_ECDH_anon_WITH_NULL_SHA", 531 false, 532 KEY_EXCHANGE_ECDH_anon, 533 "EC", 534 null, 535 "SHA", 536 CODE_TLS_ECDH_anon_WITH_NULL_SHA); 537 static final CipherSuite TLS_ECDH_anon_WITH_RC4_128_SHA 538 = new CipherSuite("TLS_ECDH_anon_WITH_RC4_128_SHA", 539 false, 540 KEY_EXCHANGE_ECDH_anon, 541 "EC", 542 "RC4_128", 543 "SHA", 544 CODE_TLS_ECDH_anon_WITH_RC4_128_SHA); 545 static final CipherSuite TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA 546 = new CipherSuite("TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA", 547 false, 548 KEY_EXCHANGE_ECDH_anon, 549 "EC", 550 "3DES_EDE_CBC", 551 "SHA", 552 CODE_TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA); 553 static final CipherSuite TLS_ECDH_anon_WITH_AES_128_CBC_SHA 554 = new CipherSuite("TLS_ECDH_anon_WITH_AES_128_CBC_SHA", 555 false, 556 KEY_EXCHANGE_ECDH_anon, 557 "EC", 558 "AES_128_CBC", 559 "SHA", 560 CODE_TLS_ECDH_anon_WITH_AES_128_CBC_SHA); 561 static final CipherSuite TLS_ECDH_anon_WITH_AES_256_CBC_SHA 562 = new CipherSuite("TLS_ECDH_anon_WITH_AES_256_CBC_SHA", 563 false, 564 KEY_EXCHANGE_ECDH_anon, 565 "EC", 566 "AES_256_CBC", 567 "SHA", 568 CODE_TLS_ECDH_anon_WITH_AES_256_CBC_SHA); 569 570 // arrays for quick access to cipher suite by code 571 private static final CipherSuite[] SUITES_BY_CODE_0x00 = { 572 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml 573 SSL_NULL_WITH_NULL_NULL, // { 0x00, 0x00 }; 574 SSL_RSA_WITH_NULL_MD5, // { 0x00, 0x01 }; 575 SSL_RSA_WITH_NULL_SHA, // { 0x00, 0x02 }; 576 SSL_RSA_EXPORT_WITH_RC4_40_MD5, // { 0x00, 0x03 }; 577 SSL_RSA_WITH_RC4_128_MD5, // { 0x00, 0x04 }; 578 SSL_RSA_WITH_RC4_128_SHA, // { 0x00, 0x05 }; 579 // BEGIN android-changed 580 null, // SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5, // { 0x00, 0x06 }; 581 null, // TLS_RSA_WITH_IDEA_CBC_SHA, // { 0x00, 0x07 }; 582 // END android-changed 583 SSL_RSA_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x08 }; 584 SSL_RSA_WITH_DES_CBC_SHA, // { 0x00, 0x09 }; 585 SSL_RSA_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x0a }; 586 // BEGIN android-changed 587 null, // SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA // { 0x00, 0x0b }; 588 null, // SSL_DH_DSS_WITH_DES_CBC_SHA, // { 0x00, 0x0c }; 589 null, // SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x0d }; 590 null, // SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x0e }; 591 null, // SSL_DH_RSA_WITH_DES_CBC_SHA, // { 0x00, 0x0f }; 592 null, // SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x10 }; 593 // END android-changed 594 SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x11 }; 595 SSL_DHE_DSS_WITH_DES_CBC_SHA, // { 0x00, 0x12 }; 596 SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x13 }; 597 SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x14 }; 598 SSL_DHE_RSA_WITH_DES_CBC_SHA, // { 0x00, 0x15 }; 599 SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x16 }; 600 SSL_DH_anon_EXPORT_WITH_RC4_40_MD5, // { 0x00, 0x17 }; 601 SSL_DH_anon_WITH_RC4_128_MD5, // { 0x00, 0x18 }; 602 SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x19 }; 603 SSL_DH_anon_WITH_DES_CBC_SHA, // { 0x00, 0x1A }; 604 SSL_DH_anon_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x1B }; 605 // BEGIN android-added 606 null, // SSL_FORTEZZA_KEA_WITH_NULL_SHA // { 0x00, 0x1C }; 607 null, // SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA // { 0x00, 0x1D }; 608 null, // TLS_KRB5_WITH_DES_CBC_SHA // { 0x00, 0x1E }; 609 null, // TLS_KRB5_WITH_3DES_EDE_CBC_SHA // { 0x00, 0x1F }; 610 null, // TLS_KRB5_WITH_RC4_128_SHA // { 0x00, 0x20 }; 611 null, // TLS_KRB5_WITH_IDEA_CBC_SHA // { 0x00, 0x21 }; 612 null, // TLS_KRB5_WITH_DES_CBC_MD5 // { 0x00, 0x22 }; 613 null, // TLS_KRB5_WITH_3DES_EDE_CBC_MD5 // { 0x00, 0x23 }; 614 null, // TLS_KRB5_WITH_RC4_128_MD5 // { 0x00, 0x24 }; 615 null, // TLS_KRB5_WITH_IDEA_CBC_MD5 // { 0x00, 0x25 }; 616 null, // TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA // { 0x00, 0x26 }; 617 null, // TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA // { 0x00, 0x27 }; 618 null, // TLS_KRB5_EXPORT_WITH_RC4_40_SHA // { 0x00, 0x28 }; 619 null, // TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5 // { 0x00, 0x29 }; 620 null, // TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5 // { 0x00, 0x2A }; 621 null, // TLS_KRB5_EXPORT_WITH_RC4_40_MD5 // { 0x00, 0x2B }; 622 null, // TLS_PSK_WITH_NULL_SHA // { 0x00, 0x2C }; 623 null, // TLS_DHE_PSK_WITH_NULL_SHA // { 0x00, 0x2D }; 624 null, // TLS_RSA_PSK_WITH_NULL_SHA // { 0x00, 0x2E }; 625 TLS_RSA_WITH_AES_128_CBC_SHA, // { 0x00, 0x2F }; 626 null, // TLS_DH_DSS_WITH_AES_128_CBC_SHA // { 0x00, 0x30 }; 627 null, // TLS_DH_RSA_WITH_AES_128_CBC_SHA // { 0x00, 0x31 }; 628 TLS_DHE_DSS_WITH_AES_128_CBC_SHA, // { 0x00, 0x32 }; 629 TLS_DHE_RSA_WITH_AES_128_CBC_SHA, // { 0x00, 0x33 }; 630 TLS_DH_anon_WITH_AES_128_CBC_SHA, // { 0x00, 0x34 }; 631 TLS_RSA_WITH_AES_256_CBC_SHA, // { 0x00, 0x35 }; 632 null, // TLS_DH_DSS_WITH_AES_256_CBC_SHA, // { 0x00, 0x36 }; 633 null, // TLS_DH_RSA_WITH_AES_256_CBC_SHA, // { 0x00, 0x37 }; 634 TLS_DHE_DSS_WITH_AES_256_CBC_SHA, // { 0x00, 0x38 }; 635 TLS_DHE_RSA_WITH_AES_256_CBC_SHA, // { 0x00, 0x39 }; 636 TLS_DH_anon_WITH_AES_256_CBC_SHA, // { 0x00, 0x3A }; 637 // END android-added 638 }; 639 private static final CipherSuite[] SUITES_BY_CODE_0xc0 = { 640 null, // { 0xc0, 0x00}; 641 TLS_ECDH_ECDSA_WITH_NULL_SHA, // { 0xc0, 0x01}; 642 TLS_ECDH_ECDSA_WITH_RC4_128_SHA, // { 0xc0, 0x02}; 643 TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x03}; 644 TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, // { 0xc0, 0x04}; 645 TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, // { 0xc0, 0x05}; 646 TLS_ECDHE_ECDSA_WITH_NULL_SHA, // { 0xc0, 0x06}; 647 TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, // { 0xc0, 0x07}; 648 TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x08}; 649 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, // { 0xc0, 0x09}; 650 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, // { 0xc0, 0x0A}; 651 TLS_ECDH_RSA_WITH_NULL_SHA, // { 0xc0, 0x0B}; 652 TLS_ECDH_RSA_WITH_RC4_128_SHA, // { 0xc0, 0x0C}; 653 TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x0D}; 654 TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, // { 0xc0, 0x0E}; 655 TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, // { 0xc0, 0x0F}; 656 TLS_ECDHE_RSA_WITH_NULL_SHA, // { 0xc0, 0x10}; 657 TLS_ECDHE_RSA_WITH_RC4_128_SHA, // { 0xc0, 0x11}; 658 TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x12}; 659 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, // { 0xc0, 0x13}; 660 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, // { 0xc0, 0x14}; 661 TLS_ECDH_anon_WITH_NULL_SHA, // { 0xc0, 0x15}; 662 TLS_ECDH_anon_WITH_RC4_128_SHA, // { 0xc0, 0x16}; 663 TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x17}; 664 TLS_ECDH_anon_WITH_AES_128_CBC_SHA, // { 0xc0, 0x18}; 665 TLS_ECDH_anon_WITH_AES_256_CBC_SHA, // { 0xc0, 0x19}; 666 // TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x1A}; 667 // TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x1B}; 668 // TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x1C}; 669 // TLS_SRP_SHA_WITH_AES_128_CBC_SHA, // { 0xc0, 0x1D}; 670 // TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA, // { 0xc0, 0x1E}; 671 // TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA, // { 0xc0, 0x1F}; 672 // TLS_SRP_SHA_WITH_AES_256_CBC_SHA, // { 0xc0, 0x20}; 673 // TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA, // { 0xc0, 0x21}; 674 // TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA, // { 0xc0, 0x22}; 675 // TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, // { 0xc0, 0x23}; 676 // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, // { 0xc0, 0x24}; 677 // TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, // { 0xc0, 0x25}; 678 // TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, // { 0xc0, 0x26}; 679 // TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, // { 0xc0, 0x27}; 680 // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, // { 0xc0, 0x28}; 681 // TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, // { 0xc0, 0x29}; 682 // TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, // { 0xc0, 0x2A}; 683 // TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, // { 0xc0, 0x2B}; 684 // TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, // { 0xc0, 0x2C}; 685 // TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, // { 0xc0, 0x2D}; 686 // TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, // { 0xc0, 0x2E}; 687 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, // { 0xc0, 0x2F}; 688 // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, // { 0xc0, 0x30}; 689 // TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, // { 0xc0, 0x31}; 690 // TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, // { 0xc0, 0x32}; 691 // TLS_ECDHE_PSK_WITH_RC4_128_SHA, // { 0xc0, 0x33}; 692 // TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x34}; 693 // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, // { 0xc0, 0x35}; 694 // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA, // { 0xc0, 0x36}; 695 // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256, // { 0xc0, 0x37}; 696 // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384, // { 0xc0, 0x38}; 697 // TLS_ECDHE_PSK_WITH_NULL_SHA, // { 0xc0, 0x39}; 698 // TLS_ECDHE_PSK_WITH_NULL_SHA256, // { 0xc0, 0x3A}; 699 // TLS_ECDHE_PSK_WITH_NULL_SHA384, // { 0xc0, 0x3B}; 700 }; 701 702 // hash for quick access to cipher suite by name 703 private static final Hashtable<String, CipherSuite> SUITES_BY_NAME; 704 705 /** 706 * array of supported cipher suites. 707 * Set of supported suites is defined at the moment provider's start 708 */ 709 // TODO Dynamically supported suites: new providers may be dynamically 710 // added/removed and the set of supported suites may be changed 711 static final CipherSuite[] SUPPORTED_CIPHER_SUITES; 712 713 /** 714 * array of supported cipher suites names 715 */ 716 static final String[] SUPPORTED_CIPHER_SUITE_NAMES; 717 718 /** 719 * default cipher suites 720 */ 721 static final CipherSuite[] DEFAULT_CIPHER_SUITES; 722 723 static { 724 SUITES_BY_NAME = new Hashtable<String, CipherSuite>(); 725 int count_0x00 = registerCipherSuitesByCode(SUITES_BY_CODE_0x00); 726 int count_0xc0 = registerCipherSuitesByCode(SUITES_BY_CODE_0xc0); 727 int count = count_0x00 + count_0xc0; 728 SUPPORTED_CIPHER_SUITES = new CipherSuite[count]; 729 SUPPORTED_CIPHER_SUITE_NAMES = new String[count]; 730 registerSupportedCipherSuites(0, SUITES_BY_CODE_0x00); 731 registerSupportedCipherSuites(count_0x00, SUITES_BY_CODE_0xc0); 732 733 CipherSuite[] defaultCipherSuites = { 734 SSL_RSA_WITH_RC4_128_MD5, 735 SSL_RSA_WITH_RC4_128_SHA, 736 TLS_RSA_WITH_AES_128_CBC_SHA, 737 TLS_DHE_RSA_WITH_AES_128_CBC_SHA, 738 TLS_DHE_DSS_WITH_AES_128_CBC_SHA, 739 SSL_RSA_WITH_3DES_EDE_CBC_SHA, 740 SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, 741 SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, 742 SSL_RSA_WITH_DES_CBC_SHA, 743 SSL_DHE_RSA_WITH_DES_CBC_SHA, 744 SSL_DHE_DSS_WITH_DES_CBC_SHA, 745 SSL_RSA_EXPORT_WITH_RC4_40_MD5, 746 SSL_RSA_EXPORT_WITH_DES40_CBC_SHA, 747 SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA, 748 SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA 749 }; 750 count = 0; 751 for (int i = 0; i < defaultCipherSuites.length; i++) { 752 if (defaultCipherSuites[i].supported) { 753 count++; 754 } 755 } 756 DEFAULT_CIPHER_SUITES = new CipherSuite[count]; 757 count = 0; 758 for (int i = 0; i < defaultCipherSuites.length; i++) { 759 if (defaultCipherSuites[i].supported) { 760 DEFAULT_CIPHER_SUITES[count++] = defaultCipherSuites[i]; 761 } 762 } 763 } 764 private static int registerCipherSuitesByCode(CipherSuite[] cipherSuites) { 765 int count = 0; 766 for (int i = 0; i < cipherSuites.length; i++) { 767 if (cipherSuites[i] == SSL_NULL_WITH_NULL_NULL) { 768 continue; 769 } 770 if (cipherSuites[i] == null) { 771 continue; 772 } 773 SUITES_BY_NAME.put(cipherSuites[i].getName(), cipherSuites[i]); 774 if (cipherSuites[i].supported) { 775 count++; 776 } 777 } 778 return count; 779 } 780 private static void registerSupportedCipherSuites(int offset, CipherSuite[] cipherSuites) { 781 int count = offset; 782 for (int i = 0; i < cipherSuites.length; i++) { 783 if (cipherSuites[i] == SSL_NULL_WITH_NULL_NULL) { 784 continue; 785 } 786 if (cipherSuites[i] == null) { 787 continue; 788 } 789 if (cipherSuites[i].supported) { 790 SUPPORTED_CIPHER_SUITES[count] = cipherSuites[i]; 791 SUPPORTED_CIPHER_SUITE_NAMES[count] = SUPPORTED_CIPHER_SUITES[count].getName(); 792 count++; 793 } 794 } 795 } 796 797 /** 798 * Returns CipherSuite by name 799 */ 800 public static CipherSuite getByName(String name) { 801 return SUITES_BY_NAME.get(name); 802 } 803 804 /** 805 * Returns CipherSuite based on TLS CipherSuite code 806 * @see <a href="http://www.ietf.org/rfc/rfc2246.txt">TLS 1.0 spec., A.5. The CipherSuite</a> 807 */ 808 public static CipherSuite getByCode(byte b1, byte b2) { 809 int i1 = b1 & 0xff; 810 int i2 = b2 & 0xff; 811 CipherSuite cs = getCipherSuiteByCode(0, i1, i2); 812 if (cs != null) { 813 return cs; 814 } 815 return new CipherSuite("UNKNOWN_" + i1 + "_" + i2, false, 0, null, 816 null, null, new byte[] { b1, b2 }); 817 } 818 819 /** 820 * Returns CipherSuite based on V2CipherSpec code 821 * as described in TLS 1.0 spec., E. Backward Compatibility With SSL 822 */ 823 public static CipherSuite getByCode(byte b1, byte b2, byte b3) { 824 int i1 = b1 & 0xff; 825 int i2 = b2 & 0xff; 826 int i3 = b3 & 0xff; 827 CipherSuite cs = getCipherSuiteByCode(i1, i2, i3); 828 if (cs != null) { 829 return cs; 830 } 831 return new CipherSuite("UNKNOWN_" + i1 + "_" + i2 + "_" + i3, false, 0, 832 null, null, null, new byte[] { b1, b2, b3 }); 833 } 834 835 private static CipherSuite getCipherSuiteByCode(int i1, int i2, int i3) { 836 CipherSuite[] cipherSuites; 837 if (i1 == 0x00 && i2 == 0x00) { 838 cipherSuites = SUITES_BY_CODE_0x00; 839 } else if (i1 == 0x00 && i2 == 0xc0) { 840 cipherSuites = SUITES_BY_CODE_0xc0; 841 } else { 842 return null; 843 } 844 if (i3 >= cipherSuites.length) { 845 return null; 846 } 847 return cipherSuites[i3]; 848 } 849 850 /** 851 * Creates CipherSuite 852 */ 853 private CipherSuite(String name, boolean isExportable, int keyExchange, 854 String authType, String cipherName, String hash, byte[] code) { 855 this.name = name; 856 this.keyExchange = keyExchange; 857 this.authType = authType; 858 this.isExportable = isExportable; 859 if (cipherName == null) { 860 this.cipherName = null; 861 keyMaterial = 0; 862 expandedKeyMaterial = 0; 863 effectiveKeyBytes = 0; 864 ivSize = 0; 865 blockSize = 0; 866 // BEGIN android-removed 867 // } else if ("IDEA_CBC".equals(cipherName)) { 868 // this.cipherName = "IDEA/CBC/NoPadding"; 869 // keyMaterial = 16; 870 // expandedKeyMaterial = 16; 871 // effectiveKeyBytes = 16; 872 // ivSize = 8; 873 // blockSize = 8; 874 // } else if ("RC2_CBC_40".equals(cipherName)) { 875 // this.cipherName = "RC2/CBC/NoPadding"; 876 // keyMaterial = 5; 877 // expandedKeyMaterial = 16; 878 // effectiveKeyBytes = 5; 879 // ivSize = 8; 880 // blockSize = 8; 881 // END android-removed 882 } else if ("RC4_40".equals(cipherName)) { 883 this.cipherName = "RC4"; 884 keyMaterial = 5; 885 expandedKeyMaterial = 16; 886 effectiveKeyBytes = 5; 887 ivSize = 0; 888 blockSize = 0; 889 } else if ("RC4_128".equals(cipherName)) { 890 this.cipherName = "RC4"; 891 keyMaterial = 16; 892 expandedKeyMaterial = 16; 893 effectiveKeyBytes = 16; 894 ivSize = 0; 895 blockSize = 0; 896 } else if ("DES40_CBC".equals(cipherName)) { 897 this.cipherName = "DES/CBC/NoPadding"; 898 keyMaterial = 5; 899 expandedKeyMaterial = 8; 900 effectiveKeyBytes = 5; 901 ivSize = 8; 902 blockSize = 8; 903 } else if ("DES_CBC".equals(cipherName)) { 904 this.cipherName = "DES/CBC/NoPadding"; 905 keyMaterial = 8; 906 expandedKeyMaterial = 8; 907 effectiveKeyBytes = 7; 908 ivSize = 8; 909 blockSize = 8; 910 } else if ("3DES_EDE_CBC".equals(cipherName)) { 911 this.cipherName = "DESede/CBC/NoPadding"; 912 keyMaterial = 24; 913 expandedKeyMaterial = 24; 914 effectiveKeyBytes = 24; 915 ivSize = 8; 916 blockSize = 8; 917 } else if ("AES_128_CBC".equals(cipherName)) { 918 this.cipherName = "AES/CBC/NoPadding"; 919 keyMaterial = 16; 920 expandedKeyMaterial = 16; 921 effectiveKeyBytes = 16; 922 ivSize = 16; 923 blockSize = 16; 924 } else if ("AES_256_CBC".equals(cipherName)) { 925 this.cipherName = "AES/CBC/NoPadding"; 926 keyMaterial = 32; 927 expandedKeyMaterial = 32; 928 effectiveKeyBytes = 32; 929 ivSize = 16; 930 blockSize = 16; 931 } else { 932 this.cipherName = cipherName; 933 keyMaterial = 0; 934 expandedKeyMaterial = 0; 935 effectiveKeyBytes = 0; 936 ivSize = 0; 937 blockSize = 0; 938 } 939 940 if ("MD5".equals(hash)) { 941 this.hmacName = "HmacMD5"; 942 this.hashName = "MD5"; 943 hashSize = 16; 944 } else if ("SHA".equals(hash)) { 945 this.hmacName = "HmacSHA1"; 946 this.hashName = "SHA-1"; 947 hashSize = 20; 948 } else { 949 this.hmacName = null; 950 this.hashName = null; 951 hashSize = 0; 952 } 953 954 cipherSuiteCode = code; 955 956 if (this.cipherName != null) { 957 try { 958 Cipher.getInstance(this.cipherName); 959 } catch (GeneralSecurityException e) { 960 supported = false; 961 } 962 } 963 964 // We define the Elliptic Curve cipher suites for use with 965 // code shared by OpenSSL, but they are not supported by 966 // SSLEngine or SSLSocket's built with SSLEngine. 967 if (this.name.startsWith("TLS_EC")) { 968 supported = false; 969 } 970 } 971 972 /** 973 * Returns true if cipher suite is anonymous 974 */ 975 public boolean isAnonymous() { 976 if (keyExchange == KEY_EXCHANGE_DH_anon 977 || keyExchange == KEY_EXCHANGE_DH_anon_EXPORT 978 || keyExchange == KEY_EXCHANGE_ECDH_anon) { 979 return true; 980 } 981 return false; 982 } 983 984 /** 985 * Returns array of supported CipherSuites 986 */ 987 public static CipherSuite[] getSupported() { 988 return SUPPORTED_CIPHER_SUITES; 989 } 990 991 /** 992 * Returns array of supported cipher suites names 993 */ 994 public static String[] getSupportedCipherSuiteNames() { 995 return SUPPORTED_CIPHER_SUITE_NAMES.clone(); 996 } 997 998 /** 999 * Returns cipher suite name 1000 */ 1001 public String getName() { 1002 return name; 1003 } 1004 1005 /** 1006 * Returns cipher suite code as byte array 1007 */ 1008 public byte[] toBytes() { 1009 return cipherSuiteCode; 1010 } 1011 1012 /** 1013 * Returns cipher suite description 1014 */ 1015 @Override 1016 public String toString() { 1017 return name + ": " + cipherSuiteCode[0] + " " + cipherSuiteCode[1]; 1018 } 1019 1020 /** 1021 * Returns cipher algorithm name 1022 */ 1023 public String getBulkEncryptionAlgorithm() { 1024 return cipherName; 1025 } 1026 1027 /** 1028 * Returns cipher block size 1029 */ 1030 public int getBlockSize() { 1031 return blockSize; 1032 } 1033 1034 /** 1035 * Returns MAC algorithm name 1036 */ 1037 public String getHmacName() { 1038 return hmacName; 1039 } 1040 1041 /** 1042 * Returns hash algorithm name 1043 */ 1044 public String getHashName() { 1045 return hashName; 1046 } 1047 1048 /** 1049 * Returns hash size 1050 */ 1051 public int getMACLength() { 1052 return hashSize; 1053 } 1054 1055 /** 1056 * Indicates whether this cipher suite is exportable 1057 */ 1058 public boolean isExportable() { 1059 return isExportable; 1060 } 1061 1062 static final String KEY_TYPE_RSA = "RSA"; 1063 static final String KEY_TYPE_DSA = "DSA"; 1064 static final String KEY_TYPE_DH_RSA = "DH_RSA"; 1065 static final String KEY_TYPE_DH_DSA = "DH_DSA"; 1066 static final String KEY_TYPE_EC = "EC"; 1067 static final String KEY_TYPE_EC_EC = "EC_EC"; 1068 static final String KEY_TYPE_EC_RSA = "EC_RSA"; 1069 1070 /** 1071 * Returns key type constant suitable for calling 1072 * X509KeyManager.chooseServerAlias or 1073 * X509ExtendedKeyManager.chooseEngineServerAlias. 1074 */ 1075 public String getServerKeyType() { 1076 switch (keyExchange) { 1077 case KEY_EXCHANGE_DHE_RSA: 1078 case KEY_EXCHANGE_DHE_RSA_EXPORT: 1079 case KEY_EXCHANGE_ECDHE_RSA: 1080 case KEY_EXCHANGE_RSA: 1081 case KEY_EXCHANGE_RSA_EXPORT: 1082 return KEY_TYPE_RSA; 1083 case KEY_EXCHANGE_DHE_DSS: 1084 case KEY_EXCHANGE_DHE_DSS_EXPORT: 1085 return KEY_TYPE_DSA; 1086 case KEY_EXCHANGE_ECDH_ECDSA: 1087 case KEY_EXCHANGE_ECDHE_ECDSA: 1088 return KEY_TYPE_EC_EC; 1089 case KEY_EXCHANGE_ECDH_RSA: 1090 return KEY_TYPE_EC_RSA; 1091 case KEY_EXCHANGE_DH_anon: 1092 case KEY_EXCHANGE_DH_anon_EXPORT: 1093 case KEY_EXCHANGE_ECDH_anon: 1094 return null; 1095 default: 1096 throw new IllegalStateException("Unknown key type for key exchange " + keyExchange); 1097 } 1098 } 1099 1100 /** 1101 * Client certificate types as defined in 1102 * TLS 1.0 spec., 7.4.4. Certificate request. 1103 * EC constants from RFC 4492. 1104 * Names match openssl constants. 1105 */ 1106 static final byte TLS_CT_RSA_SIGN = 1; 1107 static final byte TLS_CT_DSS_SIGN = 2; 1108 static final byte TLS_CT_RSA_FIXED_DH = 3; 1109 static final byte TLS_CT_DSS_FIXED_DH = 4; 1110 static final byte TLS_CT_ECDSA_SIGN = 64; 1111 static final byte TLS_CT_RSA_FIXED_ECDH = 65; 1112 static final byte TLS_CT_ECDSA_FIXED_ECDH = 66; 1113 1114 /** 1115 * Similar to getServerKeyType, but returns value given TLS 1116 * ClientCertificateType byte values from a CertificateRequest 1117 * message for use with X509KeyManager.chooseClientAlias or 1118 * X509ExtendedKeyManager.chooseEngineClientAlias. 1119 */ 1120 public static String getClientKeyType(byte keyType) { 1121 // See also http://www.ietf.org/assignments/tls-parameters/tls-parameters.xml 1122 switch (keyType) { 1123 case TLS_CT_RSA_SIGN: 1124 return KEY_TYPE_RSA; // RFC rsa_sign 1125 case TLS_CT_DSS_SIGN: 1126 return KEY_TYPE_DSA; // RFC dss_sign 1127 case TLS_CT_RSA_FIXED_DH: 1128 return KEY_TYPE_DH_RSA; // RFC rsa_fixed_dh 1129 case TLS_CT_DSS_FIXED_DH: 1130 return KEY_TYPE_DH_DSA; // RFC dss_fixed_dh 1131 case TLS_CT_ECDSA_SIGN: 1132 return KEY_TYPE_EC; // RFC ecdsa_sign 1133 case TLS_CT_RSA_FIXED_ECDH: 1134 return KEY_TYPE_EC_RSA; // RFC rsa_fixed_ecdh 1135 case TLS_CT_ECDSA_FIXED_ECDH: 1136 return KEY_TYPE_EC_EC; // RFC ecdsa_fixed_ecdh 1137 default: 1138 return null; 1139 } 1140 } 1141 1142 private static final String AUTH_TYPE_RSA = "RSA"; 1143 private static final String AUTH_TYPE_RSA_EXPORT = "RSA_EXPORT"; 1144 private static final String AUTH_TYPE_DHE_DSS = "DHE_DSS"; 1145 private static final String AUTH_TYPE_DHE_RSA = "DHE_RSA"; 1146 private static final String AUTH_TYPE_DH_DSS = "DH_DSS"; 1147 private static final String AUTH_TYPE_DH_RSA = "DH_RSA"; 1148 private static final String AUTH_TYPE_ECDH_ECDSA = "ECDH_ECDSA"; 1149 private static final String AUTH_TYPE_ECDH_RSA = "ECDH_RSA"; 1150 private static final String AUTH_TYPE_ECDHE_ECDSA = "ECDHE_ECDSA"; 1151 private static final String AUTH_TYPE_ECDHE_RSA = "ECDHE_RSA"; 1152 1153 /** 1154 * Returns auth type constant suitable for calling X509TrustManager.checkServerTrusted. 1155 */ 1156 public String getAuthType(boolean emphemeral) { 1157 switch (keyExchange) { 1158 case KEY_EXCHANGE_RSA: 1159 return AUTH_TYPE_RSA; 1160 case KEY_EXCHANGE_RSA_EXPORT: 1161 return emphemeral ? AUTH_TYPE_RSA_EXPORT : AUTH_TYPE_RSA; 1162 case KEY_EXCHANGE_DHE_DSS: 1163 case KEY_EXCHANGE_DHE_DSS_EXPORT: 1164 return AUTH_TYPE_DHE_DSS; 1165 case KEY_EXCHANGE_DHE_RSA: 1166 case KEY_EXCHANGE_DHE_RSA_EXPORT: 1167 return AUTH_TYPE_DHE_RSA; 1168 case KEY_EXCHANGE_ECDH_ECDSA: 1169 return AUTH_TYPE_ECDH_ECDSA; 1170 case KEY_EXCHANGE_ECDHE_ECDSA: 1171 return AUTH_TYPE_ECDHE_ECDSA; 1172 case KEY_EXCHANGE_ECDH_RSA: 1173 return AUTH_TYPE_ECDH_RSA; 1174 case KEY_EXCHANGE_ECDHE_RSA: 1175 return AUTH_TYPE_ECDHE_RSA; 1176 case KEY_EXCHANGE_DH_anon: 1177 case KEY_EXCHANGE_DH_anon_EXPORT: 1178 case KEY_EXCHANGE_ECDH_anon: 1179 return null; 1180 default: 1181 throw new IllegalStateException("Unknown auth type for key exchange " + keyExchange); 1182 } 1183 } 1184 } 1185