Top Description Inners Fields Constructors Methods
sun.security.ssl

public final Class SSLSocketImpl

extends BaseSSLSocketImpl
implements SSLTransport
Class Inheritance
All Implemented Interfaces
sun.security.ssl.SSLTransport
Imports
java.io.EOFException, .IOException, .InputStream, .InterruptedIOException, .OutputStream, java.net.InetAddress, .InetSocketAddress, .Socket, .SocketAddress, .SocketException, java.nio.ByteBuffer, java.util.List, java.util.concurrent.TimeUnit, java.util.concurrent.locks.ReentrantLock, java.util.function.BiFunction, javax.net.ssl.HandshakeCompletedListener, .SSLException, .SSLHandshakeException, .SSLParameters, .SSLProtocolException, .SSLServerSocket, .SSLSession, .SSLSocket, jdk.internal.access.JavaNetInetAddressAccess, .SharedSecrets

Implementation of an SSL socket.

This is a normal connection type socket, implementing SSL over some lower level socket, such as TCP. Because it is layered over some lower level socket, it MUST override all default socket methods.

This API offers a non-traditional option for establishing SSL connections. You may first establish the connection directly, then pass that connection to the SSL socket constructor with a flag saying which role should be taken in the handshake protocol. (The two ends of the connection must not choose the same role!) This allows setup of SSL proxying or tunneling, and also allows the kind of "role reversal" that is required for most FTP data transfers.

Author
David Brownell
See Also
javax.net.ssl.SSLSocket, SSLServerSocket

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
SSLSocketImpl.AppInputStream

InputStream for application data as returned by SSLSocket.getInputStream().

private class
SSLSocketImpl.AppOutputStream

OutputStream for application data as returned by SSLSocket.getOutputStream().

Field Summary

Modifier and TypeField and Description
private final SSLSocketImpl.AppInputStream
private final SSLSocketImpl.AppOutputStream
private boolean
pack-priv final TransportContext
private static final int
private final ReentrantLock
private boolean
private String
private final ReentrantLock
pack-priv final SSLContextImpl
sslContext

ERROR HANDLING GUIDELINES (which exceptions to throw and catch and which not to throw and catch) - if there is an IOException (SocketException) when accessing the underlying Socket, pass it through - do not throw IOExceptions, throw SSLExceptions (or a subclass)

private volatile boolean
private static final boolean
Inherited from sun.security.ssl.BaseSSLSocketImpl:
requireCloseNotify

Constructor Summary

AccessConstructor and Description
pack-priv
SSLSocketImpl(SSLContextImpl sslContext)

Package-private constructor used to instantiate an unconnected socket.

pack-priv
SSLSocketImpl(SSLContextImpl sslContext, SSLConfiguration sslConfig)

Package-private constructor used to instantiate a server socket.

pack-priv
SSLSocketImpl(SSLContextImpl sslContext, String peerHost, int peerPort)

Constructs an SSL connection to a named host at a specified port, using the authentication context provided.

pack-priv
SSLSocketImpl(SSLContextImpl sslContext, InetAddress address, int peerPort)

Constructs an SSL connection to a server at a specified address, and TCP port, using the authentication context provided.

pack-priv
SSLSocketImpl(SSLContextImpl sslContext, String peerHost, int peerPort, InetAddress localAddr, int localPort)

Constructs an SSL connection to a named host at a specified port, using the authentication context provided.

pack-priv
SSLSocketImpl(SSLContextImpl sslContext, InetAddress peerAddr, int peerPort, InetAddress localAddr, int localPort)

Constructs an SSL connection to a server at a specified address, and TCP port, using the authentication context provided.

pack-priv
SSLSocketImpl(SSLContextImpl sslContext, Socket sock, InputStream consumed, boolean autoClose)

Creates a server mode Socket layered over an existing connected socket, and is able to read data which has already been consumed/removed from the Socket's underlying InputStream.

pack-priv
SSLSocketImpl(SSLContextImpl sslContext, Socket sock, String peerHost, int port, boolean autoClose)

Layer SSL traffic over an existing connection, rather than creating a new connection.

Method Summary

Modifier and TypeMethod and Description
public void
addHandshakeCompletedListener(HandshakeCompletedListener
the HandShake Completed event listener
listener
)

Implements abstract javax.net.ssl.SSLSocket.addHandshakeCompletedListener.

Registers an event listener to receive notifications that an SSL handshake has completed on this connection.

private void
bruteForceCloseInput(boolean hasCloseReceipt)

Brute force close the input bound.

public void
close()

Overrides sun.security.ssl.BaseSSLSocketImpl.close.

Implements java.io.Closeable.close.

Closes this socket.

pack-priv void
closeNotify(boolean useUserCanceled)

private void
closeSocket(boolean selfInitiated)

public void
connect(SocketAddress
the SocketAddress
endpoint
,
int
the timeout value to be used in milliseconds.
timeout
)

Overrides java.net.Socket.connect.

Connects this socket to the server with a specified timeout value.

private Plaintext
decode(ByteBuffer destination)

private void
deliverClosedNotify(boolean useUserCanceled)

pack-priv void
doneConnect()

Initialize the handshaker and socket streams.

private void
duplexCloseInput()

Duplex close, start from closing inbound.

private void
duplexCloseOutput()

Duplex close, start from closing outbound.

private void
ensureNegotiated(boolean resumable)

public String
getApplicationProtocol()

Overrides javax.net.ssl.SSLSocket.getApplicationProtocol.

Returns the most recent application protocol value negotiated for this connection.

public String[]
getEnabledCipherSuites()

Implements abstract javax.net.ssl.SSLSocket.getEnabledCipherSuites.

Returns the names of the SSL cipher suites which are currently enabled for use on this connection.

public String[]
getEnabledProtocols()

Implements abstract javax.net.ssl.SSLSocket.getEnabledProtocols.

Returns the names of the protocol versions which are currently enabled for use on this connection.

public boolean
getEnableSessionCreation()

Implements abstract javax.net.ssl.SSLSocket.getEnableSessionCreation.

Returns true if new SSL sessions may be established by this socket.

public String
getHandshakeApplicationProtocol()

Overrides javax.net.ssl.SSLSocket.getHandshakeApplicationProtocol.

Returns the application protocol value negotiated on a SSL/TLS handshake currently in progress.

public BiFunction<SSLSocket, List<String>, String>
getHandshakeApplicationProtocolSelector()

Overrides javax.net.ssl.SSLSocket.getHandshakeApplicationProtocolSelector.

Retrieves the callback function that selects an application protocol value during a SSL/TLS/DTLS handshake.

public SSLSession
getHandshakeSession()

Overrides javax.net.ssl.SSLSocket.getHandshakeSession.

Returns the SSLSession being constructed during a SSL/TLS handshake.

public InputStream
getInputStream()

Overrides sun.security.ssl.BaseSSLSocketImpl.getInputStream.

Returns an input stream for this socket.

public boolean
getNeedClientAuth()

Implements abstract javax.net.ssl.SSLSocket.getNeedClientAuth.

Returns true if the socket will require client authentication.

public OutputStream
getOutputStream()

Overrides sun.security.ssl.BaseSSLSocketImpl.getOutputStream.

Returns an output stream for this socket.

public String
getPeerHost()

Implements sun.security.ssl.SSLTransport.getPeerHost.

Returns the host name of the peer.

public int
getPeerPort()

Implements sun.security.ssl.SSLTransport.getPeerPort.

Returns the port number of the peer.

public SSLSession
getSession()

Implements abstract javax.net.ssl.SSLSocket.getSession.

Returns the SSL Session in use by this connection.

public SSLParameters
getSSLParameters()

Overrides javax.net.ssl.SSLSocket.getSSLParameters.

Returns the SSLParameters in effect for this SSLSocket.

public String[]
getSupportedCipherSuites()

Implements abstract javax.net.ssl.SSLSocket.getSupportedCipherSuites.

Returns the names of the cipher suites which could be enabled for use on this connection.

public String[]
getSupportedProtocols()

Implements abstract javax.net.ssl.SSLSocket.getSupportedProtocols.

Returns the names of the protocols which could be enabled for use on an SSL connection.

public boolean
getUseClientMode()

Implements abstract javax.net.ssl.SSLSocket.getUseClientMode.

Returns true if the socket is set to use client mode when handshaking.

public boolean
getWantClientAuth()

Implements abstract javax.net.ssl.SSLSocket.getWantClientAuth.

Returns true if the socket will request client authentication.

private Plaintext
private void
handleException(Exception cause)

Handle an exception.

public boolean
isClosed()

Overrides java.net.Socket.isClosed.

Returns the closed state of the socket.

public boolean
isInputShutdown()

Overrides sun.security.ssl.BaseSSLSocketImpl.isInputShutdown.

Returns the input state of the socket

public boolean
isOutputShutdown()

Overrides sun.security.ssl.BaseSSLSocketImpl.isOutputShutdown.

Returns the output state of the socket

private ByteBuffer
readApplicationRecord(ByteBuffer buffer)

Read application data record.

private int
readHandshakeRecord()

Read the initial handshake records.

public void
removeHandshakeCompletedListener(HandshakeCompletedListener
the HandShake Completed event listener
listener
)

Implements abstract javax.net.ssl.SSLSocket.removeHandshakeCompletedListener.

Removes a previously registered handshake completion listener.

public void
setEnabledCipherSuites(String[]
Names of all the cipher suites to enable
suites
)

Implements abstract javax.net.ssl.SSLSocket.setEnabledCipherSuites.

Sets the cipher suites enabled for use on this connection.

public void
setEnabledProtocols(String[]
Names of all the protocols to enable.
protocols
)

Implements abstract javax.net.ssl.SSLSocket.setEnabledProtocols.

Sets the protocol versions enabled for use on this connection.

public void
setEnableSessionCreation(boolean
true indicates that sessions may be created; this is the default. false indicates that an existing session must be resumed
flag
)

Implements abstract javax.net.ssl.SSLSocket.setEnableSessionCreation.

Controls whether new SSL sessions may be established by this socket.

public void
setHandshakeApplicationProtocolSelector(BiFunction<SSLSocket, List<String>, String>
the callback function, or null to de-register.
selector
)

Overrides javax.net.ssl.SSLSocket.setHandshakeApplicationProtocolSelector.

Registers a callback function that selects an application protocol value for a SSL/TLS/DTLS handshake.

public void
public void
setNeedClientAuth(boolean
set to true if client authentication is required, or false if no client authentication is desired.
need
)

Implements abstract javax.net.ssl.SSLSocket.setNeedClientAuth.

Configures the socket to require client authentication.

public void
setSSLParameters(SSLParameters
the parameters
params
)

Overrides javax.net.ssl.SSLSocket.setSSLParameters.

Applies SSLParameters to this socket.

public void
setUseClientMode(boolean
true if the socket should start its handshaking in "client" mode
mode
)

Implements abstract javax.net.ssl.SSLSocket.setUseClientMode.

Configures the socket to use client (or server) mode when handshaking.

public void
setWantClientAuth(boolean
set to true if client authentication is requested, or false if no client authentication is desired.
want
)

Implements abstract javax.net.ssl.SSLSocket.setWantClientAuth.

Configures the socket to request client authentication.

public void
shutdown()

Overrides default sun.security.ssl.SSLTransport.shutdown.

Shutdown the transport.

public void
shutdownInput()

Overrides sun.security.ssl.BaseSSLSocketImpl.shutdownInput.

Places the input stream for this socket at "end of stream".

private void
shutdownInput(boolean checkCloseNotify)

public void
shutdownOutput()

Overrides sun.security.ssl.BaseSSLSocketImpl.shutdownOutput.

Disables the output stream for this socket.

public void
startHandshake()

Implements abstract javax.net.ssl.SSLSocket.startHandshake.

Starts an SSL handshake on this connection.

private void
startHandshake(boolean resumable)

public String
toString()

Overrides sun.security.ssl.BaseSSLSocketImpl.toString.

Converts this socket to a String.

private void
tryKeyUpdate()

Try key update for sequence number wrap or key usage limit.

private void
public boolean
useDelegatedTask()

Implements sun.security.ssl.SSLTransport.useDelegatedTask.

Return true if delegated tasks used for handshaking operations.

private void
useImplicitHost(boolean useNameService)

private void
waitForClose()

Wait for close_notify alert for a graceful closure.

Inherited from sun.security.ssl.BaseSSLSocketImpl:
bindconnectgetChannelgetInetAddressgetKeepAlivegetLocalAddressgetLocalPortgetLocalSocketAddressgetOOBInlinegetOptiongetPortgetReceiveBufferSizegetRemoteSocketAddressgetReuseAddressgetSendBufferSizegetSoLingergetSoTimeoutgetTcpNoDelaygetTrafficClassisBoundisConnectedisLayeredsendUrgentDatasetKeepAlivesetOOBInlinesetOptionsetPerformancePreferencessetReceiveBufferSizesetReuseAddresssetSendBufferSizesetSoLingersetSoTimeoutsetTcpNoDelaysetTrafficClasssupportedOptions