public abstract class TlsProtocol extends java.lang.Object implements TlsCloseable
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 |
blocking |
protected java.util.Hashtable |
clientExtensions |
protected short |
connection_state |
protected static short |
CS_CLIENT_CERTIFICATE |
protected static short |
CS_CLIENT_CERTIFICATE_VERIFY |
protected static short |
CS_CLIENT_END_OF_EARLY_DATA |
protected static short |
CS_CLIENT_FINISHED |
protected static short |
CS_CLIENT_HELLO |
protected static short |
CS_CLIENT_HELLO_RETRY |
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_CERTIFICATE_REQUEST |
protected static short |
CS_SERVER_CERTIFICATE_STATUS |
protected static short |
CS_SERVER_CERTIFICATE_VERIFY |
protected static short |
CS_SERVER_ENCRYPTED_EXTENSIONS |
protected static short |
CS_SERVER_FINISHED |
protected static short |
CS_SERVER_HELLO |
protected static short |
CS_SERVER_HELLO_DONE |
protected static short |
CS_SERVER_HELLO_RETRY_REQUEST |
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 ByteQueueOutputStream |
outputBuffer |
protected boolean |
receivedChangeCipherSpec |
protected byte[] |
retryCookie |
protected int |
retryGroup |
protected boolean |
selectedPSK13 |
protected java.util.Hashtable |
serverExtensions |
protected TlsSecret |
sessionMasterSecret |
protected SessionParameters |
sessionParameters |
protected TlsSession |
tlsSession |
Modifier | Constructor and Description |
---|---|
protected |
TlsProtocol() |
protected |
TlsProtocol(java.io.InputStream input,
java.io.OutputStream output) |
Modifier and Type | Method and Description |
---|---|
int |
applicationDataAvailable() |
protected void |
applyMaxFragmentLengthExtension(short maxFragmentLength) |
protected static void |
assertEmpty(java.io.ByteArrayInputStream buf)
Make sure the InputStream 'buf' now empty.
|
protected void |
beginHandshake(boolean renegotiation) |
protected void |
blockForHandshake() |
protected void |
cancelSession() |
protected void |
checkReceivedChangeCipherSpec(boolean expected) |
protected void |
cleanupHandshake() |
void |
close()
Closes this connection.
|
protected void |
closeConnection() |
void |
closeInput()
Should be called in non-blocking mode when the input data reaches EOF.
|
protected void |
completeHandshake() |
protected static byte[] |
createRandomBlock(boolean useGMTUnixTime,
TlsContext context) |
protected static byte[] |
createRenegotiationInfo(byte[] renegotiated_connection) |
protected static void |
establishMasterSecret(TlsContext context,
TlsKeyExchange keyExchange) |
protected boolean |
establishSession(TlsSession sessionToResume) |
void |
flush() |
int |
getAppDataSplitMode() |
int |
getApplicationDataLimit() |
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() |
java.io.InputStream |
getInputStream() |
java.io.OutputStream |
getOutputStream() |
protected abstract TlsPeer |
getPeer() |
protected int |
getRenegotiationPolicy() |
protected void |
handleAlertMessage(short alertLevel,
short alertDescription) |
protected void |
handleAlertWarningMessage(short alertDescription) |
protected void |
handleChangeCipherSpecMessage() |
protected void |
handleClose(boolean user_canceled) |
protected void |
handleException(short alertDescription,
java.lang.String message,
java.lang.Throwable e) |
protected void |
handleFailure() |
protected abstract void |
handleHandshakeMessage(short type,
HandshakeMessageInput buf) |
protected boolean |
handleRenegotiation() |
protected void |
invalidateSession() |
boolean |
isClosed() |
boolean |
isConnected() |
boolean |
isHandshaking() |
protected boolean |
isLegacyConnectionState() |
boolean |
isResumableHandshake() |
protected boolean |
isTLSv13ConnectionState() |
void |
offerInput(byte[] input)
Equivalent to
offerInput(input, 0, input.length) |
void |
offerInput(byte[] input,
int inputOff,
int inputLen)
Offer input from an arbitrary source.
|
RecordPreview |
previewInputRecord(byte[] recordHeader) |
int |
previewOutputRecord() |
RecordPreview |
previewOutputRecord(int applicationDataSize) |
protected void |
process13FinishedMessage(java.io.ByteArrayInputStream buf) |
protected void |
processFinishedMessage(java.io.ByteArrayInputStream buf) |
protected short |
processMaxFragmentLengthExtension(java.util.Hashtable clientExtensions,
java.util.Hashtable serverExtensions,
short alertDescription)
Deprecated.
Will be removed.
|
protected void |
processRecord(short protocol,
byte[] buf,
int off,
int len) |
protected void |
raiseAlertFatal(short alertDescription,
java.lang.String message,
java.lang.Throwable cause) |
protected void |
raiseAlertWarning(short alertDescription,
java.lang.String message) |
int |
readApplicationData(byte[] buf,
int off,
int len)
Read data from the network.
|
protected static java.util.Hashtable |
readExtensions(java.io.ByteArrayInputStream input) |
protected static java.util.Hashtable |
readExtensionsData(byte[] extBytes) |
protected static java.util.Hashtable |
readExtensionsData13(int handshakeType,
byte[] extBytes) |
protected static java.util.Hashtable |
readExtensionsDataClientHello(byte[] extBytes) |
int |
readInput(byte[] buffer,
int offset,
int length)
Retrieves received application data.
|
int |
readInput(java.nio.ByteBuffer buffer,
int length)
Retrieves received application data into a
ByteBuffer . |
int |
readOutput(byte[] buffer,
int offset,
int length)
Retrieves encrypted data to be sent.
|
int |
readOutput(java.nio.ByteBuffer buffer,
int length)
Retrieves encrypted data to be sent.
|
protected static java.util.Vector |
readSupplementalDataMessage(java.io.ByteArrayInputStream input) |
protected void |
receive13KeyUpdate(java.io.ByteArrayInputStream buf) |
protected void |
refuseRenegotiation() |
void |
resumeHandshake() |
protected RecordPreview |
safePreviewRecordHeader(byte[] recordHeader) |
protected boolean |
safeReadFullRecord(byte[] input,
int inputOff,
int inputLen) |
protected void |
safeReadRecord() |
protected void |
safeWriteRecord(short type,
byte[] buf,
int offset,
int len) |
protected void |
send13CertificateMessage(Certificate certificate) |
protected void |
send13CertificateVerifyMessage(DigitallySigned certificateVerify) |
protected void |
send13FinishedMessage() |
protected void |
send13KeyUpdate(boolean updateRequested) |
protected void |
sendCertificateMessage(Certificate certificate,
java.io.OutputStream endPointHash) |
protected void |
sendChangeCipherSpec() |
protected void |
sendChangeCipherSpecMessage() |
protected void |
sendFinishedMessage() |
protected void |
sendSupplementalDataMessage(java.util.Vector supplementalData) |
void |
setAppDataSplitMode(int appDataSplitMode) |
void |
setResumableHandshake(boolean resumableHandshake) |
void |
writeApplicationData(byte[] buf,
int off,
int len)
Write some application data.
|
protected static void |
writeExtensions(java.io.OutputStream output,
java.util.Hashtable extensions) |
protected static void |
writeExtensions(java.io.OutputStream output,
java.util.Hashtable extensions,
int bindersSize) |
protected static byte[] |
writeExtensionsData(java.util.Hashtable extensions) |
protected static byte[] |
writeExtensionsData(java.util.Hashtable extensions,
int bindersSize) |
protected static void |
writeExtensionsData(java.util.Hashtable extensions,
int bindersSize,
java.io.ByteArrayOutputStream buf) |
protected static void |
writePreSharedKeyExtension(java.io.OutputStream output,
java.util.Hashtable extensions,
int bindersSize) |
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_RETRY_REQUEST
protected static final short CS_CLIENT_HELLO_RETRY
protected static final short CS_SERVER_HELLO
protected static final short CS_SERVER_ENCRYPTED_EXTENSIONS
protected static final short CS_SERVER_SUPPLEMENTAL_DATA
protected static final short CS_SERVER_CERTIFICATE
protected static final short CS_SERVER_CERTIFICATE_STATUS
protected static final short CS_SERVER_CERTIFICATE_VERIFY
protected static final short CS_SERVER_KEY_EXCHANGE
protected static final short CS_SERVER_CERTIFICATE_REQUEST
protected static final short CS_SERVER_HELLO_DONE
protected static final short CS_CLIENT_END_OF_EARLY_DATA
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_CLIENT_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 TlsSession tlsSession
protected SessionParameters sessionParameters
protected TlsSecret sessionMasterSecret
protected byte[] retryCookie
protected int retryGroup
protected java.util.Hashtable clientExtensions
protected java.util.Hashtable serverExtensions
protected short connection_state
protected boolean selectedPSK13
protected boolean receivedChangeCipherSpec
protected boolean expectSessionTicket
protected boolean blocking
protected ByteQueueInputStream inputBuffers
protected ByteQueueOutputStream outputBuffer
protected TlsProtocol()
protected TlsProtocol(java.io.InputStream input, java.io.OutputStream output)
protected boolean isLegacyConnectionState()
protected boolean isTLSv13ConnectionState()
public void resumeHandshake() throws java.io.IOException
java.io.IOException
protected void closeConnection() throws java.io.IOException
java.io.IOException
protected abstract TlsContext getContext()
protected abstract TlsPeer getPeer()
protected int getRenegotiationPolicy()
protected void handleAlertMessage(short alertLevel, short alertDescription) throws java.io.IOException
java.io.IOException
protected void handleAlertWarningMessage(short alertDescription) throws java.io.IOException
java.io.IOException
protected void handleChangeCipherSpecMessage() throws java.io.IOException
java.io.IOException
protected void handleClose(boolean user_canceled) throws java.io.IOException
java.io.IOException
protected void handleException(short alertDescription, java.lang.String message, java.lang.Throwable e) throws java.io.IOException
java.io.IOException
protected void handleFailure() throws java.io.IOException
java.io.IOException
protected abstract void handleHandshakeMessage(short type, HandshakeMessageInput buf) throws java.io.IOException
java.io.IOException
protected boolean handleRenegotiation() throws java.io.IOException
java.io.IOException
protected void applyMaxFragmentLengthExtension(short maxFragmentLength) throws java.io.IOException
java.io.IOException
protected void checkReceivedChangeCipherSpec(boolean expected) throws java.io.IOException
java.io.IOException
protected void blockForHandshake() throws java.io.IOException
java.io.IOException
protected void beginHandshake(boolean renegotiation) throws java.io.IOException
java.io.IOException
protected void cleanupHandshake()
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
public int applicationDataAvailable()
public int readApplicationData(byte[] buf, int off, int len) throws java.io.IOException
buf
- The buffer where the data will be copied to.off
- 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 RecordPreview safePreviewRecordHeader(byte[] recordHeader) throws java.io.IOException
java.io.IOException
protected void safeReadRecord() throws java.io.IOException
java.io.IOException
protected boolean safeReadFullRecord(byte[] input, int inputOff, int inputLen) 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
public void writeApplicationData(byte[] buf, int off, int len) throws java.io.IOException
readOutput(byte[], int, int)
to get the output bytes to send to the peer.IllegalStateException
.buf
- The buffer containing application data to sendoff
- The offset at which the application data beginslen
- The number of bytes of application datajava.lang.IllegalStateException
- If called before the initial handshake has completed.java.io.IOException
- If connection is already closed, or for encryption or transport errors.public int getAppDataSplitMode()
public void setAppDataSplitMode(int appDataSplitMode)
public boolean isResumableHandshake()
public void setResumableHandshake(boolean resumableHandshake)
public java.io.OutputStream getOutputStream()
public java.io.InputStream getInputStream()
public void closeInput() throws java.io.IOException
java.io.IOException
public RecordPreview previewInputRecord(byte[] recordHeader) throws java.io.IOException
java.io.IOException
public int previewOutputRecord()
public RecordPreview previewOutputRecord(int applicationDataSize) throws java.io.IOException
java.io.IOException
public void offerInput(byte[] input) throws java.io.IOException
offerInput(input, 0, input.length)
input
- The input buffer to offerjava.io.IOException
- If an error occurs while decrypting or processing a recordofferInput(byte[], int, int)
public void offerInput(byte[] input, int inputOff, int inputLen) 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 offerinputOff
- The offset within the input buffer that input beginsinputLen
- The number of bytes of input being offeredjava.io.IOException
- If an error occurs while decrypting or processing a recordpublic int getApplicationDataLimit()
public 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 int readInput(java.nio.ByteBuffer buffer, int length)
ByteBuffer
. Use 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 ByteBuffer
to hold the application datalength
- The maximum number of bytes to readpublic 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 readpublic int readOutput(java.nio.ByteBuffer buffer, 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 ByteBuffer
to hold the encrypted datalength
- The maximum number of bytes to readprotected boolean establishSession(TlsSession sessionToResume)
protected void cancelSession()
protected void invalidateSession()
protected void processFinishedMessage(java.io.ByteArrayInputStream buf) throws java.io.IOException
java.io.IOException
protected void process13FinishedMessage(java.io.ByteArrayInputStream buf) throws java.io.IOException
java.io.IOException
protected void raiseAlertFatal(short alertDescription, java.lang.String message, java.lang.Throwable cause) throws java.io.IOException
java.io.IOException
protected void raiseAlertWarning(short alertDescription, java.lang.String message) throws java.io.IOException
java.io.IOException
protected void receive13KeyUpdate(java.io.ByteArrayInputStream buf) throws java.io.IOException
java.io.IOException
protected void sendCertificateMessage(Certificate certificate, java.io.OutputStream endPointHash) throws java.io.IOException
java.io.IOException
protected void send13CertificateMessage(Certificate certificate) throws java.io.IOException
java.io.IOException
protected void send13CertificateVerifyMessage(DigitallySigned certificateVerify) throws java.io.IOException
java.io.IOException
protected void sendChangeCipherSpec() 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 send13FinishedMessage() throws java.io.IOException
java.io.IOException
protected void send13KeyUpdate(boolean updateRequested) throws java.io.IOException
java.io.IOException
protected void sendSupplementalDataMessage(java.util.Vector supplementalData) throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
close
in interface TlsCloseable
java.io.IOException
- If something goes wrong during closing.public void flush() throws java.io.IOException
java.io.IOException
public boolean isClosed()
public boolean isConnected()
public boolean isHandshaking()
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, TlsContext context)
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 java.util.Hashtable readExtensions(java.io.ByteArrayInputStream input) throws java.io.IOException
java.io.IOException
protected static java.util.Hashtable readExtensionsData(byte[] extBytes) throws java.io.IOException
java.io.IOException
protected static java.util.Hashtable readExtensionsData13(int handshakeType, byte[] extBytes) throws java.io.IOException
java.io.IOException
protected static java.util.Hashtable readExtensionsDataClientHello(byte[] extBytes) 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 writeExtensions(java.io.OutputStream output, java.util.Hashtable extensions, int bindersSize) throws java.io.IOException
java.io.IOException
protected static byte[] writeExtensionsData(java.util.Hashtable extensions) throws java.io.IOException
java.io.IOException
protected static byte[] writeExtensionsData(java.util.Hashtable extensions, int bindersSize) throws java.io.IOException
java.io.IOException
protected static void writeExtensionsData(java.util.Hashtable extensions, int bindersSize, java.io.ByteArrayOutputStream buf) throws java.io.IOException
java.io.IOException
protected static void writePreSharedKeyExtension(java.io.OutputStream output, java.util.Hashtable extensions, int bindersSize) 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