public class OpenSSLSocketImpl extends SSLSocket implements NativeCrypto.SSLHandshakeCallbacks, SSLParametersImpl.AliasChooser, SSLParametersImpl.PSKCallbacks
Extensions to SSLSocket include:
| Modifier | Constructor and Description |
|---|---|
protected |
OpenSSLSocketImpl(InetAddress address,
int port,
InetAddress clientAddress,
int clientPort,
SSLParametersImpl sslParameters) |
protected |
OpenSSLSocketImpl(InetAddress address,
int port,
SSLParametersImpl sslParameters) |
protected |
OpenSSLSocketImpl(Socket socket,
String hostname,
int port,
boolean autoClose,
SSLParametersImpl sslParameters)
Create an SSL socket that wraps another socket.
|
protected |
OpenSSLSocketImpl(SSLParametersImpl sslParameters) |
protected |
OpenSSLSocketImpl(String hostname,
int port,
InetAddress clientAddress,
int clientPort,
SSLParametersImpl sslParameters) |
protected |
OpenSSLSocketImpl(String hostname,
int port,
SSLParametersImpl sslParameters) |
| Modifier and Type | Method and Description |
|---|---|
void |
addHandshakeCompletedListener(HandshakeCompletedListener listener) |
String |
chooseClientAlias(X509KeyManager keyManager,
X500Principal[] issuers,
String[] keyTypes) |
String |
chooseClientPSKIdentity(PSKKeyManager keyManager,
String identityHint) |
String |
chooseServerAlias(X509KeyManager keyManager,
String keyType) |
String |
chooseServerPSKIdentityHint(PSKKeyManager keyManager) |
void |
clientCertificateRequested(byte[] keyTypeBytes,
byte[][] asn1DerEncodedPrincipals)
Called on an SSL client when the server requests (or
requires a certificate).
|
int |
clientPSKKeyRequested(String identityHint,
byte[] identity,
byte[] key)
Gets the key to be used in client mode for this connection in Pre-Shared Key (PSK) key
exchange.
|
void |
close() |
void |
connect(SocketAddress endpoint) |
void |
connect(SocketAddress endpoint,
int timeout)
Try to extract the peer's hostname if it's available from the endpoint address.
|
protected void |
finalize() |
byte[] |
getAlpnSelectedProtocol()
Returns the protocol agreed upon by client and server, or
null if
no protocol was agreed upon. |
byte[] |
getChannelId()
Gets the TLS Channel ID for this server socket.
|
String[] |
getEnabledCipherSuites() |
String[] |
getEnabledProtocols() |
boolean |
getEnableSessionCreation() |
FileDescriptor |
getFileDescriptor$() |
SSLSession |
getHandshakeSession() |
String |
getHostname()
Returns the hostname that was supplied during socket creation.
|
String |
getHostnameOrIP()
For the purposes of an SSLSession, we want a way to represent the supplied hostname
or the IP address in a textual representation.
|
InputStream |
getInputStream() |
boolean |
getNeedClientAuth() |
byte[] |
getNpnSelectedProtocol()
Returns null always for backward compatibility.
|
OutputStream |
getOutputStream() |
int |
getPort() |
SecretKey |
getPSKKey(PSKKeyManager keyManager,
String identityHint,
String identity) |
SSLSession |
getSession() |
int |
getSoTimeout() |
int |
getSoWriteTimeout()
Note write timeouts are not part of the javax.net.ssl.SSLSocket API
|
SSLParameters |
getSSLParameters() |
String[] |
getSupportedCipherSuites() |
String[] |
getSupportedProtocols() |
boolean |
getUseClientMode() |
boolean |
getWantClientAuth() |
void |
onSSLStateChange(int type,
int val)
Called when SSL state changes.
|
void |
removeHandshakeCompletedListener(HandshakeCompletedListener listener) |
void |
sendUrgentData(int data) |
int |
serverPSKKeyRequested(String identityHint,
String identity,
byte[] key)
Gets the key to be used in server mode for this connection in Pre-Shared Key (PSK) key
exchange.
|
void |
setAlpnProtocols(byte[] alpnProtocols)
Sets the list of protocols this peer is interested in.
|
void |
setChannelIdEnabled(boolean enabled)
Enables/disables TLS Channel ID for this server socket.
|
void |
setChannelIdPrivateKey(PrivateKey privateKey)
Sets the
PrivateKey to be used for TLS Channel ID by this client socket. |
void |
setEnabledCipherSuites(String[] suites) |
void |
setEnabledProtocols(String[] protocols) |
void |
setEnableSessionCreation(boolean flag) |
void |
setHandshakeTimeout(int handshakeTimeoutMilliseconds)
Set the handshake timeout on this socket.
|
void |
setHostname(String hostname)
This method enables Server Name Indication
|
void |
setNeedClientAuth(boolean need) |
void |
setNpnProtocols(byte[] npnProtocols)
This method does nothing and is kept for backward compatibility.
|
void |
setOOBInline(boolean on) |
void |
setSoTimeout(int readTimeoutMilliseconds) |
void |
setSoWriteTimeout(int writeTimeoutMilliseconds)
Note write timeouts are not part of the javax.net.ssl.SSLSocket API
|
void |
setSSLParameters(SSLParameters p) |
void |
setUseClientMode(boolean mode) |
void |
setUseSessionTickets(boolean useSessionTickets)
This method enables session ticket support.
|
void |
setWantClientAuth(boolean want) |
void |
startHandshake()
Starts a TLS/SSL handshake on this connection using some native methods
from the OpenSSL library.
|
void |
verifyCertificateChain(long[] certRefs,
String authMethod)
Verify that we trust the certificate chain is trusted.
|
bind, getChannel, getInetAddress, getKeepAlive, getLocalAddress, getLocalPort, getLocalSocketAddress, getOOBInline, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoLinger, getTcpNoDelay, getTrafficClass, isBound, isClosed, isConnected, isInputShutdown, isOutputShutdown, setKeepAlive, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSocketImplFactory, setSoLinger, setTcpNoDelay, setTrafficClass, shutdownInput, shutdownOutput, toStringprotected OpenSSLSocketImpl(SSLParametersImpl sslParameters) throws IOException
IOExceptionprotected OpenSSLSocketImpl(String hostname, int port, SSLParametersImpl sslParameters) throws IOException
IOExceptionprotected OpenSSLSocketImpl(InetAddress address, int port, SSLParametersImpl sslParameters) throws IOException
IOExceptionprotected OpenSSLSocketImpl(String hostname, int port, InetAddress clientAddress, int clientPort, SSLParametersImpl sslParameters) throws IOException
IOExceptionprotected OpenSSLSocketImpl(InetAddress address, int port, InetAddress clientAddress, int clientPort, SSLParametersImpl sslParameters) throws IOException
IOExceptionprotected OpenSSLSocketImpl(Socket socket, String hostname, int port, boolean autoClose, SSLParametersImpl sslParameters) throws IOException
IOExceptionpublic void connect(SocketAddress endpoint) throws IOException
connect in class SocketIOExceptionpublic void connect(SocketAddress endpoint, int timeout) throws IOException
connect in class SocketIOExceptionpublic void startHandshake()
throws IOException
startHandshake in class SSLSocketIOExceptionpublic String getHostname()
public String getHostnameOrIP()
public void clientCertificateRequested(byte[] keyTypeBytes,
byte[][] asn1DerEncodedPrincipals)
throws CertificateEncodingException,
SSLException
NativeCrypto.SSLHandshakeCallbacksclientCertificateRequested in interface NativeCrypto.SSLHandshakeCallbackskeyTypeBytes - key types supported by the server,
convertible to strings with #keyTypeasn1DerEncodedPrincipals - CAs known to the serverCertificateEncodingExceptionSSLExceptionpublic int clientPSKKeyRequested(String identityHint, byte[] identity, byte[] key)
NativeCrypto.SSLHandshakeCallbacksclientPSKKeyRequested in interface NativeCrypto.SSLHandshakeCallbacksidentityHint - PSK identity hint provided by the server or null if no hint
provided.identity - buffer to be populated with PSK identity (NULL-terminated modified UTF-8)
by this method. This identity will be provided to the server.key - buffer to be populated with key material by this method.key buffer or 0 if an
error occurred in which case the handshake will be aborted.public int serverPSKKeyRequested(String identityHint, String identity, byte[] key)
NativeCrypto.SSLHandshakeCallbacksserverPSKKeyRequested in interface NativeCrypto.SSLHandshakeCallbacksidentityHint - PSK identity hint provided by this server to the client or
null if no hint was provided.identity - PSK identity provided by the client.key - buffer to be populated with key material by this method.key buffer or 0 if an
error occurred in which case the handshake will be aborted.public void onSSLStateChange(int type,
int val)
NativeCrypto.SSLHandshakeCallbacksonSSLStateChange in interface NativeCrypto.SSLHandshakeCallbackspublic void verifyCertificateChain(long[] certRefs,
String authMethod)
throws CertificateException
NativeCrypto.SSLHandshakeCallbacksverifyCertificateChain in interface NativeCrypto.SSLHandshakeCallbackscertRefs - chain of X.509 certificate referencesauthMethod - auth algorithm nameCertificateException - if the certificate is untrustedpublic InputStream getInputStream() throws IOException
getInputStream in class SocketIOExceptionpublic OutputStream getOutputStream() throws IOException
getOutputStream in class SocketIOExceptionpublic SSLSession getSession()
getSession in class SSLSocketpublic SSLSession getHandshakeSession()
getHandshakeSession in class SSLSocketpublic void addHandshakeCompletedListener(HandshakeCompletedListener listener)
addHandshakeCompletedListener in class SSLSocketpublic void removeHandshakeCompletedListener(HandshakeCompletedListener listener)
removeHandshakeCompletedListener in class SSLSocketpublic boolean getEnableSessionCreation()
getEnableSessionCreation in class SSLSocketpublic void setEnableSessionCreation(boolean flag)
setEnableSessionCreation in class SSLSocketpublic String[] getSupportedCipherSuites()
getSupportedCipherSuites in class SSLSocketpublic String[] getEnabledCipherSuites()
getEnabledCipherSuites in class SSLSocketpublic void setEnabledCipherSuites(String[] suites)
setEnabledCipherSuites in class SSLSocketpublic String[] getSupportedProtocols()
getSupportedProtocols in class SSLSocketpublic String[] getEnabledProtocols()
getEnabledProtocols in class SSLSocketpublic void setEnabledProtocols(String[] protocols)
setEnabledProtocols in class SSLSocketpublic void setUseSessionTickets(boolean useSessionTickets)
useSessionTickets - True to enable session ticketspublic void setHostname(String hostname)
hostname - the desired SNI hostname, or null to disablepublic void setChannelIdEnabled(boolean enabled)
This method needs to be invoked before the handshake starts.
IllegalStateException - if this is a client socket or if the handshake has already
started.public byte[] getChannelId()
throws SSLException
null if not available.IllegalStateException - if this is a client socket or if the handshake has not yet
completed.SSLException - if channel ID is available but could not be obtained.public void setChannelIdPrivateKey(PrivateKey privateKey)
PrivateKey to be used for TLS Channel ID by this client socket.
This method needs to be invoked before the handshake starts.
privateKey - private key (enables TLS Channel ID) or null for no key (disables
TLS Channel ID). The private key must be an Elliptic Curve (EC) key based on the NIST
P-256 curve (aka SECG secp256r1 or ANSI X9.62 prime256v1).IllegalStateException - if this is a server socket or if the handshake has already
started.public boolean getUseClientMode()
getUseClientMode in class SSLSocketpublic void setUseClientMode(boolean mode)
setUseClientMode in class SSLSocketpublic boolean getWantClientAuth()
getWantClientAuth in class SSLSocketpublic boolean getNeedClientAuth()
getNeedClientAuth in class SSLSocketpublic void setNeedClientAuth(boolean need)
setNeedClientAuth in class SSLSocketpublic void setWantClientAuth(boolean want)
setWantClientAuth in class SSLSocketpublic void sendUrgentData(int data)
throws IOException
sendUrgentData in class SocketIOExceptionpublic void setOOBInline(boolean on)
throws SocketException
setOOBInline in class SocketSocketExceptionpublic void setSoTimeout(int readTimeoutMilliseconds)
throws SocketException
setSoTimeout in class SocketSocketExceptionpublic int getSoTimeout()
throws SocketException
getSoTimeout in class SocketSocketExceptionpublic void setSoWriteTimeout(int writeTimeoutMilliseconds)
throws SocketException
SocketExceptionpublic int getSoWriteTimeout()
throws SocketException
SocketExceptionpublic void setHandshakeTimeout(int handshakeTimeoutMilliseconds)
throws SocketException
SocketExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class SocketIOExceptionprotected void finalize()
throws Throwable
public FileDescriptor getFileDescriptor$()
public byte[] getNpnSelectedProtocol()
public byte[] getAlpnSelectedProtocol()
null if
no protocol was agreed upon.public void setNpnProtocols(byte[] npnProtocols)
public void setAlpnProtocols(byte[] alpnProtocols)
null, no protocols will be used.alpnProtocols - a non-empty array of protocol names. From
SSL_select_next_proto, "vector of 8-bit, length prefixed byte
strings. The length byte itself is not included in the length.
A byte string of length 0 is invalid. No byte string may be
truncated.".public SSLParameters getSSLParameters()
getSSLParameters in class SSLSocketpublic void setSSLParameters(SSLParameters p)
setSSLParameters in class SSLSocketpublic String chooseServerAlias(X509KeyManager keyManager, String keyType)
chooseServerAlias in interface SSLParametersImpl.AliasChooserpublic String chooseClientAlias(X509KeyManager keyManager, X500Principal[] issuers, String[] keyTypes)
chooseClientAlias in interface SSLParametersImpl.AliasChooserpublic String chooseServerPSKIdentityHint(PSKKeyManager keyManager)
chooseServerPSKIdentityHint in interface SSLParametersImpl.PSKCallbackspublic String chooseClientPSKIdentity(PSKKeyManager keyManager, String identityHint)
chooseClientPSKIdentity in interface SSLParametersImpl.PSKCallbackspublic SecretKey getPSKKey(PSKKeyManager keyManager, String identityHint, String identity)
getPSKKey in interface SSLParametersImpl.PSKCallbacks