- java.lang.Object
-
- javax.net.ssl.SSLEngine
-
- io.netty5.handler.ssl.ReferenceCountedOpenSslEngine
-
- All Implemented Interfaces:
ReferenceCounted
- Direct Known Subclasses:
OpenSslEngine
public class ReferenceCountedOpenSslEngine extends SSLEngine implements ReferenceCounted
Implements aSSLEngine
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 theReferenceCountedOpenSslContext
JNI resources the JVM may crash.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beginHandshake()
void
closeInbound()
void
closeOutbound()
String
getApplicationProtocol()
Runnable
getDelegatedTask()
String[]
getEnabledCipherSuites()
String[]
getEnabledProtocols()
boolean
getEnableSessionCreation()
String
getHandshakeApplicationProtocol()
SSLSession
getHandshakeSession()
SSLEngineResult.HandshakeStatus
getHandshakeStatus()
boolean
getNeedClientAuth()
String
getNegotiatedApplicationProtocol()
byte[]
getOcspResponse()
Returns the OCSP response ornull
if the server didn't provide a stapled OCSP response.SSLSession
getSession()
SSLParameters
getSSLParameters()
String[]
getSupportedCipherSuites()
String[]
getSupportedProtocols()
boolean
getUseClientMode()
boolean
getWantClientAuth()
boolean
isInboundDone()
boolean
isOutboundDone()
int
refCnt()
Returns the reference count of this object.boolean
release()
Decreases the reference count by1
and deallocates this object if the reference count reaches at0
.boolean
release(int decrement)
Decreases the reference count by the specifieddecrement
and deallocates this object if the reference count reaches at0
.ReferenceCounted
retain()
Increases the reference count by1
.ReferenceCounted
retain(int increment)
Increases the reference count by the specifiedincrement
.void
setEnabledCipherSuites(String[] cipherSuites)
void
setEnabledProtocols(String[] protocols)
TLS doesn't support a way to advertise non-contiguous versions from the client's perspective, and the client just advertises the max supported version.void
setEnableSessionCreation(boolean b)
void
setNeedClientAuth(boolean b)
void
setOcspResponse(byte[] response)
Sets the OCSP response.void
setSSLParameters(SSLParameters sslParameters)
void
setUseClientMode(boolean clientMode)
void
setVerify(int verifyMode, int depth)
See SSL_set_verify andSSL.setVerify(long, int, int)
.void
setWantClientAuth(boolean b)
void
shutdown()
Destroys this engine.long
sslPointer()
Returns the pointer to theSSL
object for thisReferenceCountedOpenSslEngine
.ReferenceCounted
touch()
Records the current access location of this object for debugging purposes.ReferenceCounted
touch(Object hint)
Records the current access location of this object with an additional arbitrary information for debugging purposes.SSLEngineResult
unwrap(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength)
SSLEngineResult
unwrap(ByteBuffer[] srcs, ByteBuffer[] dsts)
SSLEngineResult
unwrap(ByteBuffer src, ByteBuffer dst)
SSLEngineResult
unwrap(ByteBuffer src, ByteBuffer[] dsts)
SSLEngineResult
unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int length)
SSLEngineResult
wrap(ByteBuffer[] srcs, int offset, int length, ByteBuffer dst)
SSLEngineResult
wrap(ByteBuffer src, ByteBuffer dst)
-
Methods inherited from class javax.net.ssl.SSLEngine
getHandshakeApplicationProtocolSelector, getPeerHost, getPeerPort, setHandshakeApplicationProtocolSelector, wrap
-
-
-
-
Method Detail
-
setOcspResponse
@UnstableApi public void setOcspResponse(byte[] response)
Sets the OCSP response.
-
getOcspResponse
@UnstableApi public byte[] getOcspResponse()
Returns the OCSP response ornull
if the server didn't provide a stapled OCSP response.
-
refCnt
public final int refCnt()
Description copied from interface:ReferenceCounted
Returns the reference count of this object. If0
, it means this object has been deallocated.- Specified by:
refCnt
in interfaceReferenceCounted
-
retain
public final ReferenceCounted retain()
Description copied from interface:ReferenceCounted
Increases the reference count by1
.- Specified by:
retain
in interfaceReferenceCounted
-
retain
public final ReferenceCounted retain(int increment)
Description copied from interface:ReferenceCounted
Increases the reference count by the specifiedincrement
.- Specified by:
retain
in interfaceReferenceCounted
-
touch
public final ReferenceCounted touch()
Description copied from interface:ReferenceCounted
Records the current access location of this object for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you viaResourceLeakDetector
. This method is a shortcut totouch(null)
.- Specified by:
touch
in interfaceReferenceCounted
-
touch
public final ReferenceCounted touch(Object hint)
Description copied from interface:ReferenceCounted
Records the current access location of this object with an additional arbitrary information for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you viaResourceLeakDetector
.- Specified by:
touch
in interfaceReferenceCounted
-
release
public final boolean release()
Description copied from interface:ReferenceCounted
Decreases the reference count by1
and deallocates this object if the reference count reaches at0
.- Specified by:
release
in interfaceReferenceCounted
- Returns:
true
if and only if the reference count became0
and this object has been deallocated
-
release
public final boolean release(int decrement)
Description copied from interface:ReferenceCounted
Decreases the reference count by the specifieddecrement
and deallocates this object if the reference count reaches at0
.- Specified by:
release
in interfaceReferenceCounted
- Returns:
true
if and only if the reference count became0
and this object has been deallocated
-
getApplicationProtocol
public String getApplicationProtocol()
- Overrides:
getApplicationProtocol
in classSSLEngine
-
getHandshakeApplicationProtocol
public String getHandshakeApplicationProtocol()
- Overrides:
getHandshakeApplicationProtocol
in classSSLEngine
-
getHandshakeSession
public final SSLSession getHandshakeSession()
- Overrides:
getHandshakeSession
in classSSLEngine
-
sslPointer
public final long sslPointer()
Returns the pointer to theSSL
object for thisReferenceCountedOpenSslEngine
. Be aware that it is freed as soon as therelease()
orshutdown()
methods are called. At this point0
will be returned.
-
shutdown
public final void shutdown()
Destroys this engine.
-
wrap
public final SSLEngineResult wrap(ByteBuffer[] srcs, int offset, int length, ByteBuffer dst) throws SSLException
- Specified by:
wrap
in classSSLEngine
- Throws:
SSLException
-
unwrap
public final SSLEngineResult unwrap(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength) throws SSLException
- Throws:
SSLException
-
unwrap
public final SSLEngineResult unwrap(ByteBuffer[] srcs, ByteBuffer[] dsts) throws SSLException
- Throws:
SSLException
-
unwrap
public final SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int length) throws SSLException
- Specified by:
unwrap
in classSSLEngine
- Throws:
SSLException
-
wrap
public final SSLEngineResult wrap(ByteBuffer src, ByteBuffer dst) throws SSLException
- Overrides:
wrap
in classSSLEngine
- Throws:
SSLException
-
unwrap
public final SSLEngineResult unwrap(ByteBuffer src, ByteBuffer dst) throws SSLException
- Overrides:
unwrap
in classSSLEngine
- Throws:
SSLException
-
unwrap
public final SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts) throws SSLException
- Overrides:
unwrap
in classSSLEngine
- Throws:
SSLException
-
getDelegatedTask
public final Runnable getDelegatedTask()
- Specified by:
getDelegatedTask
in classSSLEngine
-
closeInbound
public final void closeInbound() throws SSLException
- Specified by:
closeInbound
in classSSLEngine
- Throws:
SSLException
-
isInboundDone
public final boolean isInboundDone()
- Specified by:
isInboundDone
in classSSLEngine
-
closeOutbound
public final void closeOutbound()
- Specified by:
closeOutbound
in classSSLEngine
-
isOutboundDone
public final boolean isOutboundDone()
- Specified by:
isOutboundDone
in classSSLEngine
-
getSupportedCipherSuites
public final String[] getSupportedCipherSuites()
- Specified by:
getSupportedCipherSuites
in classSSLEngine
-
getEnabledCipherSuites
public final String[] getEnabledCipherSuites()
- Specified by:
getEnabledCipherSuites
in classSSLEngine
-
setEnabledCipherSuites
public final void setEnabledCipherSuites(String[] cipherSuites)
- Specified by:
setEnabledCipherSuites
in classSSLEngine
-
getSupportedProtocols
public final String[] getSupportedProtocols()
- Specified by:
getSupportedProtocols
in classSSLEngine
-
getEnabledProtocols
public final String[] getEnabledProtocols()
- Specified by:
getEnabledProtocols
in classSSLEngine
-
setEnabledProtocols
public final void setEnabledProtocols(String[] protocols)
TLS doesn't support a way to advertise non-contiguous versions from the client's perspective, and the client just advertises the max supported version. The TLS protocol also doesn't support all different combinations of discrete protocols, and instead assumes contiguous ranges. OpenSSL has some unexpected behavior (e.g. handshake failures) if non-contiguous protocols are used even where there is a compatible set of protocols and ciphers. For these reasons this method will determine the minimum protocol and the maximum protocol and enabled a contiguous range from [min protocol, max protocol] in OpenSSL.- Specified by:
setEnabledProtocols
in classSSLEngine
-
getSession
public final SSLSession getSession()
- Specified by:
getSession
in classSSLEngine
-
beginHandshake
public final void beginHandshake() throws SSLException
- Specified by:
beginHandshake
in classSSLEngine
- Throws:
SSLException
-
getHandshakeStatus
public final SSLEngineResult.HandshakeStatus getHandshakeStatus()
- Specified by:
getHandshakeStatus
in classSSLEngine
-
setUseClientMode
public final void setUseClientMode(boolean clientMode)
- Specified by:
setUseClientMode
in classSSLEngine
-
getUseClientMode
public final boolean getUseClientMode()
- Specified by:
getUseClientMode
in classSSLEngine
-
setNeedClientAuth
public final void setNeedClientAuth(boolean b)
- Specified by:
setNeedClientAuth
in classSSLEngine
-
getNeedClientAuth
public final boolean getNeedClientAuth()
- Specified by:
getNeedClientAuth
in classSSLEngine
-
setWantClientAuth
public final void setWantClientAuth(boolean b)
- Specified by:
setWantClientAuth
in classSSLEngine
-
getWantClientAuth
public final boolean getWantClientAuth()
- Specified by:
getWantClientAuth
in classSSLEngine
-
setVerify
@UnstableApi public final void setVerify(int verifyMode, int depth)
See SSL_set_verify andSSL.setVerify(long, int, int)
.
-
setEnableSessionCreation
public final void setEnableSessionCreation(boolean b)
- Specified by:
setEnableSessionCreation
in classSSLEngine
-
getEnableSessionCreation
public final boolean getEnableSessionCreation()
- Specified by:
getEnableSessionCreation
in classSSLEngine
-
getSSLParameters
public final SSLParameters getSSLParameters()
- Overrides:
getSSLParameters
in classSSLEngine
-
setSSLParameters
public final void setSSLParameters(SSLParameters sslParameters)
- Overrides:
setSSLParameters
in classSSLEngine
-
getNegotiatedApplicationProtocol
public String getNegotiatedApplicationProtocol()
-
-