Closeable
, AutoCloseable
public abstract class SSLServerSocket extends ServerSocket
ServerSocket
and provides secure server sockets using protocols such as the Secure Sockets Layer (SSL) or Transport Layer Security (TLS) protocols. Instances of this class are generally created using an SSLServerSocketFactory
. The primary function of an SSLServerSocket
is to create SSLSocket
s by accept
ing connections.
An SSLServerSocket
contains several pieces of state data which are inherited by the SSLSocket
at socket creation. These include the enabled cipher suites and protocols, whether client authentication is necessary, and whether created sockets should begin handshaking in client or server mode. The state inherited by the created SSLSocket
can be overridden by calling the appropriate methods.
Modifier | Constructor | Description |
---|---|---|
protected |
Used only by subclasses. |
|
protected |
Used only by subclasses. |
|
protected |
Used only by subclasses. |
|
protected |
Used only by subclasses. |
Modifier and Type | Method | Description |
---|---|---|
abstract String[] |
getEnabledCipherSuites() |
Returns the list of cipher suites which are currently enabled for use by newly accepted connections. |
abstract String[] |
getEnabledProtocols() |
Returns the names of the protocols which are currently enabled for use by the newly accepted connections. |
abstract boolean |
getEnableSessionCreation() |
Returns true if new SSL sessions may be established by the sockets which are created from this server socket. |
abstract boolean |
getNeedClientAuth() |
Returns true if client authentication will be required on newly accept ed server-mode SSLSocket s. |
SSLParameters |
getSSLParameters() |
Returns the SSLParameters in effect for newly accepted connections. |
abstract String[] |
getSupportedCipherSuites() |
Returns the names of the cipher suites which could be enabled for use on an SSL connection. |
abstract String[] |
getSupportedProtocols() |
Returns the names of the protocols which could be enabled for use. |
abstract boolean |
getUseClientMode() |
Returns true if accepted connections will be in SSL client mode. |
abstract boolean |
getWantClientAuth() |
Returns true if client authentication will be requested on newly accepted server-mode connections. |
abstract void |
setEnabledCipherSuites |
Sets the cipher suites enabled for use by accepted connections. |
abstract void |
setEnabledProtocols |
Controls which particular protocols are enabled for use by accepted connections. |
abstract void |
setEnableSessionCreation |
Controls whether new SSL sessions may be established by the sockets which are created from this server socket. |
abstract void |
setNeedClientAuth |
Controls whether accept ed server-mode SSLSockets will be initially configured to require client authentication. |
void |
setSSLParameters |
Applies SSLParameters to newly accepted connections. |
abstract void |
setUseClientMode |
Controls whether accepted connections are in the (default) SSL server mode, or the SSL client mode. |
abstract void |
setWantClientAuth |
Controls whether accept ed server-mode SSLSockets will be initially configured to request client authentication. |
accept, bind, bind, close, getChannel, getInetAddress, getLocalPort, getLocalSocketAddress, getOption, getReceiveBufferSize, getReuseAddress, getSoTimeout, implAccept, isBound, isClosed, setOption, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSocketFactory, setSoTimeout, supportedOptions, toString
protected SSLServerSocket() throws IOException
Create an unbound TCP server socket using the default authentication context.
IOException
- if an I/O error occurs when creating the socketprotected SSLServerSocket(int port) throws IOException
Create a TCP server socket on a port, using the default authentication context. The connection backlog defaults to fifty connections queued up before the system starts to reject new connection requests.
A port number of 0
creates a socket on any free port.
If there is a security manager, its checkListen
method is called with the port
argument as its argument to ensure the operation is allowed. This could result in a SecurityException.
port
- the port on which to listenIOException
- if an I/O error occurs when creating the socketSecurityException
- if a security manager exists and its checkListen
method doesn't allow the operation.IllegalArgumentException
- if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.protected SSLServerSocket(int port, int backlog) throws IOException
Create a TCP server socket on a port, using the default authentication context and a specified backlog of connections.
A port number of 0
creates a socket on any free port.
The backlog
argument is the requested maximum number of pending connections on the socket. Its exact semantics are implementation specific. In particular, an implementation may impose a maximum length or may choose to ignore the parameter altogether. The value provided should be greater than 0
. If it is less than or equal to 0
, then an implementation specific default will be used.
If there is a security manager, its checkListen
method is called with the port
argument as its argument to ensure the operation is allowed. This could result in a SecurityException.
port
- the port on which to listenbacklog
- requested maximum length of the queue of incoming connections.IOException
- if an I/O error occurs when creating the socketSecurityException
- if a security manager exists and its checkListen
method doesn't allow the operation.IllegalArgumentException
- if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.protected SSLServerSocket(int port, int backlog, InetAddress address) throws IOException
Create a TCP server socket on a port, using the default authentication context and a specified backlog of connections as well as a particular specified network interface. This constructor is used on multihomed hosts, such as those used for firewalls or as routers, to control through which interface a network service is provided.
If there is a security manager, its checkListen
method is called with the port
argument as its argument to ensure the operation is allowed. This could result in a SecurityException.
A port number of 0
creates a socket on any free port.
The backlog
argument is the requested maximum number of pending connections on the socket. Its exact semantics are implementation specific. In particular, an implementation may impose a maximum length or may choose to ignore the parameter altogether. The value provided should be greater than 0
. If it is less than or equal to 0
, then an implementation specific default will be used.
If address is null, it will default accepting connections on any/all local addresses.
port
- the port on which to listenbacklog
- requested maximum length of the queue of incoming connections.address
- the address of the network interface through which connections will be acceptedIOException
- if an I/O error occurs when creating the socketSecurityException
- if a security manager exists and its checkListen
method doesn't allow the operation.IllegalArgumentException
- if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.public abstract String[] getEnabledCipherSuites()
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.
public abstract void setEnabledCipherSuites(String[] suites)
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.
SSLSocket
s returned from accept()
inherit this setting.
suites
- Names of all the cipher suites to enableIllegalArgumentException
- when one or more of ciphers named by the parameter is not supported, or when the parameter is null.public abstract String[] getSupportedCipherSuites()
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.
public abstract String[] getSupportedProtocols()
public abstract String[] getEnabledProtocols()
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.
public abstract void setEnabledProtocols(String[] protocols)
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.
SSLSocket
s returned from accept()
inherit this setting.
protocols
- Names of all the protocols to enable.IllegalArgumentException
- when one or more of the protocols named by the parameter is not supported or when the protocols parameter is null.public abstract void setNeedClientAuth(boolean need)
accept
ed server-mode SSLSockets
will be initially configured to require client authentication. A socket's client authentication setting is one of the following:
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)
.
need
- set to true if client authentication is required, or false if no client authentication is desired.public abstract boolean getNeedClientAuth()
accept
ed server-mode SSLSocket
s. The initial inherited setting may be overridden by calling SSLSocket.setNeedClientAuth(boolean)
or SSLSocket.setWantClientAuth(boolean)
.
public abstract void setWantClientAuth(boolean want)
accept
ed server-mode SSLSockets
will be initially configured to request client authentication. A socket's client authentication setting is one of the following:
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)
.
want
- set to true if client authentication is requested, or false if no client authentication is desired.public abstract boolean getWantClientAuth()
The initial inherited setting may be overridden by calling SSLSocket.setNeedClientAuth(boolean)
or SSLSocket.setWantClientAuth(boolean)
.
public abstract void setUseClientMode(boolean 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.
SSLSocket
s returned from accept()
inherit this setting.
mode
- true if newly accepted connections should use SSL client mode.public abstract boolean getUseClientMode()
public abstract void setEnableSessionCreation(boolean flag)
SSLSocket
s returned from accept()
inherit this setting.
flag
- true indicates that sessions may be created; this is the default. false indicates that an existing session must be resumed.public abstract boolean getEnableSessionCreation()
public SSLParameters getSSLParameters()
public void setSSLParameters(SSLParameters params)
This means:
params.getCipherSuites()
is non-null, setEnabledCipherSuites()
is called with that value.params.getProtocols()
is non-null, setEnabledProtocols()
is called with that value.params.getNeedClientAuth()
or params.getWantClientAuth()
return true
, setNeedClientAuth(true)
and setWantClientAuth(true)
are called, respectively; otherwise setWantClientAuth(false)
is called.params.getServerNames()
is non-null, the socket will configure its server names with that value.params.getSNIMatchers()
is non-null, the socket will configure its SNI matchers with that value.params
- the parametersIllegalArgumentException
- if the setEnabledCipherSuites() or the setEnabledProtocols() call fails
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/javax/net/ssl/SSLServerSocket.html