public class SSLTransport extends java.lang.Object implements TLS13Communication
SSLTransportSpi
class or typically on sockets using the Java socket using SSLSocket.
For more information see the documentation in your installation directory.
Note that the SSL/TLS handshake is not started immediately when the transport object is created but only when one of the following methods is called:
SSLContext,
SSLSocket,
SSLTransportSpi| Constructor and Description |
|---|
SSLTransport(SSLTransportSpi transportSpi)
Creates a SSLTransport with the given spi implementation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close this SSL socket.
|
void |
debug(java.lang.String msg)
Writes debug information to a debug stream.
|
void |
debug(java.lang.Throwable e) |
CipherSuite |
getActiveCipherSuite()
Returns the active cipher suite.
|
CompressionMethod |
getActiveCompressionMethod()
Returns the active compression method.
|
ExtensionList |
getActiveExtensions()
Gets the active TLS extensions of the current TLS session.
|
int |
getActiveProtocolVersion()
Return the active SSL protocol version.
|
ChannelBindings |
getChannelBindings()
Gets any ChannelBindings associated with this Handshaker.
|
SSLContext |
getContext()
Returns the SSLContext of this SSLSocket.
|
java.io.InputStream |
getInputStream()
Returns an input stream for this socket.
|
java.io.OutputStream |
getOutputStream()
Returns an output stream for this socket.
|
java.security.cert.X509Certificate[] |
getPeerCertificateChain()
Returns the certificate chain sent by the peer or null if the peer
has no certificate.
|
ExtensionList |
getPeerExtensions()
Gets the TLS extensions received from the peer.
|
CipherSuiteList |
getPeerSupportedCipherSuiteList()
Return the list of cipher suites known to be supported by the remote peer.
|
CompressionMethod[] |
getPeerSupportedCompressionMethods()
Return the compression methods supported by the remote peer.
|
java.lang.String |
getPSKIdentity()
Returns the PSK identity used for identifying the pre-shared
key or
null if no PSK cipher suite is used for
the communication. |
java.net.InetAddress |
getRemoteInetAddress()
Returns the peer's
InetAddress. |
java.lang.Object |
getRemotePeerId()
Get an object uniquely identifying the remote peer for the
session manager.
|
java.lang.String |
getRemotePeerName() |
Session |
getSession()
Returns the currently active Session for this SSLSocket.
|
boolean |
getUseClientMode()
Returns whether or not this socket resides on the client
side of the connection.
|
void |
postHandshake(TLS13PostHandshakeConfig postHandshakeConfig)
Performs a TLS 1.3 post handshake.
|
void |
renegotiate()
Start a renegotiating SSL handshake.
|
void |
setAutoHandshake(boolean on)
Can be used to switch off the automatic start of the handshake procedure.
|
void |
setDebugStream(java.io.OutputStream os)
Enables debugging mode.
|
void |
setDebugStream(java.io.Writer writer)
Enables debugging mode.
|
void |
setUseClientMode(boolean mode)
Select client or server mode for this socket.
|
void |
shutdown()
Shuts the SSL layer down.
|
void |
startHandshake()
Start the SSL handshake process.
|
public SSLTransport(SSLTransportSpi transportSpi) throws java.io.IOException
transportSpi - the underlying transport protocol implementationif - an I/O problem occurs when initializing this SSLTransportjava.io.IOExceptionpublic void setUseClientMode(boolean mode)
throws java.io.IOException
SSLCommunicationThis selection can only be made prior to the initial SSL handshake. If the method is called made afterwards an SSLException is thrown.
setUseClientMode in interface SSLCommunicationjava.io.IOExceptionpublic boolean getUseClientMode()
SSLCommunicationgetUseClientMode in interface SSLCommunicationpublic java.lang.String getRemotePeerName()
public java.net.InetAddress getRemoteInetAddress()
InetAddress.public java.lang.Object getRemotePeerId()
public SSLContext getContext()
SSLCommunicationgetContext in interface SSLCommunicationpublic void setAutoHandshake(boolean on)
SSLCommunicationIf auto handshake is switched off the application has to start the handshaking process manually using the method startHandshake(). This kind of operation is used when connecting over a proxy or firewall.
setAutoHandshake in interface SSLCommunicationon - true if handshake should start automatically, false otherwiseSSLCommunication.startHandshake()public java.security.cert.X509Certificate[] getPeerCertificateChain()
SSLCommunicationIn SSLv2 this will always just return the server's certificate (protocol limitation). Note that some SSLv3/TLS server do not include self signed certificates as those will have to be obtained and verified using a different method anyway.
getPeerCertificateChain in interface SSLCommunicationpublic java.lang.String getPSKIdentity()
null if no PSK cipher suite is used for
the communication.getPSKIdentity in interface TLSCommunicationnull if no PSK cipher
suite is used for the communicationpublic ExtensionList getActiveExtensions()
peer extensions.
Note the extensions are cloned before returned by this method. Since cloning may be an expensive operation, you may call this method only if required.
getActiveExtensions in interface TLSCommunicationnull
if no extensions are usedpublic ExtensionList getPeerExtensions()
Note the extensions are cloned before returned by this method. Since cloning may be an expensive operation, you may call this method only if required.
getPeerExtensions in interface TLSCommunicationnull
if the peer did not sent any extensionspublic int getActiveProtocolVersion()
SSLCommunicationgetActiveProtocolVersion in interface SSLCommunicationSSLContextpublic CipherSuite getActiveCipherSuite()
SSLCommunicationgetActiveCipherSuite in interface SSLCommunicationCipherSuitepublic CompressionMethod getActiveCompressionMethod()
SSLCommunicationgetActiveCompressionMethod in interface SSLCommunicationCompressionMethodpublic CipherSuiteList getPeerSupportedCipherSuiteList()
SSLCommunicationgetPeerSupportedCipherSuiteList in interface SSLCommunicationCipherSuite,
SSLCommunication.getActiveCipherSuite()public CompressionMethod[] getPeerSupportedCompressionMethods()
SSLCommunicationgetPeerSupportedCipherSuiteList(), see there with
the exception of the SSLv2 case. As there are no compression
in SSLv2 the empty array is returned.getPeerSupportedCompressionMethods in interface SSLCommunicationCompressionMethod,
SSLCommunication.getActiveCompressionMethod()public Session getSession()
SSLCommunicationgetSession in interface SSLCommunicationpublic ChannelBindings getChannelBindings()
getChannelBindings in interface TLSCommunicationnull if no channel bindings are
available (e.g. if the application does not have
announced interest in channel bindings.public void renegotiate()
throws java.io.IOException
SSLCommunicationgetSession().invalidate() before
calling renegotiate, see below for more information.
Basically there are two reasons you might want to initiate renegotiation:
This method locks the InputStream and the OutputStream for exclusive access before proceeding with the handshake. That means that for the duration of the handshake procedure no communication is possible and more importantly that the handshake can not begin until possible blocking read() and write() calls by other threads have completed.
renegotiate in interface SSLCommunicationjava.io.IOException - if an error occurs during the handshake procedurepublic void startHandshake()
throws java.io.IOException
SSLCommunicationThis method locks the InputStream and the OutputStream for exclusive access before proceeding with the handshake. That means that for the duration of the handshake procedure no communication is possible and more importantly that the handshake can not begin until possible blocking read() and write() calls by other threads have completed.
startHandshake in interface SSLCommunicationjava.io.IOException - if an error occurs during the handshake procedureSSLCommunication.setAutoHandshake(boolean)public void postHandshake(TLS13PostHandshakeConfig postHandshakeConfig) throws java.io.IOException
This method may be called by an application to trigger some
post handshake action. The given post handshake configuration specifies the type of post handshake
to be performed (either NEW_SESSION_TICKET
to send a new session ticket to the client,
POST_HANDSHAKE_AUTH to
request post client authentication, or KEY_UPDATE
to perform a key update) and may provide some configuration options.
Sending a new session ticket or requesting post client authentication may
be only triggered on the server side, a key update may be done on both, client
or server side.
postHandshake in interface TLS13CommunicationpostHandshakeConfig - the post handshake configurationjava.io.IOException - if the requested post handshake action is not suitable for the local
connection end, handshake state or protocol version, or some error occurs when
performing the post handshakepublic java.io.OutputStream getOutputStream()
throws java.io.IOException
SSLCommunicationgetOutputStream in interface SSLCommunicationjava.io.IOException - if an error occurs when creating the output streampublic java.io.InputStream getInputStream()
throws java.io.IOException
SSLCommunicationgetInputStream in interface SSLCommunicationjava.io.IOException - if an error occurs when creating the input stream.public void close()
throws java.io.IOException
SSLCommunicationThis method will never be called by the library itself, it will always just call shutdown(). It is the responsibility of the application to always close the socket when communication has been completed. Once the socket has been closed read() and write() calls will throw SocketExceptions. The behaviour described here is compatible with the original Java sockets.
close in interface SSLCommunicationjava.io.IOExceptionpublic void shutdown()
throws java.io.IOException
SSLCommunicationA SSL layer shutdown occurs in the following cases:
shutdown in interface SSLCommunicationjava.io.IOException - if an I/O error occurs when closing this SSLSocketpublic void debug(java.lang.String msg)
msg - the debug messagepublic void debug(java.lang.Throwable e)
public void setDebugStream(java.io.Writer writer)
SSLCommunicationsetDebugStream in interface SSLCommunicationwriter - the Writer to which debug information shall be writtenpublic void setDebugStream(java.io.OutputStream os)
SSLCommunicationsetDebugStream in interface SSLCommunicationos - the OutputStream to which debug information shall be written