public class OpenSSLEngineImpl extends SSLEngine implements NativeCrypto.SSLHandshakeCallbacks, SSLParametersImpl.AliasChooser, SSLParametersImpl.PSKCallbacks
SSLEngine API using OpenSSL's non-blocking interfaces.| Constructor and Description |
|---|
OpenSSLEngineImpl(SSLParametersImpl sslParameters) |
OpenSSLEngineImpl(String host,
int port,
SSLParametersImpl sslParameters) |
| Modifier and Type | Method and Description |
|---|---|
void |
beginHandshake()
Initiates a handshake on this engine.
|
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 |
closeInbound()
Notifies this engine instance that no more inbound network data will be
sent to this engine.
|
void |
closeOutbound()
Notifies this engine instance that no more outbound application data will
be sent to this engine.
|
protected void |
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
Runnable |
getDelegatedTask()
Returns a delegate task for this engine instance.
|
String[] |
getEnabledCipherSuites()
Returns the SSL cipher suite names that are enabled in this engine
instance.
|
String[] |
getEnabledProtocols()
Returns the protocol version names that are enabled in this engine
instance.
|
boolean |
getEnableSessionCreation()
Returns whether new SSL sessions may be established by this engine.
|
SSLEngineResult.HandshakeStatus |
getHandshakeStatus()
Returns the status of the handshake of this engine instance.
|
boolean |
getNeedClientAuth()
Returns whether this engine instance will require client authentication.
|
SecretKey |
getPSKKey(PSKKeyManager keyManager,
String identityHint,
String identity) |
SSLSession |
getSession()
Returns the SSL session for this engine instance.
|
String[] |
getSupportedCipherSuites()
Returns the SSL cipher suite names that are supported by this engine.
|
String[] |
getSupportedProtocols()
Returns the protocol names that are supported by this engine.
|
boolean |
getUseClientMode()
Returns whether this engine is set to act in client mode when
handshaking.
|
boolean |
getWantClientAuth()
Returns whether this engine will request client authentication.
|
boolean |
isInboundDone()
Returns whether no more inbound data will be accepted by this engine.
|
boolean |
isOutboundDone()
Returns whether no more outbound data will be produced by this engine.
|
void |
onSSLStateChange(long sslSessionNativePtr,
int type,
int val)
Called when SSL state changes.
|
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 |
setEnabledCipherSuites(String[] suites)
Sets the SSL cipher suite names that should be enabled in this engine
instance.
|
void |
setEnabledProtocols(String[] protocols)
Sets the protocol version names that should be enabled in this engine
instance.
|
void |
setEnableSessionCreation(boolean flag)
Sets whether new SSL sessions may be established by this engine instance.
|
void |
setNeedClientAuth(boolean need)
Sets whether this engine must require client authentication.
|
void |
setUseClientMode(boolean mode)
Sets whether this engine should act in client (or server) mode when
handshaking.
|
void |
setWantClientAuth(boolean want)
Sets whether this engine should request client authentication.
|
SSLEngineResult |
unwrap(ByteBuffer src,
ByteBuffer[] dsts,
int offset,
int length)
Decodes the incoming network data buffer into application data buffers.
|
void |
verifyCertificateChain(long sslSessionNativePtr,
long[] certRefs,
String authMethod)
Verify that we trust the certificate chain is trusted.
|
SSLEngineResult |
wrap(ByteBuffer[] srcs,
int offset,
int length,
ByteBuffer dst)
Encodes the outgoing application data buffers into the network data
buffer.
|
getPeerHost, getPeerPort, getSSLParameters, setSSLParameters, unwrap, unwrap, wrap, wrappublic OpenSSLEngineImpl(SSLParametersImpl sslParameters)
public OpenSSLEngineImpl(String host, int port, SSLParametersImpl sslParameters)
public void beginHandshake()
throws SSLException
SSLEngine
Calling this method is not needed for the initial handshake: it will be
called by wrap or unwrap if the initial handshake has not
been started yet.
beginHandshake in class SSLEngineSSLException - if starting the handshake fails.public void closeInbound()
throws SSLException
SSLEnginecloseInbound in class SSLEngineSSLException - if this engine did not receive a needed protocol specific
close notification message from the peer.public void closeOutbound()
SSLEnginecloseOutbound in class SSLEnginepublic Runnable getDelegatedTask()
SSLEngineSSLEngineResult instances returned by this engine may indicate
that a delegated task result is needed. In this case the
run method of the returned Runnable
delegated task must be called.getDelegatedTask in class SSLEnginenull if none are available.public String[] getEnabledCipherSuites()
SSLEnginegetEnabledCipherSuites in class SSLEnginepublic String[] getEnabledProtocols()
SSLEnginegetEnabledProtocols in class SSLEnginepublic boolean getEnableSessionCreation()
SSLEnginegetEnableSessionCreation in class SSLEnginetrue if new session may be established, false if
existing sessions must be reused.public SSLEngineResult.HandshakeStatus getHandshakeStatus()
SSLEnginegetHandshakeStatus in class SSLEnginepublic boolean getNeedClientAuth()
SSLEnginegetNeedClientAuth in class SSLEnginetrue if this engine will require client authentication,
false if no client authentication is needed.public SSLSession getSession()
SSLEnginegetSession in class SSLEnginepublic String[] getSupportedCipherSuites()
SSLEngineSSLEngine.setEnabledCipherSuites(String[]).getSupportedCipherSuites in class SSLEnginepublic String[] getSupportedProtocols()
SSLEngineSSLEngine.setEnabledProtocols(String[]).getSupportedProtocols in class SSLEnginepublic boolean getUseClientMode()
SSLEnginegetUseClientMode in class SSLEnginetrue if the engine is set to do handshaking in client
mode.public boolean getWantClientAuth()
SSLEnginegetWantClientAuth in class SSLEnginetrue if client authentication will be requested,
false otherwise.public boolean isInboundDone()
SSLEngineisInboundDone in class SSLEnginetrue if no more inbound data will be accepted by this
engine, false otherwise.public boolean isOutboundDone()
SSLEngineisOutboundDone in class SSLEnginetrue if no more outbound data will be producted by this
engine, otherwise false.public void setEnabledCipherSuites(String[] suites)
SSLEnginegetSupportedCipherSuites()
are allowed.setEnabledCipherSuites in class SSLEnginesuites - the SSL cipher suite names to be enabled.public void setEnabledProtocols(String[] protocols)
SSLEnginegetSupportedProtocols() are
allowed.setEnabledProtocols in class SSLEngineprotocols - the protocol version names to be enabled.public void setEnableSessionCreation(boolean flag)
SSLEnginesetEnableSessionCreation in class SSLEngineflag - true if new SSL sessions may be established,
false if existing SSL sessions must be reused.public void setNeedClientAuth(boolean need)
SSLEngineSSLEngine.setWantClientAuth(boolean).setNeedClientAuth in class SSLEngineneed - true if client authentication is required,
false if no authentication is needed.public void setUseClientMode(boolean mode)
SSLEnginesetUseClientMode in class SSLEnginemode - true if this engine should act in client mode,
false if not.public void setWantClientAuth(boolean want)
SSLEngineSSLEngine.setNeedClientAuth(boolean).setWantClientAuth in class SSLEnginewant - true if client authentication should be requested,
false if no authentication is needed.public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int length) throws SSLException
SSLEngineunwrap in class SSLEnginesrc - the buffer with incoming network datadsts - the array of destination buffers for incoming application
data.offset - the offset in the array of destination buffers to which data
is to be transferred.length - the maximum number of destination buffers to be used.SSLException - if a problem occurred while processing the data.public SSLEngineResult wrap(ByteBuffer[] srcs, int offset, int length, ByteBuffer dst) throws SSLException
SSLEnginewrap in class SSLEnginesrcs - the array of source buffers of outgoing application data.offset - the offset in the array of source buffers from which data is
to be retrieved.length - the maximum number of source buffers to be used.dst - the destination buffer for network data.SSLException - if a problem occurred while processing the data.public 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(long sslSessionNativePtr,
int type,
int val)
NativeCrypto.SSLHandshakeCallbacksonSSLStateChange in interface NativeCrypto.SSLHandshakeCallbackspublic void verifyCertificateChain(long sslSessionNativePtr,
long[] certRefs,
String authMethod)
throws CertificateException
NativeCrypto.SSLHandshakeCallbacksverifyCertificateChain in interface NativeCrypto.SSLHandshakeCallbackssslSessionNativePtr - pointer to a reference of the SSL_SESSIONcertRefs - chain of X.509 certificate referencesauthMethod - auth algorithm nameCertificateException - if the certificate is untrustedpublic 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 serverCertificateEncodingExceptionSSLExceptionprotected void finalize()
throws Throwable
ObjectNote that objects that override finalize are significantly more expensive than
objects that don't. Finalizers may be run a long time after the object is no longer
reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
Note also that finalizers are run on a single VM-wide finalizer thread,
so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
for a class that has a native peer and needs to call a native method to destroy that peer.
Even then, it's better to provide an explicit close method (and implement
Closeable), and insist that callers manually dispose of instances. This
works well for something like files, but less well for something like a BigInteger
where typical calling code would have to deal with lots of temporaries. Unfortunately,
code that creates lots of temporaries is the worst kind of code from the point of view of
the single finalizer thread.
If you must use finalizers, consider at least providing your own
ReferenceQueue and having your own thread process that queue.
Unlike constructors, finalizers are not automatically chained. You are responsible for
calling super.finalize() yourself.
Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.
public 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