FileDocCategorySizeDatePackage
CipherSuite.javaAPI DocAndroid 1.5 API21783Wed May 06 22:41:06 BST 2009org.apache.harmony.xnet.provider.jsse

CipherSuite

public class CipherSuite extends Object
Represents Cipher Suite as defined in TLS 1.0 spec., A.5. The CipherSuite; C. CipherSuite definitions.
see
TLS 1.0 spec.

Fields Summary
boolean
supported
true if this cipher suite is supported
final int
keyExchange
cipher suite key exchange
final String
cipherName
cipher
final int
keyMaterial
Cipher information
final int
expandedKeyMaterial
final int
effectiveKeyBytes
final int
IVSize
private final int
blockSize
private final byte[]
cipherSuiteCode
private final String
name
private final boolean
isExportable
private final String
hashName
private final String
hmacName
private final int
hashSize
static int
KeyExchange_RSA
key exchange values
static int
KeyExchange_RSA_EXPORT
static int
KeyExchange_DHE_DSS
static int
KeyExchange_DHE_DSS_EXPORT
static int
KeyExchange_DHE_RSA
static int
KeyExchange_DHE_RSA_EXPORT
static int
KeyExchange_DH_DSS
static int
KeyExchange_DH_RSA
static int
KeyExchange_DH_anon
static int
KeyExchange_DH_anon_EXPORT
static int
KeyExchange_DH_DSS_EXPORT
static int
KeyExchange_DH_RSA_EXPORT
static byte[]
code_TLS_NULL_WITH_NULL_NULL
TLS cipher suite codes
static byte[]
code_TLS_RSA_WITH_NULL_MD5
static byte[]
code_TLS_RSA_WITH_NULL_SHA
static byte[]
code_TLS_RSA_EXPORT_WITH_RC4_40_MD5
static byte[]
code_TLS_RSA_WITH_RC4_128_MD5
static byte[]
code_TLS_RSA_WITH_RC4_128_SHA
static byte[]
code_TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5
static byte[]
code_TLS_RSA_WITH_IDEA_CBC_SHA
static byte[]
code_TLS_RSA_EXPORT_WITH_DES40_CBC_SHA
static byte[]
code_TLS_RSA_WITH_DES_CBC_SHA
static byte[]
code_TLS_RSA_WITH_3DES_EDE_CBC_SHA
static byte[]
code_TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA
static byte[]
code_TLS_DH_DSS_WITH_DES_CBC_SHA
static byte[]
code_TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA
static byte[]
code_TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA
static byte[]
code_TLS_DH_RSA_WITH_DES_CBC_SHA
static byte[]
code_TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA
static byte[]
code_TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA
static byte[]
code_TLS_DHE_DSS_WITH_DES_CBC_SHA
static byte[]
code_TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
static byte[]
code_TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA
static byte[]
code_TLS_DHE_RSA_WITH_DES_CBC_SHA
static byte[]
code_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
static byte[]
code_TLS_DH_anon_EXPORT_WITH_RC4_40_MD5
static byte[]
code_TLS_DH_anon_WITH_RC4_128_MD5
static byte[]
code_TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA
static byte[]
code_TLS_DH_anon_WITH_DES_CBC_SHA
static byte[]
code_TLS_DH_anon_WITH_3DES_EDE_CBC_SHA
static CipherSuite
TLS_NULL_WITH_NULL_NULL
static CipherSuite
TLS_RSA_WITH_NULL_MD5
static CipherSuite
TLS_RSA_WITH_NULL_SHA
static CipherSuite
TLS_RSA_EXPORT_WITH_RC4_40_MD5
static CipherSuite
TLS_RSA_WITH_RC4_128_MD5
static CipherSuite
TLS_RSA_WITH_RC4_128_SHA
static CipherSuite
TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5
static CipherSuite
TLS_RSA_WITH_IDEA_CBC_SHA
static CipherSuite
TLS_RSA_EXPORT_WITH_DES40_CBC_SHA
static CipherSuite
TLS_RSA_WITH_DES_CBC_SHA
static CipherSuite
TLS_RSA_WITH_3DES_EDE_CBC_SHA
static CipherSuite
TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA
static CipherSuite
TLS_DH_DSS_WITH_DES_CBC_SHA
static CipherSuite
TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA
static CipherSuite
TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA
static CipherSuite
TLS_DH_RSA_WITH_DES_CBC_SHA
static CipherSuite
TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA
static CipherSuite
TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA
static CipherSuite
TLS_DHE_DSS_WITH_DES_CBC_SHA
static CipherSuite
TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
static CipherSuite
TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA
static CipherSuite
TLS_DHE_RSA_WITH_DES_CBC_SHA
static CipherSuite
TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
static CipherSuite
TLS_DH_anon_EXPORT_WITH_RC4_40_MD5
static CipherSuite
TLS_DH_anon_WITH_RC4_128_MD5
static CipherSuite
TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA
static CipherSuite
TLS_DH_anon_WITH_DES_CBC_SHA
static CipherSuite
TLS_DH_anon_WITH_3DES_EDE_CBC_SHA
private static CipherSuite[]
cuitesByCode
private static Hashtable
cuitesByName
static CipherSuite[]
supportedCipherSuites
array of supported sipher suites. Set of supported suites is defined at the moment provider's start
static String[]
supportedCipherSuiteNames
array of supported sipher suites names
static CipherSuite[]
defaultCipherSuites
default sipher suites
Constructors Summary
public CipherSuite(String name, boolean isExportable, int keyExchange, String cipherName, String hash, byte[] code)
Creates CipherSuite

param
name
param
isExportable
param
keyExchange
param
cipherName
param
hash
param
code

        this.name = name;
        this.keyExchange = keyExchange;
        this.isExportable = isExportable;
        if (cipherName == null) {
            this.cipherName = null;
            keyMaterial = 0;
            expandedKeyMaterial = 0;
            effectiveKeyBytes = 0;
            IVSize = 0;
            blockSize = 0;
        } else if ("IDEA_CBC".equals(cipherName)) {
            this.cipherName = "IDEA/CBC/NoPadding";
            keyMaterial = 16;
            expandedKeyMaterial = 16;
            effectiveKeyBytes = 16;
            IVSize = 8;
            blockSize = 8;
        } else if ("RC2_CBC_40".equals(cipherName)) {
            this.cipherName = "RC2/CBC/NoPadding";
            keyMaterial = 5;
            expandedKeyMaterial = 16;
            effectiveKeyBytes = 5;
            IVSize = 8;
            blockSize = 8;
        } else if ("RC4_40".equals(cipherName)) {
            this.cipherName = "RC4";
            keyMaterial = 5;
            expandedKeyMaterial = 16;
            effectiveKeyBytes = 5;
            IVSize = 0;
            blockSize = 0;
        } else if ("RC4_128".equals(cipherName)) {
            this.cipherName = "RC4";
            keyMaterial = 16;
            expandedKeyMaterial = 16;
            effectiveKeyBytes = 16;
            IVSize = 0;
            blockSize = 0;
        } else if ("DES40_CBC".equals(cipherName)) {
            this.cipherName = "DES/CBC/NoPadding";
            keyMaterial = 5;
            expandedKeyMaterial = 8;
            effectiveKeyBytes = 5;
            IVSize = 8;
            blockSize = 8;
        } else if ("DES_CBC".equals(cipherName)) {
            this.cipherName = "DES/CBC/NoPadding";
            keyMaterial = 8;
            expandedKeyMaterial = 8;
            effectiveKeyBytes = 7;
            IVSize = 8;
            blockSize = 8;
        } else if ("3DES_EDE_CBC".equals(cipherName)) {
            this.cipherName = "DESede/CBC/NoPadding";
            keyMaterial = 24;
            expandedKeyMaterial = 24;
            effectiveKeyBytes = 24;
            IVSize = 8;
            blockSize = 8;
        } else {
            this.cipherName = cipherName;
            keyMaterial = 0;
            expandedKeyMaterial = 0;
            effectiveKeyBytes = 0;
            IVSize = 0;
            blockSize = 0;
        }

        if ("MD5".equals(hash)) {
            this.hmacName = "HmacMD5";
            this.hashName = "MD5";
            hashSize = 16;
        } else if ("SHA".equals(hash)) {
            this.hmacName = "HmacSHA1";
            this.hashName = "SHA-1";
            hashSize = 20;
        } else {
            this.hmacName = null;
            this.hashName = null;
            hashSize = 0;
        }

        cipherSuiteCode = code;

        if (this.cipherName != null) {
            try {
                Cipher.getInstance(this.cipherName);
            } catch (GeneralSecurityException e) {
                supported = false;
            }
        }

    
Methods Summary
public booleanequals(java.lang.Object obj)
Compares this cipher suite to the specified object.

        if (obj instanceof CipherSuite
                && this.cipherSuiteCode[0] == ((CipherSuite) obj).cipherSuiteCode[0]
                && this.cipherSuiteCode[1] == ((CipherSuite) obj).cipherSuiteCode[1]) {
            return true;
        }
        return false;
    
public intgetBlockSize()
Returns cipher block size

return

        return blockSize;
    
public java.lang.StringgetBulkEncryptionAlgorithm()
Returns cipher algorithm name

return

        return cipherName;
    
public static org.apache.harmony.xnet.provider.jsse.CipherSuitegetByCode(byte b1, byte b2)
Returns CipherSuite based on TLS CipherSuite code

see
TLS 1.0 spec., A.5. The CipherSuite
param
b1
param
b2
return

        if (b1 != 0 || b2 > cuitesByCode.length) {
            // Unknoun
            return new CipherSuite("UNKNOUN_" + b1 + "_" + b2, false, 0, "",
                    "", new byte[] { b1, b2 });
        }
        return cuitesByCode[b2];
    
public static org.apache.harmony.xnet.provider.jsse.CipherSuitegetByCode(byte b1, byte b2, byte b3)
Returns CipherSuite based on V2CipherSpec code as described in TLS 1.0 spec., E. Backward Compatibility With SSL

param
b1
param
b2
param
b3
return
CipherSuite

        if (b1 == 0 && b2 == 0) {
            if (b3 <= cuitesByCode.length) {
                return cuitesByCode[b3];
            }
        }
        // as TLSv1 equivalent of V2CipherSpec should be included in
        // V2ClientHello, ignore V2CipherSpec
        return new CipherSuite("UNKNOUN_" + b1 + "_" + b2 + "_" + b3, false, 0,
                "", "", new byte[] { b1, b2, b3 });
    
public static org.apache.harmony.xnet.provider.jsse.CipherSuitegetByName(java.lang.String name)
Returns CipherSuite by name

param
name
return

    
     
        int count = 0;
        cuitesByName = new Hashtable();
        for (int i = 0; i < cuitesByCode.length; i++) {
            cuitesByName.put(cuitesByCode[i].getName(), cuitesByCode[i]);
            if (cuitesByCode[i].supported) {
                count++;
            }
        }
        supportedCipherSuites = new CipherSuite[count];
        supportedCipherSuiteNames = new String[count];
        count = 0;
        for (int i = 0; i < cuitesByCode.length; i++) {
            if (cuitesByCode[i].supported) {
                supportedCipherSuites[count] = cuitesByCode[i];
                supportedCipherSuiteNames[count] = supportedCipherSuites[count].getName();
                count++;
            }
        }

        CipherSuite[] defaultPretendent = { 
                TLS_RSA_WITH_RC4_128_MD5,
                TLS_RSA_WITH_RC4_128_SHA,
                // TLS_RSA_WITH_AES_128_CBC_SHA,
                // TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
                // LS_DHE_DSS_WITH_AES_128_CBC_SHA,
                TLS_RSA_WITH_3DES_EDE_CBC_SHA,
                TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA,
                TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_DES_CBC_SHA,
                TLS_DHE_RSA_WITH_DES_CBC_SHA, TLS_DHE_DSS_WITH_DES_CBC_SHA,
                TLS_RSA_EXPORT_WITH_RC4_40_MD5,
                TLS_RSA_EXPORT_WITH_DES40_CBC_SHA,
                TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA,
                TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA 
                };
        count = 0;
        for (int i = 0; i < defaultPretendent.length; i++) {
            if (defaultPretendent[i].supported) {
                count++;
            }
        }
        defaultCipherSuites = new CipherSuite[count];
        count = 0;
        for (int i = 0; i < defaultPretendent.length; i++) {
            if (defaultPretendent[i].supported) {
                defaultCipherSuites[count++] = defaultPretendent[i];
            }
        }
    
        return (CipherSuite) cuitesByName.get(name);
    
public java.lang.StringgetHashName()
Returns hash algorithm name

return

        return hashName;
    
public java.lang.StringgetHmacName()
Returns MAC algorithm name

return

        return hmacName;
    
public intgetMACLength()
Returns hash size

return

        return hashSize;
    
public java.lang.StringgetName()
Returns cipher suite name

return

        return name;
    
public static org.apache.harmony.xnet.provider.jsse.CipherSuite[]getSupported()
Returns array of supported CipherSuites

return

        return supportedCipherSuites;
    
public static java.lang.String[]getSupportedCipherSuiteNames()
Returns array of supported cipher suites names

return

        return (String[]) supportedCipherSuiteNames.clone();
    
public booleanisAnonymous()
Returns true if cipher suite is anonymous

return

        if (keyExchange == KeyExchange_DH_anon
                || keyExchange == KeyExchange_DH_anon_EXPORT) {
            return true;
        }
        return false;
    
public booleanisExportable()
Indicates whether this cipher suite is exportable

return

        return isExportable;
    
public byte[]toBytes()
Returns cipher suite code as byte array

return

        return cipherSuiteCode;
    
public java.lang.StringtoString()
Returns cipher suite description

        return name + ": " + cipherSuiteCode[0] + " " + cipherSuiteCode[1];