APIdia Launch Partner
Top Description Fields Constructors Methods
sun.security.ssl

pack-priv final Class SSLServerSocketImpl

extends SSLServerSocket
Class Inheritance
Imports
java.io.IOException, java.net.InetAddress, .Socket, java.util.concurrent.locks.ReentrantLock, javax.net.ssl.SSLParameters, .SSLServerSocket

This class provides a simple way for servers to support conventional use of the Secure Sockets Layer (SSL). Application code uses an SSLServerSocketImpl exactly like it uses a regular TCP ServerSocket; the difference is that the connections established are secured using SSL.

Also, the constructors take an explicit authentication context parameter, giving flexibility with respect to how the server socket authenticates itself. That policy flexibility is not exposed through the standard SSLServerSocketFactory API.

System security defaults prevent server sockets from accepting connections if the authentication context has not been given a certificate chain and its matching private key. If the clients of your application support "anonymous" cipher suites, you may be able to configure a server socket to accept those suites.

Author
David Brownell
See Also
SSLSocketImpl, SSLServerSocketFactoryImpl

Field Summary

Modifier and TypeField and Description
private final ReentrantLock
private final SSLConfiguration
private final SSLContextImpl

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
SSLServerSocketImpl(SSLContextImpl sslContext, int port, int backlog)

pack-priv
SSLServerSocketImpl(SSLContextImpl sslContext, int port, int backlog, InetAddress address)

Method Summary

Modifier and TypeMethod and Description
public Socket
accept()

Overrides java.net.ServerSocket.accept.

Listens for a connection to be made to this socket and accepts it.

public String[]
getEnabledCipherSuites()

Implements abstract javax.net.ssl.SSLServerSocket.getEnabledCipherSuites.

Returns the list of cipher suites which are currently enabled for use by newly accepted connections.

public String[]
getEnabledProtocols()

Implements abstract javax.net.ssl.SSLServerSocket.getEnabledProtocols.

Returns the names of the protocols which are currently enabled for use by the newly accepted connections.

public boolean
getEnableSessionCreation()

Implements abstract javax.net.ssl.SSLServerSocket.getEnableSessionCreation.

Returns true if new SSL sessions may be established by the sockets which are created from this server socket.

public boolean
getNeedClientAuth()

Implements abstract javax.net.ssl.SSLServerSocket.getNeedClientAuth.

Returns true if client authentication will be required on newly accepted server-mode SSLSockets.

public SSLParameters
getSSLParameters()

Overrides javax.net.ssl.SSLServerSocket.getSSLParameters.

Returns the SSLParameters in effect for newly accepted connections.

public String[]
getSupportedCipherSuites()

Implements abstract javax.net.ssl.SSLServerSocket.getSupportedCipherSuites.

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

public String[]
getSupportedProtocols()

Implements abstract javax.net.ssl.SSLServerSocket.getSupportedProtocols.

Returns the names of the protocols which could be enabled for use.

public boolean
getUseClientMode()

Implements abstract javax.net.ssl.SSLServerSocket.getUseClientMode.

Returns true if accepted connections will be in SSL client mode.

public boolean
getWantClientAuth()

Implements abstract javax.net.ssl.SSLServerSocket.getWantClientAuth.

Returns true if client authentication will be requested on newly accepted server-mode connections.

public void
setEnabledCipherSuites(String[] suites)

Implements abstract javax.net.ssl.SSLServerSocket.setEnabledCipherSuites.

Sets the cipher suites enabled for use by accepted connections.

public void
setEnabledProtocols(String[] protocols)

Implements abstract javax.net.ssl.SSLServerSocket.setEnabledProtocols.

Controls which particular protocols are enabled for use by accepted connections.

public void
setEnableSessionCreation(boolean flag)

Implements abstract javax.net.ssl.SSLServerSocket.setEnableSessionCreation.

Controls whether new SSL sessions may be established by the sockets which are created from this server socket.

public void
setNeedClientAuth(boolean need)

Implements abstract javax.net.ssl.SSLServerSocket.setNeedClientAuth.

Controls whether accepted server-mode SSLSockets will be initially configured to require client authentication.

public void
setSSLParameters(SSLParameters params)

Overrides javax.net.ssl.SSLServerSocket.setSSLParameters.

Applies SSLParameters to newly accepted connections.

public void
setUseClientMode(boolean useClientMode)

Implements abstract javax.net.ssl.SSLServerSocket.setUseClientMode.

Controls whether accepted connections are in the (default) SSL server mode, or the SSL client mode.

public void
setWantClientAuth(boolean want)

Implements abstract javax.net.ssl.SSLServerSocket.setWantClientAuth.

Controls whether accepted server-mode SSLSockets will be initially configured to request client authentication.

public String
toString()

Overrides java.net.ServerSocket.toString.

Returns the implementation address and implementation port of this socket as a String.

Field Detail

serverSocketLockback to summary
private final ReentrantLock serverSocketLock
sslConfigback to summary
private final SSLConfiguration sslConfig
sslContextback to summary
private final SSLContextImpl sslContext

Constructor Detail

SSLServerSocketImplback to summary
pack-priv SSLServerSocketImpl(SSLContextImpl sslContext) throws IOException
SSLServerSocketImplback to summary
pack-priv SSLServerSocketImpl(SSLContextImpl sslContext, int port, int backlog) throws IOException
SSLServerSocketImplback to summary
pack-priv SSLServerSocketImpl(SSLContextImpl sslContext, int port, int backlog, InetAddress address) throws IOException

Method Detail

acceptback to summary
public Socket accept() throws IOException

Overrides java.net.ServerSocket.accept.

Doc from java.net.ServerSocket.accept.

Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made.

This method is interruptible in the following circumstances:

  1. The socket is associated with a ServerSocketChannel. In that case, interrupting a thread accepting a connection will close the underlying channel and cause this method to throw java.nio.channels.ClosedByInterruptException with the thread's interrupted status set.
  2. The socket uses the system-default socket implementation and a virtual thread is accepting a connection. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. This method will then throw SocketException with the thread's interrupted status set.
Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when waiting for a connection, the socket is not bound or the socket is closed.
getEnabledCipherSuitesback to summary
public String[] getEnabledCipherSuites()

Implements abstract javax.net.ssl.SSLServerSocket.getEnabledCipherSuites.

Doc from javax.net.ssl.SSLServerSocket.getEnabledCipherSuites.

Returns the list of cipher suites which are currently enabled for use by newly accepted connections.

If this list has not been explicitly modified, a system-provided default guarantees a minimum quality of service in all enabled cipher suites.

Note that even if a suite is enabled, it may never be used. This can occur if the peer does not support it, or its use is restricted, or the requisite certificates (and private keys) for the suite are not available, or an anonymous suite is enabled but authentication is required.

The returned array includes cipher suites from the list of standard cipher suite names in the JSSE Cipher Suite Names section of the Java Security Standard Algorithm Names Specification, and may also include other cipher suites that the provider supports.

Annotations
@Override
getEnabledProtocolsback to summary
public String[] getEnabledProtocols()

Implements abstract javax.net.ssl.SSLServerSocket.getEnabledProtocols.

Doc from javax.net.ssl.SSLServerSocket.getEnabledProtocols.

Returns the names of the protocols which are currently enabled for use by the newly accepted connections.

Note that even if a protocol is enabled, it may never be used. This can occur if the peer does not support the protocol, or its use is restricted, or there are no enabled cipher suites supported by the protocol.

Annotations
@Override
getEnableSessionCreationback to summary
public boolean getEnableSessionCreation()

Implements abstract javax.net.ssl.SSLServerSocket.getEnableSessionCreation.

Doc from javax.net.ssl.SSLServerSocket.getEnableSessionCreation.

Returns true if new SSL sessions may be established by the sockets which are created from this server socket.

Annotations
@Override
getNeedClientAuthback to summary
public boolean getNeedClientAuth()

Implements abstract javax.net.ssl.SSLServerSocket.getNeedClientAuth.

Doc from javax.net.ssl.SSLServerSocket.getNeedClientAuth.

Returns true if client authentication will be required on newly accepted server-mode SSLSockets.

The initial inherited setting may be overridden by calling SSLSocket#setNeedClientAuth(boolean) or SSLSocket#setWantClientAuth(boolean).

Annotations
@Override
getSSLParametersback to summary
public SSLParameters getSSLParameters()

Overrides javax.net.ssl.SSLServerSocket.getSSLParameters.

Doc from javax.net.ssl.SSLServerSocket.getSSLParameters.

Returns the SSLParameters in effect for newly accepted connections. The ciphersuites and protocols of the returned SSLParameters are always non-null.

Annotations
@Override
getSupportedCipherSuitesback to summary
public String[] getSupportedCipherSuites()

Implements abstract javax.net.ssl.SSLServerSocket.getSupportedCipherSuites.

Doc from javax.net.ssl.SSLServerSocket.getSupportedCipherSuites.

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 meet quality of service requirements for those defaults. Such cipher suites are useful in specialized applications.

The returned array includes cipher suites from the list of standard cipher suite names in the JSSE Cipher Suite Names section of the Java Security Standard Algorithm Names Specification, and may also include other cipher suites that the provider supports.

Annotations
@Override
getSupportedProtocolsback to summary
public String[] getSupportedProtocols()

Implements abstract javax.net.ssl.SSLServerSocket.getSupportedProtocols.

Doc from javax.net.ssl.SSLServerSocket.getSupportedProtocols.

Returns the names of the protocols which could be enabled for use.

Annotations
@Override
getUseClientModeback to summary
public boolean getUseClientMode()

Implements abstract javax.net.ssl.SSLServerSocket.getUseClientMode.

Doc from javax.net.ssl.SSLServerSocket.getUseClientMode.

Returns true if accepted connections will be in SSL client mode.

Annotations
@Override
getWantClientAuthback to summary
public boolean getWantClientAuth()

Implements abstract javax.net.ssl.SSLServerSocket.getWantClientAuth.

Doc from javax.net.ssl.SSLServerSocket.getWantClientAuth.

Returns true if client authentication will be requested on newly accepted server-mode connections.

The initial inherited setting may be overridden by calling SSLSocket#setNeedClientAuth(boolean) or SSLSocket#setWantClientAuth(boolean).

Annotations
@Override
setEnabledCipherSuitesback to summary
public void setEnabledCipherSuites(String[] suites)

Implements abstract javax.net.ssl.SSLServerSocket.setEnabledCipherSuites.

Doc from javax.net.ssl.SSLServerSocket.setEnabledCipherSuites.

Sets the cipher suites enabled for use by accepted connections.

The cipher suites must have been listed by getSupportedCipherSuites() as being supported. Following a successful call to this method, only suites listed in the suites parameter are enabled for use.

Suites that require authentication information which is not available in this ServerSocket's authentication context will not be used in any case, even if they are enabled.

Note that the standard list of cipher suite names may be found in the JSSE Cipher Suite Names section of the Java Security Standard Algorithm Names Specification. Providers may support cipher suite names not found in this list or might not use the recommended name for a certain cipher suite.

SSLSockets returned from accept() inherit this setting.

Annotations
@Override
setEnabledProtocolsback to summary
public void setEnabledProtocols(String[] protocols)

Implements abstract javax.net.ssl.SSLServerSocket.setEnabledProtocols.

Doc from javax.net.ssl.SSLServerSocket.setEnabledProtocols.

Controls which particular protocols are enabled for use by accepted connections.

The protocols must have been listed by getSupportedProtocols() as being supported. Following a successful call to this method, only protocols listed in the protocols parameter are enabled for use.

SSLSockets returned from accept() inherit this setting.

Annotations
@Override
setEnableSessionCreationback to summary
public void setEnableSessionCreation(boolean flag)

Implements abstract javax.net.ssl.SSLServerSocket.setEnableSessionCreation.

Doc from javax.net.ssl.SSLServerSocket.setEnableSessionCreation.

Controls whether new SSL sessions may be established by the sockets which are created from this server socket.

SSLSockets returned from accept() inherit this setting.

Annotations
@Override
setNeedClientAuthback to summary
public void setNeedClientAuth(boolean need)

Implements abstract javax.net.ssl.SSLServerSocket.setNeedClientAuth.

Doc from javax.net.ssl.SSLServerSocket.setNeedClientAuth.

Controls whether accepted server-mode SSLSockets will be initially configured to require client authentication.

A socket's client authentication setting is one of the following:

  • client authentication required
  • client authentication requested
  • no client authentication desired

Unlike setWantClientAuth(boolean), if the accepted socket's option is set and the client chooses not to provide authentication information about itself, the negotiations will stop and the connection will be dropped.

Calling this method overrides any previous setting made by this method or setWantClientAuth(boolean).

The initial inherited setting may be overridden by calling SSLSocket#setNeedClientAuth(boolean) or SSLSocket#setWantClientAuth(boolean).

Annotations
@Override
setSSLParametersback to summary
public void setSSLParameters(SSLParameters params)

Overrides javax.net.ssl.SSLServerSocket.setSSLParameters.

Doc from javax.net.ssl.SSLServerSocket.setSSLParameters.

Applies SSLParameters to newly accepted connections.

This means:

  • If params.getCipherSuites() is non-null, setEnabledCipherSuites() is called with that value.
  • If params.getProtocols() is non-null, setEnabledProtocols() is called with that value.
  • If params.getNeedClientAuth() or params.getWantClientAuth() return true, setNeedClientAuth(true) and setWantClientAuth(true) are called, respectively; otherwise setWantClientAuth(false) is called.
  • If params.getServerNames() is non-null, the socket will configure its server names with that value.
  • If params.getSNIMatchers() is non-null, the socket will configure its SNI matchers with that value.
Annotations
@Override
setUseClientModeback to summary
public void setUseClientMode(boolean useClientMode)

Implements abstract javax.net.ssl.SSLServerSocket.setUseClientMode.

Doc from javax.net.ssl.SSLServerSocket.setUseClientMode.

Controls whether accepted connections are in the (default) SSL server mode, or the SSL client mode.

Servers normally authenticate themselves, and clients are not required to do so.

In rare cases, TCP servers need to act in the SSL client mode on newly accepted connections. For example, FTP clients acquire server sockets and listen there for reverse connections from the server. An FTP client would use an SSLServerSocket in "client" mode to accept the reverse connection while the FTP server uses an SSLSocket with "client" mode disabled to initiate the connection. During the resulting handshake, existing SSL sessions may be reused.

SSLSockets returned from accept() inherit this setting.

Annotations
@Override
setWantClientAuthback to summary
public void setWantClientAuth(boolean want)

Implements abstract javax.net.ssl.SSLServerSocket.setWantClientAuth.

Doc from javax.net.ssl.SSLServerSocket.setWantClientAuth.

Controls whether accepted server-mode SSLSockets will be initially configured to request client authentication.

A socket's client authentication setting is one of the following:

  • client authentication required
  • client authentication requested
  • no client authentication desired

Unlike setNeedClientAuth(boolean), if the accepted socket's option is set and the client chooses not to provide authentication information about itself, the negotiations will continue.

Calling this method overrides any previous setting made by this method or setNeedClientAuth(boolean).

The initial inherited setting may be overridden by calling SSLSocket#setNeedClientAuth(boolean) or SSLSocket#setWantClientAuth(boolean).

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.net.ServerSocket.toString.

Doc from java.net.ServerSocket.toString.

Returns the implementation address and implementation port of this socket as a String.

Annotations
@Override