Package org.mozilla.jss.ssl.javax
Class JSSServerSocket
java.lang.Object
java.net.ServerSocket
javax.net.ssl.SSLServerSocket
org.mozilla.jss.ssl.javax.JSSServerSocket
- All Implemented Interfaces:
Closeable,AutoCloseable
SSL-enabled server socket following the javax.net.ssl.SSLServerSocket
interface.
Most users will want to use the JSSServerSocketFactory provided by the Java
Provider interface instead of using this class directly.
This SSLSocket implementation is a wrapped implementation. In particular, we
need to consume an existing ServerSocket (via the consumeSocket(...) call)
which we actually use for the accept() call. When called from a socket
factory, this additional socket will be automatically created for the
caller.
All JSSServerSocket instances have a underlying ServerSocketChannel, of type
JSSServerSocketChannel. Notably lacking from javax.net.ssl is a
javax.net.ssl.SSLServerSocketChannel interface, so JSSSocketChannel includes
no additional SSL-specific options. This purely exists to facilitate
creating JSSSocket instances.
In order to interoperate with JSSEngine, many of the adjacent methods have
been included in this class as well. This results in any accepted sockets
cloning its configuration.
To construct a (useful) new instance, the following calls must be made:
- new JSSServerSocket();
- consumeSocket(inst);
- initSSLEngine(...);
- setKeyManagers(...);
- setTrustManagers(...);
Optionally, setSSLContext(...) could be called to provide the SSLContext
from which the SSLEngine should be constructed. This should be called prior
to initSSLEngine(...) being called.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate JSSServerSocketChannelUnderlying SocketChannel for this socket; always exists.private JSSEngineJSSEngine instance to utilize for SSLEngine operations.private StringName of the SSLEngine provider to use.private StringName of the SSLEngine protocol to use.private SSLContextSSLContext to use to create the JSSEngine.private ServerSocketThe socket this JSSServerSocket was created over; accept() operations go through this socket and all information exposed via ServerSocket members go through here. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaccept()protected JSSSocketacceptSocket(Socket child) Helper to upgrade a Socket into a JSSSocket.voidbind(SocketAddress endpoint) voidbind(SocketAddress endpoint, int backlog) voidclose()voidconsumeSocket(ServerSocket parent) Consume a parent socket, utilizing it for all accept operations.Get the underlying ServerSocketChannel for this Socket.String[]Get the set of enabled cipher suites for this SSLSocket.String[]Get the set of enabled protocol versions for this SSLSocket.booleanGet whether or not this SSLSocket enables creation of new sessions.Get the underlying JSSEngine instance.protected JSSServerSocketChannelGet the internal ServerSocketChannel for this Socket.Collection<? extends EventListener>Gets the current list of event listeners this SSLSocket will fire on certain events.intbooleanGet whether or not this SSLSocket needs client authentication.<T> TgetOption(SocketOption<T> name) intbooleanintprotected SSLContextGet the SSLContext if one exists or create a new instance.Get the configuration of this SSLSocket as a JSSParameters object.String[]Get the set of supported cipher suites for this SSLSocket.String[]Get the set of supported protocol versions for this SSLSocket.booleanGet whether or not this SSLSocket is handshaking as a client.booleanGet whether or not this SSLSocket wants client authentication.private voidinit()Initialize the underlying ServerSocketChannel.voidExplicitly initialize the SSLEngine with no session resumption information.voidinitEngine(String host, int port) Explicitly initialize the SSLEngine with information for session resumption, including peer's hostname and port.booleanisBound()booleanisClosed()voidsetCertFromAlias(String alias) Set the certificate this SSLSocket will utilize from an alias in the NSS DB.voidsetEnabledCipherSuites(String[] suites) Set the list of enabled cipher suites for this SSLSocket.voidsetEnabledProtocols(String[] protocols) Set the list of enabled protocol versions for this SSLSocket.voidsetEnableSessionCreation(boolean enabled) Set whether or not this SSLSocket enables creation of new sessions.voidsetHostname(String name) Set the hostname this client socket is connecting to, for HTTPS TLS certificate validation purposes.voidSet the KeyManager this SSLSocket will utilize to select a key.voidsetKeyManagers(X509KeyManager[] xkms) Set the key managers this SSLSocket will utilize to select a key.voidsetKeyMaterials(PK11Cert our_cert, PK11PrivKey our_key) Set the certificate this SSLSocket will utilize from a certificate and its matching private key.voidsetListeners(Collection<? extends EventListener> listeners) Set the listeners this SSLSocket will fire on certain events.voidsetNeedClientAuth(boolean need) Set whether or not this SSLSocket needs client authentication.<T> ServerSocketsetOption(SocketOption<T> name, T value) voidsetPerformancePreferences(int connectionTime, int latency, int bandwidth) voidsetReceiveBufferSize(int size) voidsetReuseAddress(boolean on) voidsetSoTimeout(int timeout) voidsetSSLContext(SSLContext ctx) Explicitly set the SSLContext utilized by this JSSSocket instance.voidsetSSLParameters(SSLParameters params) Set the configuration of this SSLSocket from the given SSLParameters instance.voidSet the trust manager this SSLSocket will utilize to validate a peer's certificate.voidsetTrustManagers(X509TrustManager[] xtms) Set the trust managers this SSLSocket will utilize to validate a peer's certificate.voidsetUseClientMode(boolean client) Set whether or not this SSLSocket is handshaking as a client.voidsetWantClientAuth(boolean want) Set whether or not this SSLSocket wants client authentication.Set<SocketOption<?>>toString()Methods inherited from class java.net.ServerSocket
implAccept, setSocketFactory
-
Field Details
-
engineProviderProtocol
Name of the SSLEngine protocol to use. -
engineProvider
Name of the SSLEngine provider to use. -
jssContext
SSLContext to use to create the JSSEngine. Note that JSSSocket will fail if the context doesn't create JSSEngine instances. -
engine
JSSEngine instance to utilize for SSLEngine operations. -
parent
The socket this JSSServerSocket was created over; accept() operations go through this socket and all information exposed via ServerSocket members go through here. -
channel
Underlying SocketChannel for this socket; always exists.
-
-
Constructor Details
-
JSSServerSocket
Start building a new JSSServerSocket. We specifically avoid creating any other constructors as we wish to consume an existing socket rather than creating a new one.- Throws:
IOException
-
-
Method Details
-
consumeSocket
Consume a parent socket, utilizing it for all accept operations. This JSSServerSocket instance will inherit all information about the connection from this underlying socket. When utilized in a JSSServerSocket, callers should refrain from interacting with the underlying socket unless selective protocol upgrade should occur. In that case, it may be more appropriate to use the JSSSocketFactory method that creates server JSSSocket instances. -
getSSLContext
Get the SSLContext if one exists or create a new instance. This is used by initSSLEngine(..) to create the underlying SSLEngine.- Throws:
IOException
-
setSSLContext
Explicitly set the SSLContext utilized by this JSSSocket instance. This enables JSSServerSocket to copy its SSLContext over to the accepted JSSSocket.- Throws:
IOException
-
init
Initialize the underlying ServerSocketChannel.- Throws:
IOException
-
initEngine
Explicitly initialize the SSLEngine with no session resumption information.- Throws:
IOException
-
initEngine
Explicitly initialize the SSLEngine with information for session resumption, including peer's hostname and port.- Throws:
IOException
-
getEngine
Get the underlying JSSEngine instance. Note that, just like accessing the underlying Socket instance while the JSSSocket instance is still open is dangerous, performing other TLS operations directly via JSSEngine is also dangerous. This is mostly exposed to enable advanced configuration of the JSSEngine that isn't otherwise allowed by JSSSocket, and to facilitate the accept() method on JSSServerSocket. -
getChannel
Get the underlying ServerSocketChannel for this Socket.- Overrides:
getChannelin classServerSocket- See Also:
-
getInternalChannel
Get the internal ServerSocketChannel for this Socket. -
acceptSocket
Helper to upgrade a Socket into a JSSSocket. Called from accept in JSSServerSocket and JSSServerSocketChannel.- Throws:
IOException
-
setHostname
Set the hostname this client socket is connecting to, for HTTPS TLS certificate validation purposes.- See Also:
-
setCertFromAlias
Set the certificate this SSLSocket will utilize from an alias in the NSS DB.- Throws:
IllegalArgumentException- See Also:
-
setKeyMaterials
Set the certificate this SSLSocket will utilize from a certificate and its matching private key.- Throws:
IllegalArgumentException- See Also:
-
setKeyManager
Set the KeyManager this SSLSocket will utilize to select a key.- See Also:
-
setKeyManagers
Set the key managers this SSLSocket will utilize to select a key. -
setTrustManager
Set the trust manager this SSLSocket will utilize to validate a peer's certificate. -
setTrustManagers
Set the trust managers this SSLSocket will utilize to validate a peer's certificate. -
setListeners
Set the listeners this SSLSocket will fire on certain events.- See Also:
-
getListeners
Gets the current list of event listeners this SSLSocket will fire on certain events.- See Also:
-
getEnabledCipherSuites
Get the set of enabled cipher suites for this SSLSocket.- Specified by:
getEnabledCipherSuitesin classSSLServerSocket- See Also:
-
getSupportedCipherSuites
Get the set of supported cipher suites for this SSLSocket.- Specified by:
getSupportedCipherSuitesin classSSLServerSocket- See Also:
-
setEnabledCipherSuites
Set the list of enabled cipher suites for this SSLSocket.- Specified by:
setEnabledCipherSuitesin classSSLServerSocket- See Also:
-
getEnabledProtocols
Get the set of enabled protocol versions for this SSLSocket.- Specified by:
getEnabledProtocolsin classSSLServerSocket- See Also:
-
getSupportedProtocols
Get the set of supported protocol versions for this SSLSocket.- Specified by:
getSupportedProtocolsin classSSLServerSocket- See Also:
-
setEnabledProtocols
Set the list of enabled protocol versions for this SSLSocket.- Specified by:
setEnabledProtocolsin classSSLServerSocket- See Also:
-
getEnableSessionCreation
public boolean getEnableSessionCreation()Get whether or not this SSLSocket enables creation of new sessions.- Specified by:
getEnableSessionCreationin classSSLServerSocket- See Also:
-
setEnableSessionCreation
public void setEnableSessionCreation(boolean enabled) Set whether or not this SSLSocket enables creation of new sessions.- Specified by:
setEnableSessionCreationin classSSLServerSocket- See Also:
-
getUseClientMode
public boolean getUseClientMode()Get whether or not this SSLSocket is handshaking as a client.- Specified by:
getUseClientModein classSSLServerSocket- See Also:
-
setUseClientMode
public void setUseClientMode(boolean client) Set whether or not this SSLSocket is handshaking as a client.- Specified by:
setUseClientModein classSSLServerSocket- See Also:
-
getWantClientAuth
public boolean getWantClientAuth()Get whether or not this SSLSocket wants client authentication.- Specified by:
getWantClientAuthin classSSLServerSocket- See Also:
-
setWantClientAuth
public void setWantClientAuth(boolean want) Set whether or not this SSLSocket wants client authentication.- Specified by:
setWantClientAuthin classSSLServerSocket- See Also:
-
getNeedClientAuth
public boolean getNeedClientAuth()Get whether or not this SSLSocket needs client authentication.- Specified by:
getNeedClientAuthin classSSLServerSocket- See Also:
-
setNeedClientAuth
public void setNeedClientAuth(boolean need) Set whether or not this SSLSocket needs client authentication.- Specified by:
setNeedClientAuthin classSSLServerSocket- See Also:
-
getSSLParameters
Get the configuration of this SSLSocket as a JSSParameters object.- Overrides:
getSSLParametersin classSSLServerSocket- See Also:
-
setSSLParameters
Set the configuration of this SSLSocket from the given SSLParameters instance.- Overrides:
setSSLParametersin classSSLServerSocket- See Also:
-
accept
- Overrides:
acceptin classServerSocket- Throws:
IOException
-
bind
- Overrides:
bindin classServerSocket- Throws:
IOException
-
bind
- Overrides:
bindin classServerSocket- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classServerSocket- Throws:
IOException
-
getInetAddress
- Overrides:
getInetAddressin classServerSocket
-
getLocalPort
public int getLocalPort()- Overrides:
getLocalPortin classServerSocket
-
getLocalSocketAddress
- Overrides:
getLocalSocketAddressin classServerSocket
-
getSoTimeout
- Overrides:
getSoTimeoutin classServerSocket- Throws:
IOException
-
setSoTimeout
- Overrides:
setSoTimeoutin classServerSocket- Throws:
SocketException
-
getReuseAddress
- Overrides:
getReuseAddressin classServerSocket- Throws:
SocketException
-
setReuseAddress
- Overrides:
setReuseAddressin classServerSocket- Throws:
SocketException
-
getReceiveBufferSize
- Overrides:
getReceiveBufferSizein classServerSocket- Throws:
SocketException
-
setReceiveBufferSize
- Overrides:
setReceiveBufferSizein classServerSocket- Throws:
SocketException
-
setPerformancePreferences
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) - Overrides:
setPerformancePreferencesin classServerSocket
-
isBound
public boolean isBound()- Overrides:
isBoundin classServerSocket
-
isClosed
public boolean isClosed()- Overrides:
isClosedin classServerSocket
-
toString
- Overrides:
toStringin classServerSocket
-
setOption
- Overrides:
setOptionin classServerSocket- Throws:
IOException
-
getOption
- Overrides:
getOptionin classServerSocket- Throws:
IOException
-
supportedOptions
- Overrides:
supportedOptionsin classServerSocket
-