net.jradius.tls
Class TlsProtocolHandler

java.lang.Object
  extended by net.jradius.tls.TlsProtocolHandler

public class TlsProtocolHandler
extends Object

An implementation of all high level protocols in TLS 1.0.


Field Summary
protected static short AL_fatal
           
protected static short AL_warning
           
protected static short AP_access_denied
           
protected static short AP_bad_certificate
           
protected static short AP_bad_record_mac
           
protected static short AP_certificate_expired
           
protected static short AP_certificate_revoked
           
protected static short AP_certificate_unknown
           
protected static short AP_close_notify
           
protected static short AP_decode_error
           
protected static short AP_decompression_failure
           
protected static short AP_decrypt_error
           
protected static short AP_decryption_failed
           
protected static short AP_export_restriction
           
protected static short AP_handshake_failure
           
protected static short AP_illegal_parameter
           
protected static short AP_insufficient_security
           
protected static short AP_internal_error
           
protected static short AP_no_renegotiation
           
protected static short AP_protocol_version
           
protected static short AP_record_overflow
           
protected static short AP_unexpected_message
           
protected static short AP_unknown_ca
           
protected static short AP_unknown_psk_identity
           
protected static short AP_unsupported_certificate
           
protected static short AP_user_canceled
           
static short CS_DONE
           
 
Constructor Summary
TlsProtocolHandler()
           
TlsProtocolHandler(InputStream is, OutputStream os)
           
TlsProtocolHandler(InputStream is, OutputStream os, SecureRandom sr)
           
 
Method Summary
protected  void assertEmpty(ByteArrayInputStream is)
          Make sure the InputStream is now empty.
 void close()
          Closes this connection.
 void connect(ByteArrayInputStream is, ByteArrayOutputStream out, CertificateVerifyer verifyer)
          Connects to the remote system.
 void connect(ByteArrayInputStream is, ByteArrayOutputStream out, net.jradius.tls.TlsClient tlsClient)
          Connects to the remote system using client authentication
protected  void failWithError(short alertLevel, short alertDescription)
          Terminate this connection with an alert.
protected  void flush()
           
 InputStream getInputStream()
           
 OutputStream getOutputStream()
           
protected  void processData(short protocol, byte[] buf, int offset, int len)
           
protected  byte[] readApplicationData()
           
protected  int readApplicationData(byte[] buf, int offset, int len)
          Read data from the network.
 byte[] readApplicationData(ByteArrayInputStream is, ByteArrayOutputStream os)
           
 void setKeyManagers(KeyManager[] keyManagers)
           
 void setSendCertificate(boolean b)
           
 void setTrustManagers(TrustManager[] trustManagers)
           
 short updateConnectState(ByteArrayInputStream is, ByteArrayOutputStream os)
           
 void writeApplicationData(ByteArrayInputStream is, ByteArrayOutputStream os, byte[] b)
           
protected  void writeData(byte[] buf, int offset, int len)
          Send some application data to the remote system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CS_DONE

public static final short CS_DONE
See Also:
Constant Field Values

AL_warning

protected static final short AL_warning
See Also:
Constant Field Values

AL_fatal

protected static final short AL_fatal
See Also:
Constant Field Values

AP_close_notify

protected static final short AP_close_notify
See Also:
Constant Field Values

AP_unexpected_message

protected static final short AP_unexpected_message
See Also:
Constant Field Values

AP_bad_record_mac

protected static final short AP_bad_record_mac
See Also:
Constant Field Values

AP_decryption_failed

protected static final short AP_decryption_failed
See Also:
Constant Field Values

AP_record_overflow

protected static final short AP_record_overflow
See Also:
Constant Field Values

AP_decompression_failure

protected static final short AP_decompression_failure
See Also:
Constant Field Values

AP_handshake_failure

protected static final short AP_handshake_failure
See Also:
Constant Field Values

AP_bad_certificate

protected static final short AP_bad_certificate
See Also:
Constant Field Values

AP_unsupported_certificate

protected static final short AP_unsupported_certificate
See Also:
Constant Field Values

AP_certificate_revoked

protected static final short AP_certificate_revoked
See Also:
Constant Field Values

AP_certificate_expired

protected static final short AP_certificate_expired
See Also:
Constant Field Values

AP_certificate_unknown

protected static final short AP_certificate_unknown
See Also:
Constant Field Values

AP_illegal_parameter

protected static final short AP_illegal_parameter
See Also:
Constant Field Values

AP_unknown_ca

protected static final short AP_unknown_ca
See Also:
Constant Field Values

AP_access_denied

protected static final short AP_access_denied
See Also:
Constant Field Values

AP_decode_error

protected static final short AP_decode_error
See Also:
Constant Field Values

AP_decrypt_error

protected static final short AP_decrypt_error
See Also:
Constant Field Values

AP_export_restriction

protected static final short AP_export_restriction
See Also:
Constant Field Values

AP_protocol_version

protected static final short AP_protocol_version
See Also:
Constant Field Values

AP_insufficient_security

protected static final short AP_insufficient_security
See Also:
Constant Field Values

AP_internal_error

protected static final short AP_internal_error
See Also:
Constant Field Values

AP_user_canceled

protected static final short AP_user_canceled
See Also:
Constant Field Values

AP_no_renegotiation

protected static final short AP_no_renegotiation
See Also:
Constant Field Values

AP_unknown_psk_identity

protected static final short AP_unknown_psk_identity
See Also:
Constant Field Values
Constructor Detail

TlsProtocolHandler

public TlsProtocolHandler(InputStream is,
                          OutputStream os)

TlsProtocolHandler

public TlsProtocolHandler(InputStream is,
                          OutputStream os,
                          SecureRandom sr)

TlsProtocolHandler

public TlsProtocolHandler()
Method Detail

setSendCertificate

public void setSendCertificate(boolean b)

processData

protected void processData(short protocol,
                           byte[] buf,
                           int offset,
                           int len)
                    throws IOException
Throws:
IOException

connect

public void connect(ByteArrayInputStream is,
                    ByteArrayOutputStream out,
                    CertificateVerifyer verifyer)
             throws IOException
Connects to the remote system.

Parameters:
is -
out -
verifyer - Will be used when a certificate is received to verify that this certificate is accepted by the client.
Throws:
IOException - If handshake was not successful.

connect

public void connect(ByteArrayInputStream is,
                    ByteArrayOutputStream out,
                    net.jradius.tls.TlsClient tlsClient)
             throws IOException
Connects to the remote system using client authentication

Parameters:
verifyer - Will be used when a certificate is received to verify that this certificate is accepted by the client.
clientCertificate - The client's certificate to be provided to the remote system
clientPrivateKey - The client's private key for the certificate to authenticate to the remote system (RSA or DSA)
Throws:
IOException - If handshake was not successful.

writeApplicationData

public void writeApplicationData(ByteArrayInputStream is,
                                 ByteArrayOutputStream os,
                                 byte[] b)
                          throws IOException
Throws:
IOException

readApplicationData

public byte[] readApplicationData(ByteArrayInputStream is,
                                  ByteArrayOutputStream os)
                           throws IOException
Throws:
IOException

readApplicationData

protected byte[] readApplicationData()
                              throws IOException
Throws:
IOException

updateConnectState

public short updateConnectState(ByteArrayInputStream is,
                                ByteArrayOutputStream os)
                         throws IOException
Throws:
IOException

readApplicationData

protected int readApplicationData(byte[] buf,
                                  int offset,
                                  int len)
                           throws IOException
Read data from the network. The method will return immediately, if there is still some data left in the buffer, or block until some application data has been read from the network.

Parameters:
buf - The buffer where the data will be copied to.
offset - The position where the data will be placed in the buffer.
len - The maximum number of bytes to read.
Returns:
The number of bytes read.
Throws:
IOException - If something goes wrong during reading data.

writeData

protected void writeData(byte[] buf,
                         int offset,
                         int len)
                  throws IOException
Send some application data to the remote system.

The method will handle fragmentation internally.

Parameters:
buf - The buffer with the data.
offset - The position in the buffer where the data is placed.
len - The length of the data.
Throws:
IOException - If something goes wrong during sending.

getOutputStream

public OutputStream getOutputStream()
Returns:
An OutputStream which can be used to send data.

getInputStream

public InputStream getInputStream()
Returns:
An InputStream which can be used to read data.

failWithError

protected void failWithError(short alertLevel,
                             short alertDescription)
                      throws IOException
Terminate this connection with an alert.

Can be used for normal closure too.

Parameters:
alertLevel - The level of the alert, an be AL_fatal or AL_warning.
alertDescription - The exact alert message.
Throws:
IOException - If alert was fatal.

close

public void close()
           throws IOException
Closes this connection.

Throws:
IOException - If something goes wrong during closing.

assertEmpty

protected void assertEmpty(ByteArrayInputStream is)
                    throws IOException
Make sure the InputStream is now empty. Fail otherwise.

Parameters:
is - The InputStream to check.
Throws:
IOException - If is is not empty.

flush

protected void flush()
              throws IOException
Throws:
IOException

setKeyManagers

public void setKeyManagers(KeyManager[] keyManagers)

setTrustManagers

public void setTrustManagers(TrustManager[] trustManagers)


Copyright © 2011 Coova Technologies, LLC, All Rights Reserved.