public abstract class TlsProtocol
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static short |
ADS_MODE_0_N |
protected static short |
ADS_MODE_0_N_FIRSTONLY |
protected static short |
ADS_MODE_1_Nsub1 |
protected boolean |
allowCertificateStatus |
protected boolean |
blocking |
protected java.util.Hashtable |
clientExtensions |
protected short |
connection_state |
protected static short |
CS_CERTIFICATE_REQUEST |
protected static short |
CS_CERTIFICATE_STATUS |
protected static short |
CS_CERTIFICATE_VERIFY |
protected static short |
CS_CLIENT_CERTIFICATE |
protected static short |
CS_CLIENT_FINISHED |
protected static short |
CS_CLIENT_HELLO |
protected static short |
CS_CLIENT_KEY_EXCHANGE |
protected static short |
CS_CLIENT_SUPPLEMENTAL_DATA |
protected static short |
CS_END |
protected static short |
CS_SERVER_CERTIFICATE |
protected static short |
CS_SERVER_FINISHED |
protected static short |
CS_SERVER_HELLO |
protected static short |
CS_SERVER_HELLO_DONE |
protected static short |
CS_SERVER_KEY_EXCHANGE |
protected static short |
CS_SERVER_SESSION_TICKET |
protected static short |
CS_SERVER_SUPPLEMENTAL_DATA |
protected static short |
CS_START |
protected boolean |
expectSessionTicket |
protected static java.lang.Integer |
EXT_RenegotiationInfo |
protected static java.lang.Integer |
EXT_SessionTicket |
protected ByteQueueInputStream |
inputBuffers |
protected int[] |
offeredCipherSuites |
protected short[] |
offeredCompressionMethods |
protected ByteQueueOutputStream |
outputBuffer |
protected Certificate |
peerCertificate |
protected boolean |
receivedChangeCipherSpec |
protected boolean |
resumedSession |
protected boolean |
secure_renegotiation |
protected java.security.SecureRandom |
secureRandom |
protected SecurityParameters |
securityParameters |
protected java.util.Hashtable |
serverExtensions |
protected SessionParameters |
sessionParameters |
protected TlsSession |
tlsSession |
Constructor and Description |
---|
TlsProtocol(java.io.InputStream input,
java.io.OutputStream output,
java.security.SecureRandom secureRandom) |
TlsProtocol(java.security.SecureRandom secureRandom) |
Modifier and Type | Method and Description |
---|---|
protected int |
applicationDataAvailable() |
protected void |
applyMaxFragmentLengthExtension() |
protected static void |
assertEmpty(java.io.ByteArrayInputStream buf)
Make sure the InputStream 'buf' now empty.
|
protected void |
blockForHandshake() |
protected void |
checkReceivedChangeCipherSpec(boolean expected) |
protected void |
cleanupHandshake() |
void |
close()
Closes this connection.
|
void |
closeInput()
Should be called in non-blocking mode when the input data reaches EOF.
|
protected void |
completeHandshake() |
protected static byte[] |
createRandomBlock(boolean useGMTUnixTime,
RandomGenerator randomGenerator) |
protected static byte[] |
createRenegotiationInfo(byte[] renegotiated_connection) |
protected byte[] |
createVerifyData(boolean isServer) |
protected static void |
establishMasterSecret(TlsContext context,
TlsKeyExchange keyExchange) |
protected void |
failWithError(short alertLevel,
short alertDescription,
java.lang.String message,
java.lang.Throwable cause)
Terminate this connection with an alert.
|
protected void |
flush() |
int |
getAvailableInputBytes()
Gets the amount of received application data.
|
int |
getAvailableOutputBytes()
Gets the amount of encrypted data available to be sent.
|
protected abstract TlsContext |
getContext() |
protected static byte[] |
getCurrentPRFHash(TlsContext context,
TlsHandshakeHash handshakeHash,
byte[] sslSender)
'sender' only relevant to SSLv3
|
java.io.InputStream |
getInputStream() |
java.io.OutputStream |
getOutputStream() |
protected abstract TlsPeer |
getPeer() |
protected static int |
getPRFAlgorithm(TlsContext context,
int ciphersuite) |
protected void |
handleChangeCipherSpecMessage() |
protected void |
handleClose(boolean user_canceled) |
protected abstract void |
handleHandshakeMessage(short type,
java.io.ByteArrayInputStream buf) |
protected void |
handleWarningMessage(short description) |
protected void |
invalidateSession() |
boolean |
isClosed() |
void |
offerInput(byte[] input)
Offer input from an arbitrary source.
|
void |
offerOutput(byte[] buffer,
int offset,
int length)
Offer output from an arbitrary source.
|
protected void |
processFinishedMessage(java.io.ByteArrayInputStream buf) |
protected short |
processMaxFragmentLengthExtension(java.util.Hashtable clientExtensions,
java.util.Hashtable serverExtensions,
short alertDescription) |
protected void |
processRecord(short protocol,
byte[] buf,
int off,
int len) |
protected void |
raiseAlert(short alertLevel,
short alertDescription,
java.lang.String message,
java.lang.Throwable cause) |
protected void |
raiseWarning(short alertDescription,
java.lang.String message) |
protected int |
readApplicationData(byte[] buf,
int offset,
int len)
Read data from the network.
|
protected static java.util.Hashtable |
readExtensions(java.io.ByteArrayInputStream input) |
int |
readInput(byte[] buffer,
int offset,
int length)
Retrieves received application data.
|
int |
readOutput(byte[] buffer,
int offset,
int length)
Retrieves encrypted data to be sent.
|
protected static java.util.Vector |
readSupplementalDataMessage(java.io.ByteArrayInputStream input) |
protected void |
refuseRenegotiation() |
protected void |
safeCheckRecordHeader(byte[] recordHeader) |
protected void |
safeReadRecord() |
protected void |
safeWriteRecord(short type,
byte[] buf,
int offset,
int len) |
protected void |
sendCertificateMessage(Certificate certificate) |
protected void |
sendChangeCipherSpecMessage() |
protected void |
sendFinishedMessage() |
protected void |
sendSupplementalDataMessage(java.util.Vector supplementalData) |
protected void |
setAppDataSplitMode(int appDataSplitMode) |
protected void |
writeData(byte[] buf,
int offset,
int len)
Send some application data to the remote system.
|
protected static void |
writeExtensions(java.io.OutputStream output,
java.util.Hashtable extensions) |
protected void |
writeHandshakeMessage(byte[] buf,
int off,
int len) |
protected static void |
writeSelectedExtensions(java.io.OutputStream output,
java.util.Hashtable extensions,
boolean selectEmpty) |
protected static void |
writeSupplementalData(java.io.OutputStream output,
java.util.Vector supplementalData) |
protected static final java.lang.Integer EXT_RenegotiationInfo
protected static final java.lang.Integer EXT_SessionTicket
protected static final short CS_START
protected static final short CS_CLIENT_HELLO
protected static final short CS_SERVER_HELLO
protected static final short CS_SERVER_SUPPLEMENTAL_DATA
protected static final short CS_SERVER_CERTIFICATE
protected static final short CS_CERTIFICATE_STATUS
protected static final short CS_SERVER_KEY_EXCHANGE
protected static final short CS_CERTIFICATE_REQUEST
protected static final short CS_SERVER_HELLO_DONE
protected static final short CS_CLIENT_SUPPLEMENTAL_DATA
protected static final short CS_CLIENT_CERTIFICATE
protected static final short CS_CLIENT_KEY_EXCHANGE
protected static final short CS_CERTIFICATE_VERIFY
protected static final short CS_CLIENT_FINISHED
protected static final short CS_SERVER_SESSION_TICKET
protected static final short CS_SERVER_FINISHED
protected static final short CS_END
protected static final short ADS_MODE_1_Nsub1
protected static final short ADS_MODE_0_N
protected static final short ADS_MODE_0_N_FIRSTONLY
protected java.security.SecureRandom secureRandom
protected TlsSession tlsSession
protected SessionParameters sessionParameters
protected SecurityParameters securityParameters
protected Certificate peerCertificate
protected int[] offeredCipherSuites
protected short[] offeredCompressionMethods
protected java.util.Hashtable clientExtensions
protected java.util.Hashtable serverExtensions
protected short connection_state
protected boolean resumedSession
protected boolean receivedChangeCipherSpec
protected boolean secure_renegotiation
protected boolean allowCertificateStatus
protected boolean expectSessionTicket
protected boolean blocking
protected ByteQueueInputStream inputBuffers
protected ByteQueueOutputStream outputBuffer
public TlsProtocol(java.io.InputStream input, java.io.OutputStream output, java.security.SecureRandom secureRandom)
public TlsProtocol(java.security.SecureRandom secureRandom)
protected abstract TlsContext getContext()
protected abstract TlsPeer getPeer()
protected void handleChangeCipherSpecMessage() throws java.io.IOException
java.io.IOException
protected abstract void handleHandshakeMessage(short type, java.io.ByteArrayInputStream buf) throws java.io.IOException
java.io.IOException
protected void handleWarningMessage(short description) throws java.io.IOException
java.io.IOException
protected void applyMaxFragmentLengthExtension() throws java.io.IOException
java.io.IOException
protected void checkReceivedChangeCipherSpec(boolean expected) throws java.io.IOException
java.io.IOException
protected void cleanupHandshake()
protected void blockForHandshake() throws java.io.IOException
java.io.IOException
protected void completeHandshake() throws java.io.IOException
java.io.IOException
protected void processRecord(short protocol, byte[] buf, int off, int len) throws java.io.IOException
java.io.IOException
protected int applicationDataAvailable()
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.protected void safeCheckRecordHeader(byte[] recordHeader) throws java.io.IOException
java.io.IOException
protected void safeReadRecord() throws java.io.IOException
java.io.IOException
protected void safeWriteRecord(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
The method will handle fragmentation internally.
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.protected void setAppDataSplitMode(int appDataSplitMode)
protected void writeHandshakeMessage(byte[] buf, int off, int len) throws java.io.IOException
java.io.IOException
public java.io.OutputStream getOutputStream()
public java.io.InputStream getInputStream()
public void closeInput() throws java.io.IOException
java.io.IOException
public void offerInput(byte[] input) throws java.io.IOException
readInput(byte[], int, int)
. If any records
containing protocol data were processed, a response may have been generated.
You should always check to see if there is any available output after calling
this method by calling getAvailableOutputBytes()
.input
- The input buffer to offerjava.io.IOException
- If an error occurs while decrypting or processing a recordpublic int getAvailableInputBytes()
readInput(byte[], int, int)
is guaranteed to be able to return at least this much data.public int readInput(byte[] buffer, int offset, int length)
getAvailableInputBytes()
to check
how much application data is currently available. This method functions similarly to
InputStream.read(byte[], int, int)
, except that it never blocks. If no data
is available, nothing will be copied and zero will be returned.buffer
- The buffer to hold the application dataoffset
- The start offset in the buffer at which the data is writtenlength
- The maximum number of bytes to readpublic void offerOutput(byte[] buffer, int offset, int length) throws java.io.IOException
readOutput(byte[], int, int)
to get the bytes to
transmit to the other peer.buffer
- The buffer containing application data to encryptoffset
- The offset at which to begin reading datalength
- The number of bytes of data to readjava.io.IOException
- If an error occurs encrypting the data, or the handshake is not completepublic int getAvailableOutputBytes()
readOutput(byte[], int, int)
is guaranteed to be able to return at
least this much data.public int readOutput(byte[] buffer, int offset, int length)
getAvailableOutputBytes()
to check
how much encrypted data is currently available. This method functions similarly to
InputStream.read(byte[], int, int)
, except that it never blocks. If no data
is available, nothing will be copied and zero will be returned.buffer
- The buffer to hold the encrypted dataoffset
- The start offset in the buffer at which the data is writtenlength
- The maximum number of bytes to readprotected void failWithError(short alertLevel, short alertDescription, java.lang.String message, java.lang.Throwable cause) throws java.io.IOException
alertLevel
- See AlertLevel
for values.alertDescription
- See AlertDescription
for values.java.io.IOException
- If alert was fatal.protected void invalidateSession()
protected void processFinishedMessage(java.io.ByteArrayInputStream buf) throws java.io.IOException
java.io.IOException
protected void raiseAlert(short alertLevel, short alertDescription, java.lang.String message, java.lang.Throwable cause) throws java.io.IOException
java.io.IOException
protected void raiseWarning(short alertDescription, java.lang.String message) throws java.io.IOException
java.io.IOException
protected void sendCertificateMessage(Certificate certificate) throws java.io.IOException
java.io.IOException
protected void sendChangeCipherSpecMessage() throws java.io.IOException
java.io.IOException
protected void sendFinishedMessage() throws java.io.IOException
java.io.IOException
protected void sendSupplementalDataMessage(java.util.Vector supplementalData) throws java.io.IOException
java.io.IOException
protected byte[] createVerifyData(boolean isServer)
public void close() throws java.io.IOException
java.io.IOException
- If something goes wrong during closing.protected void handleClose(boolean user_canceled) throws java.io.IOException
java.io.IOException
protected void flush() throws java.io.IOException
java.io.IOException
public boolean isClosed()
protected short processMaxFragmentLengthExtension(java.util.Hashtable clientExtensions, java.util.Hashtable serverExtensions, short alertDescription) throws java.io.IOException
java.io.IOException
protected void refuseRenegotiation() throws java.io.IOException
java.io.IOException
protected static void assertEmpty(java.io.ByteArrayInputStream buf) throws java.io.IOException
buf
- The InputStream to check.java.io.IOException
- If 'buf' is not empty.protected static byte[] createRandomBlock(boolean useGMTUnixTime, RandomGenerator randomGenerator)
protected static byte[] createRenegotiationInfo(byte[] renegotiated_connection) throws java.io.IOException
java.io.IOException
protected static void establishMasterSecret(TlsContext context, TlsKeyExchange keyExchange) throws java.io.IOException
java.io.IOException
protected static byte[] getCurrentPRFHash(TlsContext context, TlsHandshakeHash handshakeHash, byte[] sslSender)
protected static java.util.Hashtable readExtensions(java.io.ByteArrayInputStream input) throws java.io.IOException
java.io.IOException
protected static java.util.Vector readSupplementalDataMessage(java.io.ByteArrayInputStream input) throws java.io.IOException
java.io.IOException
protected static void writeExtensions(java.io.OutputStream output, java.util.Hashtable extensions) throws java.io.IOException
java.io.IOException
protected static void writeSelectedExtensions(java.io.OutputStream output, java.util.Hashtable extensions, boolean selectEmpty) throws java.io.IOException
java.io.IOException
protected static void writeSupplementalData(java.io.OutputStream output, java.util.Vector supplementalData) throws java.io.IOException
java.io.IOException
protected static int getPRFAlgorithm(TlsContext context, int ciphersuite) throws java.io.IOException
java.io.IOException