Package com.wolfssl.provider.jsse
Class WolfSSLSocket
- java.lang.Object
 - 
- java.net.Socket
 - 
- javax.net.ssl.SSLSocket
 - 
- com.wolfssl.provider.jsse.WolfSSLSocket
 
 
 
 
- 
- All Implemented Interfaces:
 java.io.Closeable,java.lang.AutoCloseable
public class WolfSSLSocket extends javax.net.ssl.SSLSocketwolfSSL implementation of SSLSocket- Author:
 - wolfSSL
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected booleanconnectionClosedprotected booleanhandshakeCompleteprotected booleanhandshakeInitCalled 
- 
Constructor Summary
Constructors Constructor Description WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode)WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode, java.lang.String host, int port)WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode, java.lang.String host, int port, java.net.InetAddress localHost, int localPort)WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode, java.net.InetAddress host, int port)WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode, java.net.InetAddress address, int port, java.net.InetAddress localAddress, int localPort)WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode, java.net.Socket s, boolean autoClose)WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode, java.net.Socket s, java.lang.String host, int port, boolean autoClose)WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, java.net.Socket s, java.io.InputStream consumed, boolean autoClose) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener)Registers a HandshakeCompletedListener with this SSLSocket.voidclose()Closes this SSLSocket.voidconnect(java.net.SocketAddress endpoint)Connects the underlying Socket associated with this SSLSocket.voidconnect(java.net.SocketAddress endpoint, int timeout)Connects the underlying Socket associated with this SSLSocket.protected voidfinalize()byte[]getAlpnSelectedProtocol()Return ALPN protocol established for this session.java.lang.String[]getEnabledCipherSuites()Returns array of enabled cipher suites for this Socket.java.lang.String[]getEnabledProtocols()Returns SSL/TLS protocols enabled for this SSLSocket.booleangetEnableSessionCreation()Returns whether this SSLSocket can create new sessions.java.io.InputStreamgetInputStream()Return the InputStream associated with this SSLSocket.booleangetNeedClientAuth()Return if mandatory client authentication is set for this SSLSocket.java.io.OutputStreamgetOutputStream()Return the OutputStream associated with this SSLSocket.javax.net.ssl.SSLSessiongetSession()Returns the SSLSession in use by this SSLSocket.intgetSoTimeout()Get the SO_TIMEOUT value, in milliseconds.java.lang.String[]getSupportedCipherSuites()Returns the supported cipher suite list for this socket, and that have been compiled into native wolfSSL library.java.lang.String[]getSupportedProtocols()Returns array of protocols supported by this SSLSocket.booleangetUseClientMode()Return the client mode of this SSLSocket.booleangetWantClientAuth()Returns true if SSLSocket will request client authentication.voidremoveHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener)Removes a registered HandshakeCompletedListener from this SSLSocket.voidsetAlpnProtocols(byte[] alpnProtos)Set ALPN extension protocol for this session.voidsetEnabledCipherSuites(java.lang.String[] suites)Sets the cipher suites enabled for this SSLSocket.voidsetEnabledProtocols(java.lang.String[] protocols)Sets the SSL/TLS protocols enabled on this SSLSocket.voidsetEnableSessionCreation(boolean flag)Enables this SSLSocket to create new sessions.voidsetNeedClientAuth(boolean need)Configures the SSLSocket to require client authentication.voidsetSoTimeout(int timeout)Set the SO_TIMEOUT with specified timeout in milliseconds.voidsetSSLParameters(javax.net.ssl.SSLParameters params)Set the SSLParameters for this SSLSocket.voidsetUseClientMode(boolean mode)Sets the SSLSocket to use client or server mode.voidsetUseSessionTickets(boolean useTickets)Enables use of session tickets with this session.voidsetWantClientAuth(boolean want)Configures the SSLSocket to request client authentication, but not require it.voidstartHandshake()Begins the SSL/TLS handshake on this SSLSocket.- 
Methods inherited from class javax.net.ssl.SSLSocket
getApplicationProtocol, getHandshakeApplicationProtocol, getHandshakeApplicationProtocolSelector, getHandshakeSession, getSSLParameters, setHandshakeApplicationProtocolSelector 
- 
Methods inherited from class java.net.Socket
bind, getChannel, getInetAddress, getKeepAlive, getLocalAddress, getLocalPort, getLocalSocketAddress, getOOBInline, getOption, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoLinger, getTcpNoDelay, getTrafficClass, isBound, isClosed, isConnected, isInputShutdown, isOutputShutdown, sendUrgentData, setKeepAlive, setOOBInline, setOption, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSocketImplFactory, setSoLinger, setTcpNoDelay, setTrafficClass, shutdownInput, shutdownOutput, supportedOptions, toString 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
WolfSSLSocket
public WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode) throws java.io.IOException
- Throws:
 java.io.IOException
 
- 
WolfSSLSocket
public WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode, java.net.InetAddress host, int port) throws java.io.IOException
- Throws:
 java.io.IOException
 
- 
WolfSSLSocket
public WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode, java.net.InetAddress address, int port, java.net.InetAddress localAddress, int localPort) throws java.io.IOException
- Throws:
 java.io.IOException
 
- 
WolfSSLSocket
public WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode, java.lang.String host, int port) throws java.io.IOException
- Throws:
 java.io.IOException
 
- 
WolfSSLSocket
public WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode, java.lang.String host, int port, java.net.InetAddress localHost, int localPort) throws java.io.IOException
- Throws:
 java.io.IOException
 
- 
WolfSSLSocket
public WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode, java.net.Socket s, java.lang.String host, int port, boolean autoClose) throws java.io.IOException
- Throws:
 java.io.IOException
 
- 
WolfSSLSocket
public WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, boolean clientMode, java.net.Socket s, boolean autoClose) throws java.io.IOException
- Throws:
 java.io.IOException
 
- 
WolfSSLSocket
public WolfSSLSocket(WolfSSLContext context, WolfSSLAuthStore authStore, com.wolfssl.provider.jsse.WolfSSLParameters params, java.net.Socket s, java.io.InputStream consumed, boolean autoClose) throws java.io.IOException
- Throws:
 java.io.IOException
 
 - 
 
- 
Method Detail
- 
getSupportedCipherSuites
public java.lang.String[] getSupportedCipherSuites()
Returns the supported cipher suite list for this socket, and that have been compiled into native wolfSSL library.- Specified by:
 getSupportedCipherSuitesin classjavax.net.ssl.SSLSocket- Returns:
 - array of supported cipher suite Strings
 
 
- 
getEnabledCipherSuites
public java.lang.String[] getEnabledCipherSuites()
Returns array of enabled cipher suites for this Socket. This array is pre-populated by wolfJSSE with the cipher suites supported by the native wolfSSL library- Specified by:
 getEnabledCipherSuitesin classjavax.net.ssl.SSLSocket- Returns:
 - array of enabled cipher suite Strings
 
 
- 
setEnabledCipherSuites
public void setEnabledCipherSuites(java.lang.String[] suites) throws java.lang.IllegalArgumentExceptionSets the cipher suites enabled for this SSLSocket.- Specified by:
 setEnabledCipherSuitesin classjavax.net.ssl.SSLSocket- Parameters:
 suites- array of cipher suites to enable for this Socket- Throws:
 java.lang.IllegalArgumentException- when suites array contains cipher suites unsupported by native wolfSSL
 
- 
getSupportedProtocols
public java.lang.String[] getSupportedProtocols()
Returns array of protocols supported by this SSLSocket.- Specified by:
 getSupportedProtocolsin classjavax.net.ssl.SSLSocket- Returns:
 - String array containing supported SSL/TLS protocols
 
 
- 
getEnabledProtocols
public java.lang.String[] getEnabledProtocols()
Returns SSL/TLS protocols enabled for this SSLSocket.- Specified by:
 getEnabledProtocolsin classjavax.net.ssl.SSLSocket- Returns:
 - String array containing enabled protocols
 
 
- 
setEnabledProtocols
public void setEnabledProtocols(java.lang.String[] protocols) throws java.lang.IllegalArgumentExceptionSets the SSL/TLS protocols enabled on this SSLSocket.- Specified by:
 setEnabledProtocolsin classjavax.net.ssl.SSLSocket- Parameters:
 protocols- String array of SSL/TLS protocols to enable- Throws:
 java.lang.IllegalArgumentException- when protocols array contains protocols unsupported by native wolfSSL
 
- 
setAlpnProtocols
public void setAlpnProtocols(byte[] alpnProtos)
Set ALPN extension protocol for this session. Calls native SSL_set_alpn_protos() at native level. Format starts with length, where length does not include length byte itself. Example format: Non-standard JSSE API, needed for Android compatibility. Some frameworks such as OkHttp expect this API to be here. byte[] p = "http/1.1".getBytes();- Parameters:
 alpnProtos- ALPN protocols, encoded as byte array vector
 
- 
getAlpnSelectedProtocol
public byte[] getAlpnSelectedProtocol()
Return ALPN protocol established for this session. Calls native SSL_get0_alpn_selected(). Non-standard JSSE API, needed for Android compatibility. Some frameworks such as OkHttp expect this API to be here.- Returns:
 - byte array representation of selected protocol, starting with length byte. Length does not include length byte itself.
 
 
- 
getSession
public javax.net.ssl.SSLSession getSession()
Returns the SSLSession in use by this SSLSocket.- Specified by:
 getSessionin classjavax.net.ssl.SSLSocket- Returns:
 - SSLSession object, otherwise null if not handshaking or Socket has not progressed enough to create the session
 
 
- 
addHandshakeCompletedListener
public void addHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener) throws java.lang.IllegalArgumentExceptionRegisters a HandshakeCompletedListener with this SSLSocket. The handshake completed listener will be notified when the SSL/TLS handshake on this Socket has completed.- Specified by:
 addHandshakeCompletedListenerin classjavax.net.ssl.SSLSocket- Parameters:
 listener- the handshake listener to register- Throws:
 java.lang.IllegalArgumentException- when listener is null
 
- 
removeHandshakeCompletedListener
public void removeHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener) throws java.lang.IllegalArgumentExceptionRemoves a registered HandshakeCompletedListener from this SSLSocket.- Specified by:
 removeHandshakeCompletedListenerin classjavax.net.ssl.SSLSocket- Parameters:
 listener- the listener to be removed- Throws:
 java.lang.IllegalArgumentException- if listener is null, or has not been registered wit this Socket
 
- 
startHandshake
public void startHandshake() throws java.io.IOExceptionBegins the SSL/TLS handshake on this SSLSocket.- Specified by:
 startHandshakein classjavax.net.ssl.SSLSocket- Throws:
 java.io.IOException- if a network error occurs
 
- 
setUseClientMode
public void setUseClientMode(boolean mode) throws java.lang.IllegalArgumentExceptionSets the SSLSocket to use client or server mode. This must be called before the handshake begins on this Socket.- Specified by:
 setUseClientModein classjavax.net.ssl.SSLSocket- Parameters:
 mode- true for client mode, false for server mode- Throws:
 java.lang.IllegalArgumentException- if caller tries to set the mode after handshaking has completed
 
- 
getUseClientMode
public boolean getUseClientMode()
Return the client mode of this SSLSocket.- Specified by:
 getUseClientModein classjavax.net.ssl.SSLSocket- Returns:
 - true if in client mode, otherwise false for server mode
 
 
- 
setNeedClientAuth
public void setNeedClientAuth(boolean need)
Configures the SSLSocket to require client authentication. Only useful in server mode. Similar to setWantClientAuth(), but if a client does not provide a cert/method for the server to authenticate it, the connection will fail.- Specified by:
 setNeedClientAuthin classjavax.net.ssl.SSLSocket- Parameters:
 need- true sets client auth requirement, otherwise false
 
- 
getNeedClientAuth
public boolean getNeedClientAuth()
Return if mandatory client authentication is set for this SSLSocket.- Specified by:
 getNeedClientAuthin classjavax.net.ssl.SSLSocket- Returns:
 - true if Socket has been configured to require client auth, otherwise false
 
 
- 
setWantClientAuth
public void setWantClientAuth(boolean want)
Configures the SSLSocket to request client authentication, but not require it. Similar to setNeedClientAuth(), but the handshake does not abort if the client does not send a certificate back.- Specified by:
 setWantClientAuthin classjavax.net.ssl.SSLSocket- Parameters:
 want- true to enable server to request certificate from client, false if client auth should be disabled
 
- 
getWantClientAuth
public boolean getWantClientAuth()
Returns true if SSLSocket will request client authentication. "want" client auth indicates that a server socket will request that the client sends a certificate to authenticate itself, but the server will not abort the handshake if the client does not send it.- Specified by:
 getWantClientAuthin classjavax.net.ssl.SSLSocket- Returns:
 - true if Socket will request client auth, false otherwise
 
 
- 
setEnableSessionCreation
public void setEnableSessionCreation(boolean flag)
Enables this SSLSocket to create new sessions. If this is set to false, and there are not sessions to resume, this Socket will not be allowed to create new sessions.- Specified by:
 setEnableSessionCreationin classjavax.net.ssl.SSLSocket- Parameters:
 flag- true to allow session creation, otherwise false
 
- 
getEnableSessionCreation
public boolean getEnableSessionCreation()
Returns whether this SSLSocket can create new sessions.- Specified by:
 getEnableSessionCreationin classjavax.net.ssl.SSLSocket- Returns:
 - true if this Socket can create new sessions, otherwise false
 
 
- 
setUseSessionTickets
public void setUseSessionTickets(boolean useTickets)
Enables use of session tickets with this session. Disabled by default.- Parameters:
 useTickets- true to enable session tickets, otherwise false
 
- 
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOExceptionReturn the InputStream associated with this SSLSocket.- Overrides:
 getInputStreamin classjava.net.Socket- Returns:
 - InputStream for this Socket
 - Throws:
 java.io.IOException- if InputStream is not able to be returned
 
- 
getOutputStream
public java.io.OutputStream getOutputStream() throws java.io.IOExceptionReturn the OutputStream associated with this SSLSocket.- Overrides:
 getOutputStreamin classjava.net.Socket- Returns:
 - OutputStream for this Socket
 - Throws:
 java.io.IOException- if OutputStream is not able to be returned
 
- 
setSoTimeout
public void setSoTimeout(int timeout) throws java.net.SocketExceptionSet the SO_TIMEOUT with specified timeout in milliseconds. Must be called prior to socket operations to have an effect.- Overrides:
 setSoTimeoutin classjava.net.Socket- Parameters:
 timeout- Read timeout in milliseconds, or 0 for infinite- Throws:
 java.net.SocketException- if there is an error setting the timeout value
 
- 
getSoTimeout
public int getSoTimeout() throws java.net.SocketExceptionGet the SO_TIMEOUT value, in milliseconds.- Overrides:
 getSoTimeoutin classjava.net.Socket- Returns:
 - Timeout value in milliseconds, or 0 if disabled/infinite
 - Throws:
 java.net.SocketException- if there is an error getting timeout value
 
- 
setSSLParameters
public void setSSLParameters(javax.net.ssl.SSLParameters params)
Set the SSLParameters for this SSLSocket.- Overrides:
 setSSLParametersin classjavax.net.ssl.SSLSocket- Parameters:
 params- SSLParameters to set for this SSLSocket object
 
- 
close
public void close() throws java.io.IOExceptionCloses this SSLSocket. If this socket was created with an autoClose value set to true, this will also close the underlying Socket.- Specified by:
 closein interfacejava.lang.AutoCloseable- Specified by:
 closein interfacejava.io.Closeable- Overrides:
 closein classjava.net.Socket- Throws:
 java.io.IOException- upon error closing the connection
 
- 
connect
public void connect(java.net.SocketAddress endpoint) throws java.io.IOExceptionConnects the underlying Socket associated with this SSLSocket.- Overrides:
 connectin classjava.net.Socket- Parameters:
 endpoint- address of peer to connect underlying Socket to- Throws:
 java.io.IOException- upon error connecting Socket
 
- 
connect
public void connect(java.net.SocketAddress endpoint, int timeout) throws java.io.IOExceptionConnects the underlying Socket associated with this SSLSocket.- Overrides:
 connectin classjava.net.Socket- Parameters:
 endpoint- address of peer to connect underlying socket totimeout- timeout value to set for underlying Socket connection- Throws:
 java.io.IOException- upon error connecting Socket
 
- 
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
 finalizein classjava.lang.Object- Throws:
 java.lang.Throwable
 
 - 
 
 -