public abstract class SSLServerSocket
extends ServerSocket
| java.lang.Object | ||
| java.net.ServerSocket | ||
| javax.net.ssl.SSLServerSocket | ||
该类扩展了 ServerSocket并使用诸如安全套接字层(SSL)或传输层安全性(TLS)协议等协议提供安全的服务器套接字。
此类的实例通常使用SSLServerSocketFactory创建。 SSLServerSocket的主要功能是通过accept连接创建SSLSocket 。
SSLServerSocket包含创建套接字时由SSLSocket继承的多条状态数据。 这些包括已启用的密码套件和协议,是否需要客户端身份验证,以及创建的套接字是否应以客户端或服务器模式开始握手。 通过调用适当的方法可以覆盖创建的SSLSocket继承的状态。
也可以看看:
Protected constructors |
|
|---|---|
SSLServerSocket() 仅用于子类。 |
|
SSLServerSocket(int port) 仅用于子类。 |
|
SSLServerSocket(int port, int backlog) 仅用于子类。 |
|
SSLServerSocket(int port, int backlog, InetAddress address) 仅用于子类。 |
|
公共方法(Public methods) |
|
|---|---|
abstract boolean |
getEnableSessionCreation() 如果新SSL会话可能由从此服务器套接字创建的套接字建立,则返回true。 |
abstract String[] |
getEnabledCipherSuites() 返回当前启用供新接受的连接使用的密码套件列表。 |
abstract String[] |
getEnabledProtocols() 返回当前为新接受的连接启用的协议的名称。 |
abstract boolean |
getNeedClientAuth() 如果在新的 |
SSLParameters |
getSSLParameters() 返回对新接受的连接有效的SSLParameters。 |
abstract String[] |
getSupportedCipherSuites() 返回可用于SSL连接的密码套件的名称。 |
abstract String[] |
getSupportedProtocols() 返回可以启用使用的协议的名称。 |
abstract boolean |
getUseClientMode() 如果接受的连接将处于SSL客户端模式,则返回true。 |
abstract boolean |
getWantClientAuth() 如果将在新接受的服务器模式连接上 请求客户端身份验证,则返回true。 |
abstract void |
setEnableSessionCreation(boolean flag) 控制是否可以通过从此服务器套接字创建的套接字建立新的SSL会话。 |
abstract void |
setEnabledCipherSuites(String[] suites) 将密码套件设置为启用以供接受的连接使用。 |
abstract void |
setEnabledProtocols(String[] protocols) 控制哪些特定协议已启用供接受的连接使用。 |
abstract void |
setNeedClientAuth(boolean need) 控制是否将 |
void |
setSSLParameters(SSLParameters params) 将SSLParameters应用于新接受的连接。 |
abstract void |
setUseClientMode(boolean mode) 控制接受的连接是否处于(默认)SSL服务器模式或SSL客户端模式。 |
abstract void |
setWantClientAuth(boolean want) 控制 |
继承方法(Inherited methods) |
|
|---|---|
java.net.ServerSocket
|
|
java.lang.Object
|
|
java.io.Closeable
|
|
java.lang.AutoCloseable
|
|
SSLServerSocket ()
仅用于子类。
使用默认的认证上下文创建一个未绑定的TCP服务器套接字。
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs when creating the socket |
SSLServerSocket (int port)
仅用于子类。
使用默认的认证上下文在端口上创建TCP服务器套接字。 在系统开始拒绝新的连接请求之前,连接待办事项默认为50个排队连接。
端口号 0在任何空闲端口上创建一个套接字。
如果存在安全管理器,则使用port参数作为其参数调用其checkListen方法,以确保允许操作。 这可能会导致SecurityException。
| 参数(Parameters) | |
|---|---|
port |
int: the port on which to listen |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs when creating the socket |
SecurityException |
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. |
也可以看看:
SSLServerSocket (int port,
int backlog)
仅用于子类。
在端口上创建一个TCP服务器套接字,使用默认的认证上下文和指定的连接积压。
端口号 0在任何空闲端口上创建一个套接字。
backlog参数是套接字上请求的最大挂起连接数。 其确切的语义是特定于实现的。 特别是,实现可能会施加最大长度,或者可能选择忽略参数altogther。 所提供的值应该大于0 。 如果它小于或等于0 ,那么将使用特定于实现的默认值。
如果有安全管理器,则使用port参数作为其参数调用其checkListen方法,以确保允许操作。 这可能会导致SecurityException。
| 参数(Parameters) | |
|---|---|
port |
int: the port on which to listen |
backlog |
int: requested maximum length of the queue of incoming connections. |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs when creating the socket |
SecurityException |
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. |
也可以看看:
SSLServerSocket (int port,
int backlog,
InetAddress address)
仅用于子类。
在端口上创建一个TCP服务器套接字,使用默认的认证上下文和指定的连接积压以及特定的指定网络接口。 此构造函数用于多宿主主机(如用于防火墙或路由器的主机),以控制通过哪个接口提供网络服务。
如果存在安全管理器,则使用port参数作为其参数调用其checkListen方法,以确保允许操作。 这可能会导致SecurityException。
端口号 0在任何空闲端口上创建一个套接字。
backlog参数是套接字上请求的最大挂起连接数。 其确切的语义是特定于实现的。 特别是,实现可能会施加最大长度,或者可能选择忽略参数altogther。 提供的值应该大于0 。 如果它小于或等于0 ,那么将使用特定于实现的默认值。
如果 地址为空,它将默认接受任何/所有本地地址上的连接。
| 参数(Parameters) | |
|---|---|
port |
int: the port on which to listen |
backlog |
int: requested maximum length of the queue of incoming connections. |
address |
InetAddress: the address of the network interface through which connections will be accepted |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs when creating the socket |
SecurityException |
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. |
也可以看看:
boolean getEnableSessionCreation ()
如果新SSL会话可能由从此服务器套接字创建的套接字建立,则返回true。
| 返回(Returns) | |
|---|---|
boolean |
true indicates that sessions may be created; this is the default. false indicates that an existing session must be resumed |
String[] getEnabledCipherSuites ()
返回当前启用供新接受的连接使用的密码套件列表。
如果此列表未被明确修改,则系统提供的默认值可保证所有启用的密码套件中的最低服务质量。
启用密码套件可能实际上未被使用的原因有几个。 例如:服务器套接字可能没有适当的私钥可用,或者密码套件可能是匿名的,从而排除了使用客户端身份验证的情况,而服务器套接字已被告知需要这种身份验证。
| 返回(Returns) | |
|---|---|
String[] |
an array of cipher suites enabled |
String[] getEnabledProtocols ()
返回当前为新接受的连接启用的协议的名称。
| 返回(Returns) | |
|---|---|
String[] |
an array of protocol names |
boolean getNeedClientAuth ()
如果在新的 accept ed服务器模式 SSLSocket上 需要客户端身份验证,则返回true。
通过调用 setNeedClientAuth(boolean)或 setWantClientAuth(boolean)可以覆盖最初的继承设置。
| 返回(Returns) | |
|---|---|
boolean |
true if client authentication is required, or false if no client authentication is desired. |
SSLParameters getSSLParameters ()
返回对新接受的连接有效的SSLParameters。 返回的SSLParameters的密码组和协议始终为非空值。
| 返回(Returns) | |
|---|---|
SSLParameters |
the SSLParameters in effect for newly accepted connections |
String[] getSupportedCipherSuites ()
返回可用于SSL连接的密码套件的名称。
通常,默认情况下,只有这些列表中的一部分会实际启用,因为此列表可能包含不符合服务质量要求的密码套件。 这种密码套件在专门的应用程序中很有用。
| 返回(Returns) | |
|---|---|
String[] |
an array of cipher suite names |
String[] getSupportedProtocols ()
返回可以启用使用的协议的名称。
| 返回(Returns) | |
|---|---|
String[] |
an array of protocol names supported |
boolean getUseClientMode ()
如果接受的连接将处于SSL客户端模式,则返回true。
| 返回(Returns) | |
|---|---|
boolean |
true if the connection should use SSL client mode. |
也可以看看:
boolean getWantClientAuth ()
如果将在新接受的服务器模式连接上 请求客户端身份验证,则返回true。
调用 setNeedClientAuth(boolean)或 setWantClientAuth(boolean)可以覆盖最初的继承设置。
| 返回(Returns) | |
|---|---|
boolean |
true if client authentication is requested, or false if no client authentication is desired. |
void setEnableSessionCreation (boolean flag)
控制是否可以通过从此服务器套接字创建的套接字建立新的SSL会话。
SSLSocket期从返回 accept()继承此设置。
| 参数(Parameters) | |
|---|---|
flag |
boolean: true indicates that sessions may be created; this is the default. false indicates that an existing session must be resumed. |
也可以看看:
void setEnabledCipherSuites (String[] suites)
将密码套件设置为启用以供接受的连接使用。
密码套件必须已被getSupportedCipherSuites()列为受支持。 在成功调用此方法后,仅启用suites参数中列出的套件以供使用。
要求在此ServerSocket的身份验证上下文中不可用的身份验证信息的套件在任何情况下都不会被使用,即使它们已启用。
SSLSocket期从返回 accept()继承此设置。
| 参数(Parameters) | |
|---|---|
suites |
String: Names of all the cipher suites to enable |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
when one or more of ciphers named by the parameter is not supported, or when the parameter is null. |
void setEnabledProtocols (String[] protocols)
控制哪些特定协议已启用供接受的连接使用。
该协议必须已被getSupportedProtocols()列为受支持。 成功调用此方法后,仅启用protocols参数中列出的协议才能使用。
SSLSocket从 accept()返回,继承此设置。
| 参数(Parameters) | |
|---|---|
protocols |
String: Names of all the protocols to enable. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
when one or more of the protocols named by the parameter is not supported or when the protocols parameter is null. |
void setNeedClientAuth (boolean need)
控制是否将 accept ed服务器模式 SSLSockets初始配置为 需要客户端身份验证。
套接字的客户端身份验证设置是以下之一:
与 setWantClientAuth(boolean)不同,如果接受的套接字的选项已设置,并且客户端选择不提供有关其自身的身份验证信息, 则协商将停止并且连接将被丢弃 。
调用此方法将覆盖此方法或 setWantClientAuth(boolean)所做的任何以前的设置。
通过调用 setNeedClientAuth(boolean)或 setWantClientAuth(boolean)可以覆盖初始的继承设置。
| 参数(Parameters) | |
|---|---|
need |
boolean: set to true if client authentication is required, or false if no client authentication is desired. |
void setSSLParameters (SSLParameters params)
将SSLParameters应用于新接受的连接。
意即:
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. | 参数(Parameters) | |
|---|---|
params |
SSLParameters: the parameters |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if the setEnabledCipherSuites() or the setEnabledProtocols() call fails |
也可以看看:
void setUseClientMode (boolean mode)
控制接受的连接是否处于(默认)SSL服务器模式或SSL客户端模式。
服务器通常会对自己进行身份验证,并且客户端不需要这样做。
在极少数情况下,TCP服务器需要在新接受的连接上以SSL客户端模式运行。 例如,FTP客户端获取服务器套接字并在那里侦听来自服务器的反向连接。 FTP客户端在“客户端”模式下使用SSLServerSocket来接受反向连接,而FTP服务器使用禁用“客户端”模式的SSLSocket来启动连接。 在产生的握手过程中,现有的SSL会话可能会被重用。
SSLSocket期从返回 accept()继承此设置。
| 参数(Parameters) | |
|---|---|
mode |
boolean: true if newly accepted connections should use SSL client mode. |
也可以看看:
void setWantClientAuth (boolean want)
控制 accept ed服务器模式 SSLSockets将最初配置为 请求客户端身份验证。
套接字的客户端身份验证设置是以下之一:
与 setNeedClientAuth(boolean)不同,如果设置了接受的套接字选项并且客户端选择不提供关于其自身的身份验证信息, 则协商将继续 。
调用此方法将覆盖此方法或 setNeedClientAuth(boolean)所做的任何以前的设置。
通过调用 setNeedClientAuth(boolean)或 setWantClientAuth(boolean)可以覆盖最初的继承设置。
| 参数(Parameters) | |
|---|---|
want |
boolean: set to true if client authentication is requested, or false if no client authentication is desired. |