public final class SSLSocketImpl
extends javax.net.ssl.SSLSocket
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.
SSLSocket,
SSLServerSocket| Modifier and Type | Method and Description |
|---|---|
void |
addHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener) |
void |
bind(java.net.SocketAddress bindpoint)
Binds the address to the socket.
|
void |
close() |
void |
connect(java.net.SocketAddress endpoint)
Connects this socket to the server.
|
void |
connect(java.net.SocketAddress endpoint,
int timeout) |
static com.tencent.kona.sun.security.ssl.Plaintext |
decode(com.tencent.kona.sun.security.ssl.TransportContext context,
java.nio.ByteBuffer[] srcs,
int srcsOffset,
int srcsLength,
java.nio.ByteBuffer[] dsts,
int dstsOffset,
int dstsLength)
Decodes an array of SSL/(D)TLS network source data into the
destination application data buffers.
|
java.lang.String |
getApplicationProtocol() |
java.nio.channels.SocketChannel |
getChannel()
Returns the unique
SocketChannel
object associated with this socket, if any. |
java.lang.String[] |
getEnabledCipherSuites() |
java.lang.String[] |
getEnabledProtocols() |
boolean |
getEnableSessionCreation() |
java.lang.String |
getHandshakeApplicationProtocol() |
java.util.function.BiFunction<javax.net.ssl.SSLSocket,java.util.List<java.lang.String>,java.lang.String> |
getHandshakeApplicationProtocolSelector() |
javax.net.ssl.SSLSession |
getHandshakeSession() |
java.net.InetAddress |
getInetAddress()
Returns the address of the remote peer for this connection.
|
java.io.InputStream |
getInputStream() |
boolean |
getKeepAlive()
Tests if SO_KEEPALIVE is enabled.
|
java.net.InetAddress |
getLocalAddress()
Gets the local address to which the socket is bound.
|
int |
getLocalPort()
Returns the number of the local port that this connection uses.
|
java.net.SocketAddress |
getLocalSocketAddress()
Returns the address of the endpoint this socket is connected to
|
boolean |
getNeedClientAuth() |
boolean |
getOOBInline()
Tests if OOBINLINE is enabled.
|
java.io.OutputStream |
getOutputStream() |
java.lang.String |
getPeerHost()
Returns the host name of the peer.
|
int |
getPeerPort()
Returns the port number of the peer.
|
int |
getPort()
Returns the number of the remote port that this connection uses.
|
int |
getReceiveBufferSize() |
java.net.SocketAddress |
getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to
|
boolean |
getReuseAddress()
Tests if SO_REUSEADDR is enabled.
|
int |
getSendBufferSize() |
javax.net.ssl.SSLSession |
getSession() |
int |
getSoLinger()
Returns the socket's linger timeout.
|
int |
getSoTimeout()
Returns the socket timeout.
|
javax.net.ssl.SSLParameters |
getSSLParameters() |
java.lang.String[] |
getSupportedCipherSuites() |
java.lang.String[] |
getSupportedProtocols() |
boolean |
getTcpNoDelay()
Returns true if the Nagle optimization is disabled.
|
int |
getTrafficClass()
Gets traffic class or type-of-service in the IP header for packets
sent from this Socket.
|
boolean |
getUseClientMode() |
boolean |
getWantClientAuth() |
boolean |
isBound()
Returns the binding state of the socket.
|
boolean |
isClosed() |
boolean |
isConnected()
Returns the connection state of the socket.
|
boolean |
isInputShutdown()
Returns the input state of the socket
|
boolean |
isOutputShutdown()
Returns the output state of the socket
|
void |
removeHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener) |
void |
sendUrgentData(int data)
Send one byte of urgent data on the socket.
|
void |
setEnabledCipherSuites(java.lang.String[] suites) |
void |
setEnabledProtocols(java.lang.String[] protocols) |
void |
setEnableSessionCreation(boolean flag) |
void |
setHandshakeApplicationProtocolSelector(java.util.function.BiFunction<javax.net.ssl.SSLSocket,java.util.List<java.lang.String>,java.lang.String> selector) |
void |
setHost(java.lang.String host) |
void |
setKeepAlive(boolean on)
Enable/disable SO_KEEPALIVE.
|
void |
setNeedClientAuth(boolean need) |
void |
setOOBInline(boolean on)
Enable/disable OOBINLINE (receipt of TCP urgent data) By default, this
option is disabled and TCP urgent data received on a socket is silently
discarded.
|
void |
setPerformancePreferences(int connectionTime,
int latency,
int bandwidth)
Sets performance preferences for this socket.
|
void |
setReceiveBufferSize(int size) |
void |
setReuseAddress(boolean on)
Enable/disable SO_REUSEADDR.
|
void |
setSendBufferSize(int size) |
void |
setSoLinger(boolean flag,
int linger)
Assigns the socket's linger timeout.
|
void |
setSoTimeout(int timeout) |
void |
setSSLParameters(javax.net.ssl.SSLParameters params) |
void |
setTcpNoDelay(boolean value)
Enables or disables the Nagle optimization.
|
void |
setTrafficClass(int tc)
Sets traffic class or type-of-service octet in the IP header for
packets sent from this Socket.
|
void |
setUseClientMode(boolean mode) |
void |
setWantClientAuth(boolean want) |
void |
shutdown()
Shutdown the transport.
|
void |
shutdownInput()
Places the input stream for this socket at "end of stream".
|
void |
shutdownOutput()
Disables the output stream for this socket.
|
void |
startHandshake() |
java.lang.String |
toString() |
boolean |
useDelegatedTask()
Return true if delegated tasks used for handshaking operations.
|
public void connect(java.net.SocketAddress endpoint,
int timeout)
throws java.io.IOException
connect in class java.net.Socketjava.io.IOExceptionpublic java.lang.String[] getSupportedCipherSuites()
getSupportedCipherSuites in class javax.net.ssl.SSLSocketpublic java.lang.String[] getEnabledCipherSuites()
getEnabledCipherSuites in class javax.net.ssl.SSLSocketpublic void setEnabledCipherSuites(java.lang.String[] suites)
setEnabledCipherSuites in class javax.net.ssl.SSLSocketpublic java.lang.String[] getSupportedProtocols()
getSupportedProtocols in class javax.net.ssl.SSLSocketpublic java.lang.String[] getEnabledProtocols()
getEnabledProtocols in class javax.net.ssl.SSLSocketpublic void setEnabledProtocols(java.lang.String[] protocols)
setEnabledProtocols in class javax.net.ssl.SSLSocketpublic javax.net.ssl.SSLSession getSession()
getSession in class javax.net.ssl.SSLSocketpublic javax.net.ssl.SSLSession getHandshakeSession()
getHandshakeSession in class javax.net.ssl.SSLSocketpublic void addHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener)
addHandshakeCompletedListener in class javax.net.ssl.SSLSocketpublic void removeHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener)
removeHandshakeCompletedListener in class javax.net.ssl.SSLSocketpublic void startHandshake()
throws java.io.IOException
startHandshake in class javax.net.ssl.SSLSocketjava.io.IOExceptionpublic void setUseClientMode(boolean mode)
setUseClientMode in class javax.net.ssl.SSLSocketpublic boolean getUseClientMode()
getUseClientMode in class javax.net.ssl.SSLSocketpublic void setNeedClientAuth(boolean need)
setNeedClientAuth in class javax.net.ssl.SSLSocketpublic boolean getNeedClientAuth()
getNeedClientAuth in class javax.net.ssl.SSLSocketpublic void setWantClientAuth(boolean want)
setWantClientAuth in class javax.net.ssl.SSLSocketpublic boolean getWantClientAuth()
getWantClientAuth in class javax.net.ssl.SSLSocketpublic void setEnableSessionCreation(boolean flag)
setEnableSessionCreation in class javax.net.ssl.SSLSocketpublic boolean getEnableSessionCreation()
getEnableSessionCreation in class javax.net.ssl.SSLSocketpublic boolean isClosed()
isClosed in class java.net.Socketpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic void shutdownInput()
throws java.io.IOException
java.io.IOExceptionSocket.shutdownInput()public boolean isInputShutdown()
Socket.isInputShutdown()public void shutdownOutput()
throws java.io.IOException
java.io.IOExceptionSocket.shutdownOutput()public boolean isOutputShutdown()
Socket.isOutputShutdown()public java.io.InputStream getInputStream()
throws java.io.IOException
java.io.IOExceptionpublic java.io.OutputStream getOutputStream()
throws java.io.IOException
java.io.IOExceptionpublic javax.net.ssl.SSLParameters getSSLParameters()
getSSLParameters in class javax.net.ssl.SSLSocketpublic void setSSLParameters(javax.net.ssl.SSLParameters params)
setSSLParameters in class javax.net.ssl.SSLSocketpublic java.lang.String getApplicationProtocol()
getApplicationProtocol in class javax.net.ssl.SSLSocketpublic java.lang.String getHandshakeApplicationProtocol()
getHandshakeApplicationProtocol in class javax.net.ssl.SSLSocketpublic void setHandshakeApplicationProtocolSelector(java.util.function.BiFunction<javax.net.ssl.SSLSocket,java.util.List<java.lang.String>,java.lang.String> selector)
setHandshakeApplicationProtocolSelector in class javax.net.ssl.SSLSocketpublic java.util.function.BiFunction<javax.net.ssl.SSLSocket,java.util.List<java.lang.String>,java.lang.String> getHandshakeApplicationProtocolSelector()
getHandshakeApplicationProtocolSelector in class javax.net.ssl.SSLSocketpublic void setHost(java.lang.String host)
public java.lang.String getPeerHost()
public int getPeerPort()
public boolean useDelegatedTask()
public void shutdown()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String toString()
public static com.tencent.kona.sun.security.ssl.Plaintext decode(com.tencent.kona.sun.security.ssl.TransportContext context,
java.nio.ByteBuffer[] srcs,
int srcsOffset,
int srcsLength,
java.nio.ByteBuffer[] dsts,
int dstsOffset,
int dstsLength)
throws java.io.IOException
context - the transportation contextsrcs - an array of ByteBuffers containing the
inbound network datasrcsOffset - The offset within the srcs buffer array
of the first buffer from which bytes are to be
retrieved; it must be non-negative and no larger
than srcs.length.srcsLength - The maximum number of srcs buffers to be
accessed; it must be non-negative and no larger than
srcs.length - srcsOffset.dsts - an array of ByteBuffers to hold inbound
application datadstsOffset - The offset within the dsts buffer array
of the first buffer from which bytes are to be
placed; it must be non-negative and no larger
than dsts.length.dstsLength - The maximum number of dsts buffers to be
accessed; it must be non-negative and no larger than
dsts.length - dstsOffset.Plaintext describing the result of
the operationjava.io.IOException - if a problem was encountered while receiving or
decoding networking datapublic final java.nio.channels.SocketChannel getChannel()
SocketChannel
object associated with this socket, if any.getChannel in class java.net.SocketSocket.getChannel()public void bind(java.net.SocketAddress bindpoint)
throws java.io.IOException
bind in class java.net.Socketjava.io.IOExceptionSocket.bind(java.net.SocketAddress)public java.net.SocketAddress getLocalSocketAddress()
getLocalSocketAddress in class java.net.SocketSocket.getLocalSocketAddress()public java.net.SocketAddress getRemoteSocketAddress()
getRemoteSocketAddress in class java.net.SocketSocket.getRemoteSocketAddress()public final void connect(java.net.SocketAddress endpoint)
throws java.io.IOException
connect in class java.net.Socketendpoint - the SocketAddressjava.io.IOException - if an error occurs during the connectionpublic final boolean isConnected()
isConnected in class java.net.SocketSocket.isConnected()public final boolean isBound()
isBound in class java.net.SocketSocket.isBound()public final java.net.InetAddress getInetAddress()
getInetAddress in class java.net.Socketpublic final java.net.InetAddress getLocalAddress()
getLocalAddress in class java.net.Socketpublic final int getPort()
getPort in class java.net.Socketpublic final int getLocalPort()
getLocalPort in class java.net.Socketpublic final void setTcpNoDelay(boolean value)
throws java.net.SocketException
setTcpNoDelay in class java.net.Socketjava.net.SocketExceptionSocket.setTcpNoDelay(boolean)public final boolean getTcpNoDelay()
throws java.net.SocketException
getTcpNoDelay in class java.net.Socketjava.net.SocketExceptionSocket.getTcpNoDelay()public final void setSoLinger(boolean flag,
int linger)
throws java.net.SocketException
setSoLinger in class java.net.Socketjava.net.SocketExceptionSocket.setSoLinger(boolean, int)public final int getSoLinger()
throws java.net.SocketException
getSoLinger in class java.net.Socketjava.net.SocketExceptionSocket.getSoLinger()public final void sendUrgentData(int data)
throws java.net.SocketException
sendUrgentData in class java.net.Socketjava.net.SocketExceptionAt this point, there seems to be no specific requirement to support
this for an SSLSocket. An implementation can be provided if a need
arises in the future.public final void setOOBInline(boolean on)
throws java.net.SocketException
setOOBInline in class java.net.Socketjava.net.SocketExceptionSetting OOBInline does not have any effect on SSLSocket,
since currently we don't support sending urgent data.public final boolean getOOBInline()
throws java.net.SocketException
getOOBInline in class java.net.Socketjava.net.SocketExceptionSocket.getOOBInline()public final int getSoTimeout()
throws java.net.SocketException
getSoTimeout in class java.net.Socketjava.net.SocketExceptionSocket.getSoTimeout()public final void setSendBufferSize(int size)
throws java.net.SocketException
setSendBufferSize in class java.net.Socketjava.net.SocketExceptionpublic final int getSendBufferSize()
throws java.net.SocketException
getSendBufferSize in class java.net.Socketjava.net.SocketExceptionpublic final void setReceiveBufferSize(int size)
throws java.net.SocketException
setReceiveBufferSize in class java.net.Socketjava.net.SocketExceptionpublic final int getReceiveBufferSize()
throws java.net.SocketException
getReceiveBufferSize in class java.net.Socketjava.net.SocketExceptionpublic final void setKeepAlive(boolean on)
throws java.net.SocketException
setKeepAlive in class java.net.Socketjava.net.SocketExceptionSocket.setKeepAlive(boolean)public final boolean getKeepAlive()
throws java.net.SocketException
getKeepAlive in class java.net.Socketjava.net.SocketExceptionSocket.getKeepAlive()public final void setTrafficClass(int tc)
throws java.net.SocketException
setTrafficClass in class java.net.Socketjava.net.SocketExceptionSocket.setTrafficClass(int)public final int getTrafficClass()
throws java.net.SocketException
getTrafficClass in class java.net.Socketjava.net.SocketExceptionSocket.getTrafficClass()public final void setReuseAddress(boolean on)
throws java.net.SocketException
setReuseAddress in class java.net.Socketjava.net.SocketExceptionSocket.setReuseAddress(boolean)public final boolean getReuseAddress()
throws java.net.SocketException
getReuseAddress in class java.net.Socketjava.net.SocketExceptionSocket.getReuseAddress()public void setPerformancePreferences(int connectionTime,
int latency,
int bandwidth)
setPerformancePreferences in class java.net.SocketSocket.setPerformancePreferences(int, int, int)public void setSoTimeout(int timeout)
throws java.net.SocketException
setSoTimeout in class java.net.Socketjava.net.SocketException