anon.crypto.tinytls.ciphersuites
Class CipherSuite

java.lang.Object
  extended by anon.crypto.tinytls.ciphersuites.CipherSuite
Direct Known Subclasses:
DHE_DSS_WITH_3DES_CBC_SHA, DHE_DSS_WITH_AES_128_CBC_SHA, DHE_DSS_WITH_DES_CBC_SHA, DHE_RSA_WITH_3DES_CBC_SHA, DHE_RSA_WITH_AES_128_CBC_SHA, DHE_RSA_WITH_DES_CBC_SHA

public abstract class CipherSuite
extends java.lang.Object

Author:
stefan A abstract ciphersuite that can used TinyTLS this is the parent class for all ciphersuites

Field Summary
private  byte[] m_ciphersuitecode
           
protected  java.lang.String m_ciphersuitename
           
protected  byte[] m_clientmacsecret
          client write mac secret
protected  byte[] m_clientwriteIV
          client write IV, only used for block ciphers
protected  byte[] m_clientwritekey
          client write key
protected  org.bouncycastle.crypto.modes.CBCBlockCipher m_decryptcipher
           
protected  org.bouncycastle.crypto.modes.CBCBlockCipher m_encryptcipher
           
private  org.bouncycastle.crypto.macs.HMac m_hmacInput
           
private  org.bouncycastle.crypto.macs.HMac m_hmacOutput
           
private  Key_Exchange m_keyexchangealgorithm
           
private  MyRandom m_Random
           
protected  long m_readsequenznumber
          readsequenznumber for packages
private  JAPCertificate m_servercertificate
           
protected  byte[] m_servermacsecret
          server write mac secret
protected  byte[] m_serverwriteIV
          server write IV, only used for block ciphers
protected  byte[] m_serverwritekey
          server write key
protected  long m_writesequenznumber
          writesequenznumber for packages
 
Constructor Summary
CipherSuite(byte[] code)
          Constructor for a ciphersuite
 
Method Summary
 byte[] calculateClientKeyExchange()
          calculate the client keys (see RFC2246 Client Key Exchange)
protected abstract  void calculateKeys(byte[] keys, boolean forclient)
          calculate server and client write keys (see RFC2246 TLS Record Protocoll)
 void decode(TLSPlaintextRecord msg)
          decodes a message with a symmetric key
 void encode(TLSPlaintextRecord msg)
          encodes a message with a symmetric key
 byte[] getCipherSuiteCode()
          returns the code of a ciphersuite (see RFC2246)
 Key_Exchange getKeyExchangeAlgorithm()
          gets the key exchange algorithm that is used
 void processClientKeyExchange(java.math.BigInteger dh_y)
          processes the client key exchange
 void processServerFinished(TLSPlaintextRecord msg, byte[] handshakemessages)
          validates the finishedmessage and throws a Exception if a error occure
protected  void setKeyExchangeAlgorithm(Key_Exchange ke)
          sets the key exchange algorithm
 void setServerCertificate(JAPCertificate cert)
          set the Server Certificate
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_ciphersuitecode

private byte[] m_ciphersuitecode

m_ciphersuitename

protected java.lang.String m_ciphersuitename

m_keyexchangealgorithm

private Key_Exchange m_keyexchangealgorithm

m_servercertificate

private JAPCertificate m_servercertificate

m_decryptcipher

protected org.bouncycastle.crypto.modes.CBCBlockCipher m_decryptcipher

m_encryptcipher

protected org.bouncycastle.crypto.modes.CBCBlockCipher m_encryptcipher

m_hmacInput

private org.bouncycastle.crypto.macs.HMac m_hmacInput

m_hmacOutput

private org.bouncycastle.crypto.macs.HMac m_hmacOutput

m_Random

private MyRandom m_Random

m_writesequenznumber

protected long m_writesequenznumber
writesequenznumber for packages


m_readsequenznumber

protected long m_readsequenznumber
readsequenznumber for packages


m_clientwritekey

protected byte[] m_clientwritekey
client write key


m_clientmacsecret

protected byte[] m_clientmacsecret
client write mac secret


m_clientwriteIV

protected byte[] m_clientwriteIV
client write IV, only used for block ciphers


m_serverwritekey

protected byte[] m_serverwritekey
server write key


m_servermacsecret

protected byte[] m_servermacsecret
server write mac secret


m_serverwriteIV

protected byte[] m_serverwriteIV
server write IV, only used for block ciphers

Constructor Detail

CipherSuite

public CipherSuite(byte[] code)
            throws TLSException
Constructor for a ciphersuite

Parameters:
code - Code of the ciphersuite (see RFC2246)
Throws:
TLSException
Method Detail

setKeyExchangeAlgorithm

protected void setKeyExchangeAlgorithm(Key_Exchange ke)
sets the key exchange algorithm

Parameters:
ke - Key Exchange Algorithm

getKeyExchangeAlgorithm

public Key_Exchange getKeyExchangeAlgorithm()
gets the key exchange algorithm that is used

Returns:
key exchange algorithm

setServerCertificate

public void setServerCertificate(JAPCertificate cert)
set the Server Certificate

Parameters:
cert - server certificate

getCipherSuiteCode

public byte[] getCipherSuiteCode()
returns the code of a ciphersuite (see RFC2246)

Returns:
ciphersuitecode

processClientKeyExchange

public void processClientKeyExchange(java.math.BigInteger dh_y)
processes the client key exchange

Parameters:
dh_y - diffie hellman parameter

calculateClientKeyExchange

public byte[] calculateClientKeyExchange()
                                  throws TLSException
calculate the client keys (see RFC2246 Client Key Exchange)

Returns:
client key exchange message
Throws:
TLSException

processServerFinished

public void processServerFinished(TLSPlaintextRecord msg,
                                  byte[] handshakemessages)
                           throws TLSException
validates the finishedmessage and throws a Exception if a error occure

Parameters:
finishedmessage - the message that have to be valideted
Throws:
TLSException

encode

public void encode(TLSPlaintextRecord msg)
encodes a message with a symmetric key

Parameters:
message - message

decode

public void decode(TLSPlaintextRecord msg)
            throws TLSException
decodes a message with a symmetric key

Parameters:
message - message
Throws:
TLSException

calculateKeys

protected abstract void calculateKeys(byte[] keys,
                                      boolean forclient)
calculate server and client write keys (see RFC2246 TLS Record Protocoll)

Parameters:
keys - array of bytes(see RFC how it is calculated)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object