org.bouncycastle.crypto.tls

Class TlsProtocolHandler


public class TlsProtocolHandler
extends java.lang.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_unsupported_certificate
protected static short
AP_user_canceled

Constructor Summary

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(CertificateVerifyer verifyer)
Connects to the remote system.
protected void
failWithError(short alertLevel, short alertDescription)
Terminate this connection whith an alert.
protected void
flush()
TlsInputStream
getTlsInputStream()
TlsOuputStream
getTlsOuputStream()
protected void
processData(short protocol, byte[] buf, int offset, int len)
protected int
readApplicationData(byte[] buf, int offset, int len)
Read data from the network.
protected void
writeData(byte[] buf, int offset, int len)
Send some application data to the remote system.

Field Details

AL_fatal

protected static final short AL_fatal
Field Value:
2

AL_warning

protected static final short AL_warning
Field Value:
1

AP_access_denied

protected static final short AP_access_denied
Field Value:
49

AP_bad_certificate

protected static final short AP_bad_certificate
Field Value:
42

AP_bad_record_mac

protected static final short AP_bad_record_mac
Field Value:
20

AP_certificate_expired

protected static final short AP_certificate_expired
Field Value:
45

AP_certificate_revoked

protected static final short AP_certificate_revoked
Field Value:
44

AP_certificate_unknown

protected static final short AP_certificate_unknown
Field Value:
46

AP_close_notify

protected static final short AP_close_notify
Field Value:
0

AP_decode_error

protected static final short AP_decode_error
Field Value:
50

AP_decompression_failure

protected static final short AP_decompression_failure
Field Value:
30

AP_decrypt_error

protected static final short AP_decrypt_error
Field Value:
51

AP_decryption_failed

protected static final short AP_decryption_failed
Field Value:
21

AP_export_restriction

protected static final short AP_export_restriction
Field Value:
60

AP_handshake_failure

protected static final short AP_handshake_failure
Field Value:
40

AP_illegal_parameter

protected static final short AP_illegal_parameter
Field Value:
47

AP_insufficient_security

protected static final short AP_insufficient_security
Field Value:
71

AP_internal_error

protected static final short AP_internal_error
Field Value:
80

AP_no_renegotiation

protected static final short AP_no_renegotiation
Field Value:
100

AP_protocol_version

protected static final short AP_protocol_version
Field Value:
70

AP_record_overflow

protected static final short AP_record_overflow
Field Value:
22

AP_unexpected_message

protected static final short AP_unexpected_message
Field Value:
10

AP_unknown_ca

protected static final short AP_unknown_ca
Field Value:
48

AP_unsupported_certificate

protected static final short AP_unsupported_certificate
Field Value:
43

AP_user_canceled

protected static final short AP_user_canceled
Field Value:
90

Constructor Details

TlsProtocolHandler

public TlsProtocolHandler(InputStream is,
                          OutputStream os)

TlsProtocolHandler

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

Method Details

assertEmpty

protected void assertEmpty(ByteArrayInputStream is)
            throws IOException
Make sure the InputStream is now empty. Fail otherwise.
Parameters:
is - The InputStream to check.

close

public void close()
            throws IOException
Closes this connection.

connect

public void connect(CertificateVerifyer verifyer)
            throws IOException
Connects to the remote system.
Parameters:
verifyer - Will be used when a certificate is received to verify that this certificate is accepted by the client.

failWithError

protected void failWithError(short alertLevel,
                             short alertDescription)
            throws IOException
Terminate this connection whith 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.

flush

protected void flush()
            throws IOException

getTlsInputStream

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

getTlsOuputStream

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

processData

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

readApplicationData

protected int readApplicationData(byte[] buf,
                                  int offset,
                                  int len)
            throws IOException
Read data from the network. The method will return immed, if there is still some data left in the buffer, or block untill 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.

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.