Top Description Inners Fields Constructors Methods
io.netty5.handler.ssl

public Class ReferenceCountedOpenSslEngine

extends SSLEngine
implements ReferenceCounted, ApplicationProtocolAccessor, VectoredUnwrap
Class Inheritance
All Implemented Interfaces
io.netty5.handler.ssl.VectoredUnwrap, io.netty5.handler.ssl.ApplicationProtocolAccessor, io.netty5.util.ReferenceCounted
Known Direct Subclasses
io.netty5.handler.ssl.OpenSslEngine
Imports
io.netty.internal.tcnative.AsyncTask, .SSL, io.netty5.buffer.Buffer, .BufferAllocator, .DefaultBufferAllocators, .StandardAllocationTypes, io.netty5.handler.ssl.util.LazyJavaxX509Certificate, .LazyX509Certificate, io.netty5.util.AbstractReferenceCounted, .ReferenceCounted, .ResourceLeakDetector, .ResourceLeakDetectorFactory, .ResourceLeakTracker, io.netty5.util.internal.EmptyArrays, .PlatformDependent, .StringUtil, .UnstableApi, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, javax.crypto.spec.SecretKeySpec, javax.net.ssl.ExtendedSSLSession, .SNIHostName, .SNIMatcher, .SNIServerName, .SSLEngine, .SSLEngineResult, .SSLException, .SSLHandshakeException, .SSLParameters, .SSLPeerUnverifiedException, .SSLSession, .SSLSessionBindingEvent, .SSLSessionBindingListener, javax.security.cert.X509Certificate, java.nio.ByteBuffer, .ReadOnlyBufferException, java.nio.charset.StandardCharsets, java.security.AlgorithmConstraints, .Principal, java.security.cert.Certificate, java.util.ArrayList, .Arrays, .Collection, .Collections, .HashMap, .HashSet, .LinkedHashSet, .List, .Map, .Objects, .Set, java.util.concurrent.locks.Lock

Implements a SSLEngine using OpenSSL BIO abstractions.

Instances of this class must be released or else native memory will leak!

Instances of this class must be released before the ReferenceCountedOpenSslContext the instance depends upon are released. Otherwise if any method of this class is called which uses the the ReferenceCountedOpenSslContext JNI resources the JVM may crash.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
private static enum
private class

Field Summary

Modifier and TypeField and Description
private AlgorithmConstraints
pack-priv final BufferAllocator
private final OpenSslApplicationProtocolNegotiator
apn

Deprecated as a consequence of OpenSslApplicationProtocolNegotiator being deprecated.
private volatile String
private volatile ClientAuth
private final boolean
private static final SSLEngineResult
private volatile boolean
private static final ByteBuffer
private final boolean
private String
private final OpenSslEngineMap
private String[]
private ReferenceCountedOpenSslEngine.HandshakeState
private boolean
pack-priv final boolean
private volatile long
private final ResourceLeakTracker<ReferenceCountedOpenSslEngine>
private static final ResourceLeakDetector<ReferenceCountedOpenSslEngine>
private static final String[]
private static final InternalLogger
private volatile Collection<SNIMatcher>
pack-priv static final int
MAX_PLAINTEXT_LENGTH

Depends upon tcnative ...

pack-priv static final int
MAX_RECORD_SIZE

Depends upon tcnative ...

private int
private int
private static final SSLEngineResult
private static final SSLEngineResult
private static final SSLEngineResult
private static final SSLEngineResult
private volatile boolean
private long
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int[]
private boolean
private final ReferenceCountedOpenSslContext
private Throwable
private boolean
private final AbstractReferenceCounted
private final OpenSslSession
private boolean
private final ByteBuffer[]
private final ByteBuffer[]
private List<SNIServerName>
private long

Constructor Summary

AccessConstructor and Description
pack-priv
ReferenceCountedOpenSslEngine(ReferenceCountedOpenSslContext
Reference count release responsibility is not transferred! The callee still owns this object.
context
,
final BufferAllocator
The allocator to use.
alloc
,
String
The peer host name.
peerHost
,
int
The peer port.
peerPort
,
boolean
true to behave like described in https://docs.oracle.com/javase/7/docs/api/javax/net/ssl/SSLEngine.html. false allows for partial and/or multiple packets to be process in a single wrap or unwrap call.
jdkCompatibilityMode
,
boolean
true to enable leak detection of this object.
leakDetection
)

Create a new instance.

Method Summary

Modifier and TypeMethod and Description
pack-priv final synchronized String[]
public final synchronized void
beginHandshake()

Implements abstract javax.net.ssl.SSLEngine.beginHandshake.

Initiates handshaking (initial or renegotiation) on this SSLEngine.
pack-priv synchronized void
bioSetFd(int fd)

private static long
pack-priv final int
calculateMaxLengthForWrap(int plaintextLength, int numComponents)

This method is intentionally not synchronized, only use if you know you are in the EventLoop thread and visibility on maxWrapBufferSize and maxWrapOverhead is achieved via other synchronized blocks.

private void
calculateMaxWrapOverhead()

It is assumed this method is called in a synchronized block (or the constructor)!

private void
pack-priv final boolean
checkSniHostnameMatch(byte[] hostname)

private void
public final synchronized void
closeInbound()

Implements abstract javax.net.ssl.SSLEngine.closeInbound.

Signals that no more inbound network data will be sent to this SSLEngine.
public final synchronized void
closeOutbound()

Implements abstract javax.net.ssl.SSLEngine.closeOutbound.

Signals that no more outbound application data will be sent on this SSLEngine.
private boolean

Returns:

false if the call to SSL#shutdownSSL(long) was not attempted or returned an error.
doSSLShutdown
()

Attempt to call SSL#shutdownSSL(long).

public String
getApplicationProtocol()

Overrides javax.net.ssl.SSLEngine.getApplicationProtocol.

Returns the most recent application protocol value negotiated for this connection.
public final synchronized Runnable
getDelegatedTask()

Implements abstract javax.net.ssl.SSLEngine.getDelegatedTask.

Returns a delegated Runnable task for this SSLEngine.
public final String[]
getEnabledCipherSuites()

Implements abstract javax.net.ssl.SSLEngine.getEnabledCipherSuites.

Returns the names of the SSL cipher suites which are currently enabled for use on this engine.
public final String[]
getEnabledProtocols()

Implements abstract javax.net.ssl.SSLEngine.getEnabledProtocols.

Returns the names of the protocol versions which are currently enabled for use with this SSLEngine.
public final boolean
getEnableSessionCreation()

Implements abstract javax.net.ssl.SSLEngine.getEnableSessionCreation.

Returns true if new SSL sessions may be established by this engine.
public String
getHandshakeApplicationProtocol()

Overrides javax.net.ssl.SSLEngine.getHandshakeApplicationProtocol.

Returns the application protocol value negotiated on a SSL/TLS handshake currently in progress.
public final synchronized SSLSession
getHandshakeSession()

Overrides javax.net.ssl.SSLEngine.getHandshakeSession.

Returns the SSLSession being constructed during a SSL/TLS/DTLS handshake.
public final synchronized SSLEngineResult.HandshakeStatus
getHandshakeStatus()

Implements abstract javax.net.ssl.SSLEngine.getHandshakeStatus.

Returns the current handshake status for this SSLEngine.
private SSLEngineResult.HandshakeStatus
getHandshakeStatus(int pending)

public final boolean
getNeedClientAuth()

Implements abstract javax.net.ssl.SSLEngine.getNeedClientAuth.

Returns true if the engine will require client authentication.
public String
getNegotiatedApplicationProtocol()

Implements io.netty5.handler.ssl.ApplicationProtocolAccessor.getNegotiatedApplicationProtocol.

Returns the name of the negotiated application-level protocol.
public byte[]
getOcspResponse()

Returns the OCSP response or null if the server didn't provide a stapled OCSP response.

public final SSLSession
getSession()

Implements abstract javax.net.ssl.SSLEngine.getSession.

Returns the SSLSession in use in this SSLEngine.
public final synchronized SSLParameters
getSSLParameters()

Overrides javax.net.ssl.SSLEngine.getSSLParameters.

Returns the SSLParameters in effect for this SSLEngine.
public final String[]
getSupportedCipherSuites()

Implements abstract javax.net.ssl.SSLEngine.getSupportedCipherSuites.

Returns the names of the cipher suites which could be enabled for use on this engine.
public final String[]
getSupportedProtocols()

Implements abstract javax.net.ssl.SSLEngine.getSupportedProtocols.

Returns the names of the protocols which could be enabled for use with this SSLEngine.
public final boolean
getUseClientMode()

Implements abstract javax.net.ssl.SSLEngine.getUseClientMode.

Returns true if the engine is set to use client mode when handshaking.
public final boolean
getWantClientAuth()

Implements abstract javax.net.ssl.SSLEngine.getWantClientAuth.

Returns true if the engine will request client authentication.
private SSLEngineResult
handleUnwrapException(int bytesConsumed, int bytesProduced, SSLException e)

private SSLEngineResult.HandshakeStatus
private SSLEngineResult.HandshakeStatus
pack-priv final void
initHandshakeException(Throwable cause)

Should be called if the handshake will be failed due a callback that throws an exception.

private boolean
isBytesAvailableEnoughForWrap(int bytesAvailable, int plaintextLength, int numComponents)

private boolean
private static boolean
isEmpty(Object[] arr)

private static boolean
isEmpty(byte[] cert)

private static boolean
isEndPointVerificationEnabled(String endPointIdentificationAlgorithm)

public final synchronized boolean
isInboundDone()

Implements abstract javax.net.ssl.SSLEngine.isInboundDone.

Returns whether unwrap(ByteBuffer, ByteBuffer) will accept any more inbound data messages.
public final synchronized boolean
isOutboundDone()

Implements abstract javax.net.ssl.SSLEngine.isOutboundDone.

Returns whether wrap(ByteBuffer, ByteBuffer) will produce any more outbound data messages.
private static boolean
isProtocolEnabled(int opts, int disableMask, String protocolString)

pack-priv synchronized boolean
pack-priv final synchronized SecretKeySpec
pack-priv final synchronized int
maxEncryptedPacketLength()

Visible only for testing!

pack-priv final int
maxEncryptedPacketLength0()

This method is intentionally not synchronized, only use if you know you are in the EventLoop thread and visibility on maxWrapOverhead is achieved via other synchronized blocks.

pack-priv final synchronized int
maxWrapOverhead()

Visible only for testing!

private SSLEngineResult.HandshakeStatus
mayFinishHandshake(SSLEngineResult.HandshakeStatus hs, int bytesConsumed, int bytesProduced)

private SSLEngineResult.HandshakeStatus
private boolean
private boolean
needWrapAgain(int stackError)

private SSLEngineResult
newResult(SSLEngineResult.HandshakeStatus hs, int bytesConsumed, int bytesProduced)

private SSLEngineResult
newResult(SSLEngineResult.Status status, SSLEngineResult.HandshakeStatus hs, int bytesConsumed, int bytesProduced)

private SSLEngineResult
newResultMayFinishHandshake(SSLEngineResult.HandshakeStatus hs, int bytesConsumed, int bytesProduced)

private SSLEngineResult
newResultMayFinishHandshake(SSLEngineResult.Status status, SSLEngineResult.HandshakeStatus hs, int bytesConsumed, int bytesProduced)

private static SSLEngineResult.HandshakeStatus
pendingStatus(int pendingStatus)

private int
readPlaintextData(final ByteBuffer dst)

Read plaintext data from the OpenSSL internal BIO

public final int
refCnt()

Implements io.netty5.util.ReferenceCounted.refCnt.

Returns the reference count of this object.
private void
public final boolean
release()

Implements io.netty5.util.ReferenceCounted.release.

Decreases the reference count by 1 and deallocates this object if the reference count reaches at 0.
public final boolean
release(int decrement)

Implements io.netty5.util.ReferenceCounted.release.

Decreases the reference count by the specified decrement and deallocates this object if the reference count reaches at 0.
private static void
private void
private void
public final ReferenceCounted
retain()

Implements io.netty5.util.ReferenceCounted.retain.

Increases the reference count by 1.
public final ReferenceCounted
retain(int increment)

Implements io.netty5.util.ReferenceCounted.retain.

Increases the reference count by the specified increment.
private synchronized void
private void
selectApplicationProtocol()

Select the application protocol used.

private static String
private void
public final void
setEnabledCipherSuites(String[]
Names of all the cipher suites to enable
cipherSuites
)

Implements abstract javax.net.ssl.SSLEngine.setEnabledCipherSuites.

Sets the cipher suites enabled for use on this engine.
public final void
setEnabledProtocols(String[]
Names of all the protocols to enable.
protocols
)

Implements abstract javax.net.ssl.SSLEngine.setEnabledProtocols.

Set the protocol versions enabled for use on this engine.
private void
setEnabledProtocols0(String[] protocols, boolean cache)

public final void
setEnableSessionCreation(boolean
true indicates that sessions may be created; this is the default. false indicates that an existing session must be resumed
b
)

Implements abstract javax.net.ssl.SSLEngine.setEnableSessionCreation.

Controls whether new SSL sessions may be established by this engine.
pack-priv final boolean
public final void
setNeedClientAuth(boolean
set to true if client authentication is required, or false if no client authentication is desired.
b
)

Implements abstract javax.net.ssl.SSLEngine.setNeedClientAuth.

Configures the engine to require client authentication.
public void
setOcspResponse(byte[] response)

Sets the OCSP response.

pack-priv final void
public final synchronized void
setSSLParameters(SSLParameters
the parameters
sslParameters
)

Overrides javax.net.ssl.SSLEngine.setSSLParameters.

Applies SSLParameters to this engine.
public final void
setUseClientMode(boolean
true if the engine should start its handshaking in "client" mode
clientMode
)

Implements abstract javax.net.ssl.SSLEngine.setUseClientMode.

Configures the engine to use client (or server) mode when handshaking.
public final synchronized void
setVerify(int verifyMode, int depth)

See SSL_set_verify and SSL#setVerify(long, int, int).

public final void
setWantClientAuth(boolean
set to true if client authentication is requested, or false if no client authentication is desired.
b
)

Implements abstract javax.net.ssl.SSLEngine.setWantClientAuth.

Configures the engine to request client authentication.
public final synchronized void
shutdown()

Destroys this engine.

private SSLException
shutdownWithError(String operations, int sslError)

Log the error, shutdown the engine and throw an exception.

private SSLException
shutdownWithError(String operation, int sslError, int error)

private ByteBuffer[]
private ByteBuffer[]
pack-priv final synchronized int
private int
public final synchronized long
sslPointer()

Returns the pointer to the SSL object for this ReferenceCountedOpenSslEngine.

private SSLEngineResult
sslReadErrorResult(int error, int stackError, int bytesConsumed, int bytesProduced)

private String
toJavaCipherSuite(String openSslCipherSuite)

Converts the specified OpenSSL cipher suite to the Java cipher suite.

private static String
toJavaCipherSuitePrefix(String protocolVersion)

Converts the protocol version string returned by SSL#getVersion(long) to protocol family string.

public final ReferenceCounted
touch()

Implements io.netty5.util.ReferenceCounted.touch.

Records the current access location of this object for debugging purposes.
public final ReferenceCounted
touch(Object hint)

Implements io.netty5.util.ReferenceCounted.touch.

Records the current access location of this object with an additional arbitrary information for debugging purposes.
public final SSLEngineResult
unwrap(final ByteBuffer[] srcs, int srcsOffset, final int srcsLength, final ByteBuffer[] dsts, int dstsOffset, final int dstsLength)

public final SSLEngineResult
unwrap(final ByteBuffer[]
The array of source buffers with data to unwrap.
srcs
,
final ByteBuffer[]
The array of destination buffers where the unwrapped data should be written.
dsts
)

Implements io.netty5.handler.ssl.VectoredUnwrap.unwrap.

Similar to javax.net.ssl.SSLEngine#unwrap(ByteBuffer, ByteBuffer[]), but takes an array of input buffers.
public final synchronized SSLEngineResult
unwrap(final ByteBuffer
a ByteBuffer containing inbound network data.
src
,
final ByteBuffer[]
an array of ByteBuffers to hold inbound application data.
dsts
,
final int
The offset within the buffer array of the first buffer from which bytes are to be transferred; it must be non-negative and no larger than dsts.length.
offset
,
final int
The maximum number of buffers to be accessed; it must be non-negative and no larger than dsts.length - offset.
length
)

Implements abstract javax.net.ssl.SSLEngine.unwrap.

Attempts to decode SSL/TLS/DTLS network data into a subsequence of plaintext application data buffers.
public final synchronized SSLEngineResult
unwrap(ByteBuffer
a ByteBuffer containing inbound network data.
src
,
ByteBuffer
a ByteBuffer to hold inbound application data.
dst
)

Overrides javax.net.ssl.SSLEngine.unwrap.

Attempts to decode SSL/TLS/DTLS network data into a plaintext application data buffer.
public final synchronized SSLEngineResult
unwrap(ByteBuffer
a ByteBuffer containing inbound network data.
src
,
ByteBuffer[]
an array of ByteBuffers to hold inbound application data.
dsts
)

Overrides javax.net.ssl.SSLEngine.unwrap.

Attempts to decode SSL/TLS/DTLS network data into a sequence of plaintext application data buffers.
public final SSLEngineResult
wrap(final ByteBuffer[]
an array of ByteBuffers containing the outbound application data
srcs
,
int
The offset within the buffer array of the first buffer from which bytes are to be retrieved; it must be non-negative and no larger than srcs.length
offset
,
final int
The maximum number of buffers to be accessed; it must be non-negative and no larger than srcs.length - offset
length
,
final ByteBuffer
a ByteBuffer to hold outbound network data
dst
)

Implements abstract javax.net.ssl.SSLEngine.wrap.

Attempts to encode plaintext bytes from a subsequence of data buffers into SSL/TLS/DTLS network data.
public final synchronized SSLEngineResult
wrap(ByteBuffer
a ByteBuffer containing outbound application data
src
,
ByteBuffer
a ByteBuffer to hold outbound network data
dst
)

Overrides javax.net.ssl.SSLEngine.wrap.

Attempts to encode a buffer of plaintext application data into SSL/TLS/DTLS network data.
private Buffer
writeEncryptedData(final ByteBuffer src, int len)

Write encrypted data to the OpenSSL network BIO.

private int
writePlaintextData(final ByteBuffer src, int len)

Write plaintext data to the OpenSSL internal BIO Calling this function with src.remaining == 0 is undefined.

Inherited from javax.net.ssl.SSLEngine:
getHandshakeApplicationProtocolSelectorgetPeerHostgetPeerPortsetHandshakeApplicationProtocolSelectorwrap