Package org.bouncycastle.tls
Class TlsClientProtocol
- java.lang.Object
-
- org.bouncycastle.tls.TlsProtocol
-
- org.bouncycastle.tls.TlsClientProtocol
-
- All Implemented Interfaces:
TlsCloseable
public class TlsClientProtocol extends TlsProtocol
-
-
Field Summary
Fields Modifier and Type Field Description protected TlsAuthentication
authentication
protected CertificateRequest
certificateRequest
protected CertificateStatus
certificateStatus
protected java.util.Hashtable
clientAgreements
protected ClientHello
clientHello
protected TlsKeyExchange
keyExchange
protected TlsClient
tlsClient
-
Fields inherited from class org.bouncycastle.tls.TlsProtocol
ADS_MODE_0_N, ADS_MODE_0_N_FIRSTONLY, ADS_MODE_1_Nsub1, blocking, clientExtensions, connection_state, CS_CLIENT_CERTIFICATE, CS_CLIENT_CERTIFICATE_VERIFY, CS_CLIENT_END_OF_EARLY_DATA, CS_CLIENT_FINISHED, CS_CLIENT_HELLO, CS_CLIENT_HELLO_RETRY, CS_CLIENT_KEY_EXCHANGE, CS_CLIENT_SUPPLEMENTAL_DATA, CS_END, CS_SERVER_CERTIFICATE, CS_SERVER_CERTIFICATE_REQUEST, CS_SERVER_CERTIFICATE_STATUS, CS_SERVER_CERTIFICATE_VERIFY, CS_SERVER_ENCRYPTED_EXTENSIONS, CS_SERVER_FINISHED, CS_SERVER_HELLO, CS_SERVER_HELLO_DONE, CS_SERVER_HELLO_RETRY_REQUEST, CS_SERVER_KEY_EXCHANGE, CS_SERVER_SESSION_TICKET, CS_SERVER_SUPPLEMENTAL_DATA, CS_START, expectSessionTicket, EXT_RenegotiationInfo, EXT_SessionTicket, inputBuffers, outputBuffer, receivedChangeCipherSpec, resumedSession, retryCookie, retryGroup, serverExtensions, sessionMasterSecret, sessionParameters, tlsSession
-
-
Constructor Summary
Constructors Constructor Description TlsClientProtocol()
Constructor for non-blocking mode.
When data is received, useTlsProtocol.offerInput(byte[])
to provide the received ciphertext, then useTlsProtocol.readInput(byte[], int, int)
to read the corresponding cleartext.
Similarly, when data needs to be sent, useTlsProtocol.writeApplicationData(byte[], int, int)
to provide the cleartext, then useTlsProtocol.readOutput(byte[], int, int)
to get the corresponding ciphertext.TlsClientProtocol(java.io.InputStream input, java.io.OutputStream output)
Constructor for blocking mode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
beginHandshake()
protected void
cleanupHandshake()
void
connect(TlsClient tlsClient)
Initiates a TLS handshake in the role of client.
In blocking mode, this will not return until the handshake is complete.protected TlsContext
getContext()
protected TlsPeer
getPeer()
protected void
handle13HandshakeMessage(short type, org.bouncycastle.tls.HandshakeMessageInput buf)
protected void
handleHandshakeMessage(short type, org.bouncycastle.tls.HandshakeMessageInput buf)
protected void
handleServerCertificate()
protected void
handleSupplementalData(java.util.Vector serverSupplementalData)
protected void
process13HelloRetryRequest(ServerHello helloRetryRequest)
protected void
process13ServerHello(ServerHello serverHello, boolean afterHelloRetryRequest)
protected void
process13ServerHelloCoda(ServerHello serverHello, boolean afterHelloRetryRequest)
protected void
processServerHello(ServerHello serverHello)
protected void
receive13CertificateRequest(java.io.ByteArrayInputStream buf, boolean postHandshakeAuth)
protected void
receive13EncryptedExtensions(java.io.ByteArrayInputStream buf)
protected void
receive13NewSessionTicket(java.io.ByteArrayInputStream buf)
protected void
receive13ServerCertificate(java.io.ByteArrayInputStream buf)
protected void
receive13ServerCertificateVerify(java.io.ByteArrayInputStream buf)
protected void
receive13ServerFinished(java.io.ByteArrayInputStream buf)
protected void
receiveCertificateRequest(java.io.ByteArrayInputStream buf)
protected void
receiveNewSessionTicket(java.io.ByteArrayInputStream buf)
protected ServerHello
receiveServerHelloMessage(java.io.ByteArrayInputStream buf)
protected void
send13ClientHelloRetry()
protected void
sendCertificateVerifyMessage(DigitallySigned certificateVerify)
protected void
sendClientHello()
protected void
sendClientHelloMessage()
protected void
sendClientKeyExchange()
protected void
skip13CertificateRequest()
protected void
skip13ServerCertificate()
-
Methods inherited from class org.bouncycastle.tls.TlsProtocol
applicationDataAvailable, applyMaxFragmentLengthExtension, assertEmpty, blockForHandshake, checkReceivedChangeCipherSpec, close, closeConnection, closeInput, completeHandshake, createRandomBlock, createRenegotiationInfo, establishMasterSecret, establishSession, flush, getAppDataSplitMode, getApplicationDataLimit, getAvailableInputBytes, getAvailableOutputBytes, getInputStream, getOutputStream, handleAlertMessage, handleAlertWarningMessage, handleChangeCipherSpecMessage, handleClose, handleException, handleFailure, invalidateSession, isClosed, isHandshaking, isLegacyConnectionState, isResumableHandshake, isTLSv13ConnectionState, offerInput, offerInput, previewInputRecord, previewOutputRecord, process13FinishedMessage, processFinishedMessage, processMaxFragmentLengthExtension, processRecord, raiseAlertFatal, raiseAlertWarning, readApplicationData, readExtensions, readExtensionsData, readExtensionsData13, readExtensionsDataClientHello, readInput, readOutput, readSupplementalDataMessage, receive13KeyUpdate, refuseRenegotiation, resumeHandshake, safePreviewRecordHeader, safeReadFullRecord, safeReadRecord, safeWriteRecord, send13CertificateMessage, send13CertificateVerifyMessage, send13FinishedMessage, send13KeyUpdate, sendCertificateMessage, sendChangeCipherSpec, sendChangeCipherSpecMessage, sendFinishedMessage, sendSupplementalDataMessage, setAppDataSplitMode, setResumableHandshake, writeApplicationData, writeExtensions, writeExtensionsData, writeExtensionsData, writeHandshakeMessage, writeSelectedExtensions, writeSupplementalData
-
-
-
-
Field Detail
-
tlsClient
protected TlsClient tlsClient
-
clientAgreements
protected java.util.Hashtable clientAgreements
-
clientHello
protected ClientHello clientHello
-
keyExchange
protected TlsKeyExchange keyExchange
-
authentication
protected TlsAuthentication authentication
-
certificateStatus
protected CertificateStatus certificateStatus
-
certificateRequest
protected CertificateRequest certificateRequest
-
-
Constructor Detail
-
TlsClientProtocol
public TlsClientProtocol()
Constructor for non-blocking mode.
When data is received, useTlsProtocol.offerInput(byte[])
to provide the received ciphertext, then useTlsProtocol.readInput(byte[], int, int)
to read the corresponding cleartext.
Similarly, when data needs to be sent, useTlsProtocol.writeApplicationData(byte[], int, int)
to provide the cleartext, then useTlsProtocol.readOutput(byte[], int, int)
to get the corresponding ciphertext.
-
TlsClientProtocol
public TlsClientProtocol(java.io.InputStream input, java.io.OutputStream output)
Constructor for blocking mode.- Parameters:
input
- The stream of data from the serveroutput
- The stream of data to the server
-
-
Method Detail
-
connect
public void connect(TlsClient tlsClient) throws java.io.IOException
Initiates a TLS handshake in the role of client.
In blocking mode, this will not return until the handshake is complete. In non-blocking mode, useTlsPeer.notifyHandshakeComplete()
to receive a callback when the handshake is complete.- Parameters:
tlsClient
- TheTlsClient
to use for the handshake.- Throws:
java.io.IOException
- If in blocking mode and handshake was not successful.
-
beginHandshake
protected void beginHandshake() throws java.io.IOException
- Overrides:
beginHandshake
in classTlsProtocol
- Throws:
java.io.IOException
-
cleanupHandshake
protected void cleanupHandshake()
- Overrides:
cleanupHandshake
in classTlsProtocol
-
getContext
protected TlsContext getContext()
- Specified by:
getContext
in classTlsProtocol
-
getPeer
protected TlsPeer getPeer()
- Specified by:
getPeer
in classTlsProtocol
-
handle13HandshakeMessage
protected void handle13HandshakeMessage(short type, org.bouncycastle.tls.HandshakeMessageInput buf) throws java.io.IOException
- Throws:
java.io.IOException
-
handleHandshakeMessage
protected void handleHandshakeMessage(short type, org.bouncycastle.tls.HandshakeMessageInput buf) throws java.io.IOException
- Specified by:
handleHandshakeMessage
in classTlsProtocol
- Throws:
java.io.IOException
-
handleServerCertificate
protected void handleServerCertificate() throws java.io.IOException
- Throws:
java.io.IOException
-
handleSupplementalData
protected void handleSupplementalData(java.util.Vector serverSupplementalData) throws java.io.IOException
- Throws:
java.io.IOException
-
process13HelloRetryRequest
protected void process13HelloRetryRequest(ServerHello helloRetryRequest) throws java.io.IOException
- Throws:
java.io.IOException
-
process13ServerHello
protected void process13ServerHello(ServerHello serverHello, boolean afterHelloRetryRequest) throws java.io.IOException
- Throws:
java.io.IOException
-
process13ServerHelloCoda
protected void process13ServerHelloCoda(ServerHello serverHello, boolean afterHelloRetryRequest) throws java.io.IOException
- Throws:
java.io.IOException
-
processServerHello
protected void processServerHello(ServerHello serverHello) throws java.io.IOException
- Throws:
java.io.IOException
-
receive13CertificateRequest
protected void receive13CertificateRequest(java.io.ByteArrayInputStream buf, boolean postHandshakeAuth) throws java.io.IOException
- Throws:
java.io.IOException
-
receive13EncryptedExtensions
protected void receive13EncryptedExtensions(java.io.ByteArrayInputStream buf) throws java.io.IOException
- Throws:
java.io.IOException
-
receive13NewSessionTicket
protected void receive13NewSessionTicket(java.io.ByteArrayInputStream buf) throws java.io.IOException
- Throws:
java.io.IOException
-
receive13ServerCertificate
protected void receive13ServerCertificate(java.io.ByteArrayInputStream buf) throws java.io.IOException
- Throws:
java.io.IOException
-
receive13ServerCertificateVerify
protected void receive13ServerCertificateVerify(java.io.ByteArrayInputStream buf) throws java.io.IOException
- Throws:
java.io.IOException
-
receive13ServerFinished
protected void receive13ServerFinished(java.io.ByteArrayInputStream buf) throws java.io.IOException
- Throws:
java.io.IOException
-
receiveCertificateRequest
protected void receiveCertificateRequest(java.io.ByteArrayInputStream buf) throws java.io.IOException
- Throws:
java.io.IOException
-
receiveNewSessionTicket
protected void receiveNewSessionTicket(java.io.ByteArrayInputStream buf) throws java.io.IOException
- Throws:
java.io.IOException
-
receiveServerHelloMessage
protected ServerHello receiveServerHelloMessage(java.io.ByteArrayInputStream buf) throws java.io.IOException
- Throws:
java.io.IOException
-
send13ClientHelloRetry
protected void send13ClientHelloRetry() throws java.io.IOException
- Throws:
java.io.IOException
-
sendCertificateVerifyMessage
protected void sendCertificateVerifyMessage(DigitallySigned certificateVerify) throws java.io.IOException
- Throws:
java.io.IOException
-
sendClientHello
protected void sendClientHello() throws java.io.IOException
- Throws:
java.io.IOException
-
sendClientHelloMessage
protected void sendClientHelloMessage() throws java.io.IOException
- Throws:
java.io.IOException
-
sendClientKeyExchange
protected void sendClientKeyExchange() throws java.io.IOException
- Throws:
java.io.IOException
-
skip13CertificateRequest
protected void skip13CertificateRequest() throws java.io.IOException
- Throws:
java.io.IOException
-
skip13ServerCertificate
protected void skip13ServerCertificate() throws java.io.IOException
- Throws:
java.io.IOException
-
-