java.lang.Object | |||
↳ | java.net.Socket | ||
↳ | javax.net.ssl.SSLSocket | ||
↳ | sun.security.ssl.SSLSocketImpl |
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.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Registers an event listener to receive notifications that an
SSL handshake has completed on this connection.
| |||||||||||
Binds the address to the socket.
| |||||||||||
Closes the SSL connection.
| |||||||||||
Connects this socket to the server with a specified timeout
value.
| |||||||||||
Connects this socket to the server.
| |||||||||||
Returns the unique java.nio.SocketChannel SocketChannel object
associated with this socket, if any.
| |||||||||||
Returns true if new connections may cause creation of new SSL
sessions.
| |||||||||||
Returns the names of the SSL cipher suites which are currently enabled
for use on this connection.
| |||||||||||
Returns the names of the protocol versions which are currently
enabled for use on this connection.
| |||||||||||
Returns the endpoint identification algorithm of the socket.
| |||||||||||
Returns the address of the remote peer for this connection.
| |||||||||||
Gets an input stream to read from the peer on the other side.
| |||||||||||
Tests if SO_KEEPALIVE is enabled.
| |||||||||||
Gets the local address to which the socket is bound.
| |||||||||||
Returns the number of the local port that this connection uses.
| |||||||||||
Returns the address of the endpoint this socket is connected to
| |||||||||||
Returns true if the socket will require client authentication.
| |||||||||||
Tests if OOBINLINE is enabled.
| |||||||||||
Gets an output stream to write to the peer on the other side.
| |||||||||||
Returns the number of the remote port that this connection uses.
| |||||||||||
Gets the value of the SO_RCVBUF option for this Socket,
that is the buffer size used by the platform for
input on this Socket.
| |||||||||||
Returns the address of the endpoint this socket is connected to
| |||||||||||
Tests if SO_REUSEADDR is enabled.
| |||||||||||
Get value of the SO_SNDBUF option for this Socket,
that is the buffer size used by the platform
for output on this Socket.
| |||||||||||
Returns the the SSL Session in use by this connection.
| |||||||||||
Returns the socket's linger timeout.
| |||||||||||
Returns the socket timeout.
| |||||||||||
Returns the names of the cipher suites which could be enabled for use
on an SSL connection.
| |||||||||||
Returns the protocols that are supported by this implementation.
| |||||||||||
Returns true if the Nagle optimization is disabled.
| |||||||||||
Gets traffic class or type-of-service in the IP header for packets
sent from this Socket.
| |||||||||||
Returns true if the socket is set to use client mode when
handshaking.
| |||||||||||
Returns true if the socket will request client authentication.
| |||||||||||
Returns the binding state of the socket.
| |||||||||||
Return whether the socket has been explicitly closed by the application.
| |||||||||||
Returns the connection state of the socket.
| |||||||||||
Returns the input state of the socket
| |||||||||||
Returns the output state of the socket
| |||||||||||
Removes a previously registered handshake completion listener.
| |||||||||||
Send one byte of urgent data on the socket.
| |||||||||||
Controls whether new connections may cause creation of new SSL
sessions.
| |||||||||||
Controls which particular cipher suites are enabled for use on
this connection.
| |||||||||||
Controls which protocols are enabled for use on
this connection.
| |||||||||||
Enable/disable SO_KEEPALIVE.
| |||||||||||
Sets the flag controlling whether a server mode socket
*REQUIRES* SSL client authentication.
| |||||||||||
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.
| |||||||||||
Sets performance preferences for this socket.
| |||||||||||
Sets the SO_RCVBUF option to the specified value for this
Socket.
| |||||||||||
Enable/disable SO_REUSEADDR.
| |||||||||||
Sets the SO_SNDBUF option to the specified value for this
Socket.
| |||||||||||
Assigns the socket's linger timeout.
| |||||||||||
Assigns the socket timeout.
| |||||||||||
Enables or disables the Nagle optimization.
| |||||||||||
Sets traffic class or type-of-service octet in the IP header for
packets sent from this Socket.
| |||||||||||
Sets the flag controlling whether the socket is in SSL
client or server mode.
| |||||||||||
Sets the flag controlling whether a server mode socket
*REQUESTS* SSL client authentication.
| |||||||||||
The semantics of shutdownInput is not supported in TLS 1.0
spec.
| |||||||||||
The semantics of shutdownOutput is not supported in TLS 1.0
spec.
| |||||||||||
Starts an SSL handshake on this connection.
| |||||||||||
Returns a printable representation of this end of the connection.
| |||||||||||
Try to configure the endpoint identification algorithm of the socket.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Ensures that the SSL connection is closed down as cleanly
as possible, in case the application forgets to do so.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() |
Registers an event listener to receive notifications that an SSL handshake has completed on this connection.
listener | the HandShake Completed event listener |
---|
Binds the address to the socket.
bindpoint | the SocketAddress to bind to |
---|
IOException |
---|
Closes the SSL connection. SSL includes an application level shutdown handshake; you should close SSL sockets explicitly rather than leaving it for finalization, so that your remote peer does not experience a protocol error.
IOException |
---|
Connects this socket to the server with a specified timeout value. This method is either called on an unconnected SSLSocketImpl by the application, or it is called in the constructor of a regular SSLSocketImpl. If we are layering on top on another socket, then this method should not be called, because we assume that the underlying socket is already connected by the time it is passed to us.
endpoint | the SocketAddress |
---|---|
timeout | the timeout value to be used, 0 is no timeout |
IOException | if an error occurs during the connection |
---|---|
SocketTimeoutException | if timeout expires before connecting |
Connects this socket to the server. This method is either called on an unconnected SSLSocketImpl by the application, or it is called in the constructor of a regular SSLSocketImpl. If we are layering on top on another socket, then this method should not be called, because we assume that the underlying socket is already connected by the time it is passed to us.
endpoint | the SocketAddress |
---|
IOException | if an error occurs during the connection |
---|
Returns the unique java.nio.SocketChannel SocketChannel object associated with this socket, if any.
Returns true if new connections may cause creation of new SSL sessions.
Returns the names of the SSL cipher suites which are currently enabled for use on this connection. When an SSL socket is first created, all enabled cipher suites (a) protect data confidentiality, by traffic encryption, and (b) can mutually authenticate both clients and servers. Thus, in some environments, this value might be empty.
Returns the names of the protocol versions which are currently enabled for use on this connection.
Returns the endpoint identification algorithm of the socket.
Returns the address of the remote peer for this connection.
null
if the socket is not connected.
Gets an input stream to read from the peer on the other side. Data read from this stream was always integrity protected in transit, and will usually have been confidentiality protected.
IOException |
---|
Tests if SO_KEEPALIVE is enabled.
boolean
indicating whether or not SO_KEEPALIVE is enabled.SocketException |
---|
Gets the local address to which the socket is bound.
Returns the number of the local port that this connection uses.
Returns the address of the endpoint this socket is connected to
SocketAddress
representing the local endpoint of this
socket, or null
if it is not bound yet.Returns true if the socket will require client authentication. This option is only useful to sockets in the server mode.
Tests if OOBINLINE is enabled.
boolean
indicating whether or not OOBINLINE is enabled.SocketException |
---|
Gets an output stream to write to the peer on the other side. Data written on this stream is always integrity protected, and will usually be confidentiality protected.
IOException |
---|
Returns the number of the remote port that this connection uses.
Gets the value of the SO_RCVBUF option for this Socket, that is the buffer size used by the platform for input on this Socket.
SocketException |
---|
Returns the address of the endpoint this socket is connected to
SocketAddress
reprensenting the remote endpoint of this
socket, or null
if it is not connected yet.Tests if SO_REUSEADDR is enabled.
boolean
indicating whether or not SO_REUSEADDR is enabled.SocketException |
---|
Get value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.
SocketException |
---|
Returns the the SSL Session in use by this connection. These can be long lived, and frequently correspond to an entire login session for some user.
SSLSession
Returns the socket's linger timeout.
SocketException |
---|
Returns the names of the cipher suites which could be enabled for use on an SSL connection. Normally, only a subset of these will actually be enabled by default, since this list may include cipher suites which do not support the mutual authentication of servers and clients, or which do not protect data confidentiality. Servers may also need certain kinds of certificates to use certain cipher suites.
Returns the protocols that are supported by this implementation. A subset of the supported protocols may be enabled for this connection@ returns an array of protocol names.
Returns true if the Nagle optimization is disabled. This relates to low-level buffering of TCP traffic, delaying the traffic to promote better throughput.
boolean
indicating whether or not TCP_NODELAY is enabled.SocketException |
---|
Gets traffic class or type-of-service in the IP header for packets sent from this Socket.
SocketException |
---|
Returns true if the socket is set to use client mode when handshaking.
Returns true if the socket will request client authentication. This option is only useful for sockets in the server mode.
Returns the binding state of the socket.
Return whether the socket has been explicitly closed by the application.
Returns the connection state of the socket.
Returns the input state of the socket
Returns the output state of the socket
Removes a previously registered handshake completion listener.
listener | the HandShake Completed event listener |
---|
Send one byte of urgent data on the socket.
data | The byte of data to send |
---|
SocketException |
---|
Controls whether new connections may cause creation of new SSL sessions. As long as handshaking has not started, we can change whether we enable session creations. Otherwise, we will need to wait for the next handshake.
flag | true indicates that sessions may be created; this is the default. false indicates that an existing session must be resumed |
---|
Controls which particular cipher suites are enabled for use on this connection. The cipher suites must have been listed by getCipherSuites() as being supported. Even if a suite has been enabled, it might never be used if no peer supports it or the requisite certificates (and private keys) are not available.
suites | Names of all the cipher suites to enable. |
---|
Controls which protocols are enabled for use on this connection. The protocols must have been listed by getSupportedProtocols() as being supported.
protocols | protocols to enable. |
---|
IllegalArgumentException | when one of the protocols named by the parameter is not supported. |
---|
Enable/disable SO_KEEPALIVE.
on | whether or not to have socket keep alive turned on. |
---|
SocketException |
---|
Sets the flag controlling whether a server mode socket *REQUIRES* SSL client authentication. As long as handshaking has not started, we can change whether client authentication is needed. Otherwise, we will need to wait for the next handshake.
flag | set to true if client authentication is required, or false if no client authentication is desired. |
---|
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.
on | true to enable OOBINLINE,
false to disable. |
---|
SocketException |
---|
Sets performance preferences for this socket.
connectionTime | An int expressing the relative importance of a short connection time |
---|---|
latency | An int expressing the relative importance of low latency |
bandwidth | An int expressing the relative importance of high bandwidth |
Sets the SO_RCVBUF option to the specified value for this Socket. The SO_RCVBUF option is used by the platform's networking code as a hint for the size to set the underlying network I/O buffers.
Increasing the receive buffer size can increase the performance of network I/O for high-volume connection, while decreasing it can help reduce the backlog of incoming data.
Because SO_RCVBUF is a hint, applications that want to
verify what size the buffers were set to should call
getReceiveBufferSize()
.
The value of SO_RCVBUF is also used to set the TCP receive window that is advertized to the remote peer. Generally, the window size can be modified at any time when a socket is connected. However, if a receive window larger than 64K is required then this must be requested before the socket is connected to the remote peer. There are two cases to be aware of:
setReceiveBufferSize(int)
before the ServerSocket
is bound to a local address.size | the size to which to set the receive buffer size. This value must be greater than 0. |
---|
SocketException |
---|
Enable/disable SO_REUSEADDR.
on | whether to enable or disable the socket option |
---|
SocketException |
---|
Sets the SO_SNDBUF option to the specified value for this Socket. The SO_SNDBUF option is used by the platform's networking code as a hint for the size to set the underlying network I/O buffers.
Because SO_SNDBUF is a hint, applications that want to
verify what size the buffers were set to should call
getSendBufferSize()
.
size | the size to which to set the send buffer size. This value must be greater than 0. |
---|
SocketException |
---|
Assigns the socket's linger timeout.
flag | whether or not to linger on. |
---|---|
linger | how long to linger for, if on is true. |
SocketException |
---|
Assigns the socket timeout.
timeout | the specified timeout, in milliseconds. |
---|
SocketException |
---|
Enables or disables the Nagle optimization.
value | true to enable TCP_NODELAY,
false to disable. |
---|
SocketException |
---|
Sets traffic class or type-of-service octet in the IP header for packets sent from this Socket.
tc | an int value for the bitset. |
---|
SocketException |
---|
Sets the flag controlling whether the socket is in SSL client or server mode. Must be called before any SSL traffic has started.
flag | true if the socket should start its handshaking in "client" mode |
---|
Sets the flag controlling whether a server mode socket *REQUESTS* SSL client authentication. As long as handshaking has not started, we can change whether client authentication is requested. Otherwise, we will need to wait for the next handshake.
flag | set to true if client authentication is requested, or false if no client authentication is desired. |
---|
The semantics of shutdownInput is not supported in TLS 1.0 spec. Thus when the method is called on an SSL socket, an UnsupportedOperationException will be thrown.
The semantics of shutdownOutput is not supported in TLS 1.0 spec. Thus when the method is called on an SSL socket, an UnsupportedOperationException will be thrown.
Returns a printable representation of this end of the connection.
Try to configure the endpoint identification algorithm of the socket.
identificationAlgorithm | the algorithm used to check the endpoint identity. |
---|
Ensures that the SSL connection is closed down as cleanly as possible, in case the application forgets to do so. This allows SSL connections to be implicitly reclaimed, rather than forcing them to be explicitly reclaimed at the penalty of prematurly killing SSL sessions.
Throwable |
---|