public class TlsProtocolHandler
extends java.lang.Object
Constructor and Description |
---|
TlsProtocolHandler(java.io.InputStream is,
java.io.OutputStream os) |
TlsProtocolHandler(java.io.InputStream is,
java.io.OutputStream os,
java.security.SecureRandom sr) |
Modifier and Type | Method and Description |
---|---|
private static boolean |
arrayContains(int[] a,
int n) |
private static boolean |
arrayContains(short[] a,
short n) |
protected void |
assertEmpty(java.io.ByteArrayInputStream is)
Make sure the InputStream is now empty.
|
void |
close()
Closes this connection.
|
void |
connect(CertificateVerifyer verifyer)
Deprecated.
use version taking TlsClient
|
void |
connect(TlsClient tlsClient)
Connects to the remote system using client authentication
|
private static byte[] |
createRenegotiationInfo(byte[] renegotiated_connection) |
private static java.security.SecureRandom |
createSecureRandom() |
private void |
failWithError(short alertLevel,
short alertDescription)
Terminate this connection with an alert.
|
protected void |
flush() |
java.io.InputStream |
getInputStream() |
java.io.OutputStream |
getOutputStream() |
private void |
processAlert() |
private void |
processApplicationData() |
private void |
processChangeCipherSpec()
This method is called, when a change cipher spec message is received.
|
protected void |
processData(short protocol,
byte[] buf,
int offset,
int len) |
private void |
processHandshake() |
private void |
processHandshakeMessage(short type,
byte[] buf) |
protected int |
readApplicationData(byte[] buf,
int offset,
int len)
Read data from the network.
|
private void |
safeReadData() |
private void |
safeWriteMessage(short type,
byte[] buf,
int offset,
int len) |
private void |
sendAlert(short alertLevel,
short alertDescription) |
private void |
sendCertificateVerify(byte[] data) |
private void |
sendClientCertificate(Certificate clientCert) |
private void |
sendClientKeyExchange() |
protected void |
writeData(byte[] buf,
int offset,
int len)
Send some application data to the remote system.
|
private static void |
writeExtension(java.io.OutputStream output,
java.lang.Integer extType,
byte[] extValue) |
private static final java.lang.Integer EXT_RenegotiationInfo
private static final short CS_CLIENT_HELLO_SEND
private static final short CS_SERVER_HELLO_RECEIVED
private static final short CS_SERVER_CERTIFICATE_RECEIVED
private static final short CS_SERVER_KEY_EXCHANGE_RECEIVED
private static final short CS_CERTIFICATE_REQUEST_RECEIVED
private static final short CS_SERVER_HELLO_DONE_RECEIVED
private static final short CS_CLIENT_KEY_EXCHANGE_SEND
private static final short CS_CERTIFICATE_VERIFY_SEND
private static final short CS_CLIENT_CHANGE_CIPHER_SPEC_SEND
private static final short CS_CLIENT_FINISHED_SEND
private static final short CS_SERVER_CHANGE_CIPHER_SPEC_RECEIVED
private static final short CS_DONE
private static final byte[] emptybuf
private static final java.lang.String TLS_ERROR_MESSAGE
private ByteQueue applicationDataQueue
private ByteQueue changeCipherSpecQueue
private ByteQueue alertQueue
private ByteQueue handshakeQueue
private RecordStream rs
private java.security.SecureRandom random
private TlsInputStream tlsInputStream
private TlsOutputStream tlsOutputStream
private boolean closed
private boolean failedWithError
private boolean appDataReady
private java.util.Hashtable clientExtensions
private SecurityParameters securityParameters
private TlsClientContextImpl tlsClientContext
private TlsClient tlsClient
private int[] offeredCipherSuites
private short[] offeredCompressionMethods
private TlsKeyExchange keyExchange
private TlsAuthentication authentication
private CertificateRequest certificateRequest
private short connection_state
public TlsProtocolHandler(java.io.InputStream is, java.io.OutputStream os)
public TlsProtocolHandler(java.io.InputStream is, java.io.OutputStream os, java.security.SecureRandom sr)
private static java.security.SecureRandom createSecureRandom()
protected void processData(short protocol, byte[] buf, int offset, int len) throws java.io.IOException
java.io.IOException
private void processHandshake() throws java.io.IOException
java.io.IOException
private void processHandshakeMessage(short type, byte[] buf) throws java.io.IOException
java.io.IOException
private void processApplicationData()
private void processAlert() throws java.io.IOException
java.io.IOException
private void processChangeCipherSpec() throws java.io.IOException
java.io.IOException
- If the message has an invalid content or the handshake is not
in the correct state.private void sendClientCertificate(Certificate clientCert) throws java.io.IOException
java.io.IOException
private void sendClientKeyExchange() throws java.io.IOException
java.io.IOException
private void sendCertificateVerify(byte[] data) throws java.io.IOException
java.io.IOException
public void connect(CertificateVerifyer verifyer) throws java.io.IOException
verifyer
- Will be used when a certificate is received to verify that this
certificate is accepted by the client.java.io.IOException
- If handshake was not successful.public void connect(TlsClient tlsClient) throws java.io.IOException
tlsClient
- java.io.IOException
- If handshake was not successful.protected int readApplicationData(byte[] buf, int offset, int len) throws java.io.IOException
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.java.io.IOException
- If something goes wrong during reading data.private void safeReadData() throws java.io.IOException
java.io.IOException
private void safeWriteMessage(short type, byte[] buf, int offset, int len) throws java.io.IOException
java.io.IOException
protected void writeData(byte[] buf, int offset, int len) throws java.io.IOException
buf
- The buffer with the data.offset
- The position in the buffer where the data is placed.len
- The length of the data.java.io.IOException
- If something goes wrong during sending.public java.io.OutputStream getOutputStream()
public java.io.InputStream getInputStream()
private void failWithError(short alertLevel, short alertDescription) throws java.io.IOException
alertLevel
- The level of the alert, an be AlertLevel.fatal or AL_warning.alertDescription
- The exact alert message.java.io.IOException
- If alert was fatal.private void sendAlert(short alertLevel, short alertDescription) throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
java.io.IOException
- If something goes wrong during closing.protected void assertEmpty(java.io.ByteArrayInputStream is) throws java.io.IOException
is
- The InputStream to check.java.io.IOException
- If is is not empty.protected void flush() throws java.io.IOException
java.io.IOException
private static boolean arrayContains(short[] a, short n)
private static boolean arrayContains(int[] a, int n)
private static byte[] createRenegotiationInfo(byte[] renegotiated_connection) throws java.io.IOException
java.io.IOException
private static void writeExtension(java.io.OutputStream output, java.lang.Integer extType, byte[] extValue) throws java.io.IOException
java.io.IOException