Class ReferenceCountedOpenSslContext
java.lang.Object
io.netty.handler.ssl.SslContext
io.netty.handler.ssl.ReferenceCountedOpenSslContext
- All Implemented Interfaces:
ReferenceCounted
- Direct Known Subclasses:
OpenSslContext, ReferenceCountedOpenSslClientContext, ReferenceCountedOpenSslServerContext
An implementation of
SslContext which works with libraries that support the
OpenSsl C library API.
Instances of this class must be released or else native memory will leak!
Instances of this class must not be released before any ReferenceCountedOpenSslEngine
which depends upon the instance of this class is released. Otherwise if any method of
ReferenceCountedOpenSslEngine is called which uses this class's JNI resources the JVM may crash.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classprivate static final classprivate static final classprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final OpenSslApplicationProtocolNegotiatorprivate int(package private) static final boolean(package private) static final boolean(package private) static final boolean(package private) final ClientAuth(package private) final java.util.List<OpenSslCredential> protected longThe OpenSSL SSL_CTX object.(package private) final java.util.concurrent.locks.ReadWriteLockprivate static final intprivate static final OpenSslCertificateCompressionConfigprivate static final booleanprivate static final java.lang.Integer(package private) final boolean(package private) final java.lang.String(package private) final OpenSslEngineMap(package private) final java.lang.String[](package private) final boolean(package private) final boolean(package private) final java.security.cert.Certificate[]private final ResourceLeakTracker<ReferenceCountedOpenSslContext> private static final ResourceLeakDetector<ReferenceCountedOpenSslContext> private static final InternalLoggerprivate static final intprivate final int(package private) static final OpenSslApplicationProtocolNegotiator(package private) final java.lang.String[]private final AbstractReferenceCounted(package private) static final boolean(package private) static final boolean(package private) static final boolean(package private) final java.util.List<javax.net.ssl.SNIServerName> (package private) final booleanprivate final java.util.List<java.lang.String> (package private) static final booleanprotected static final intFields inherited from class SslContext
ALIAS, defaultEndpointVerificationAlgorithm, resumptionController, X509_CERT_FACTORY -
Constructor Summary
ConstructorsConstructorDescriptionReferenceCountedOpenSslContext(java.lang.Iterable<java.lang.String> ciphers, CipherSuiteFilter cipherFilter, OpenSslApplicationProtocolNegotiator apn, int mode, java.security.cert.Certificate[] keyCertChain, ClientAuth clientAuth, java.lang.String[] protocols, boolean startTls, java.lang.String endpointIdentificationAlgorithm, boolean enableOcsp, boolean leakDetection, java.util.List<javax.net.ssl.SNIServerName> serverNames, ResumptionController resumptionController, java.util.Map.Entry<SslContextOption<?>, java.lang.Object>[] ctxOptions, java.util.List<OpenSslCredential> credentials) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddCredential(OpenSslCredential credential) Returns the object responsible for negotiating application layer protocols for the TLS NPN/ALPN extensions.(package private) static javax.net.ssl.KeyManagerFactorycertChainToKeyManagerFactory(java.security.cert.X509Certificate[] keyCertChain, java.security.PrivateKey key, java.lang.String keyPassword, java.lang.String keyStore) protected static java.security.cert.X509Certificate[]certificates(byte[][] chain) protected static javax.net.ssl.X509TrustManagerchooseTrustManager(javax.net.ssl.TrustManager[] managers) Deprecated.This method is kept for API backwards compatibility.(package private) static javax.net.ssl.X509TrustManagerchooseTrustManager(javax.net.ssl.TrustManager[] managers, ResumptionController resumptionController) protected static javax.net.ssl.X509KeyManagerchooseX509KeyManager(javax.net.ssl.KeyManager[] kms) final java.util.List<java.lang.String> Returns the list of enabled cipher suites, in the order of preference.final longcontext()Deprecated.this method is considered unsafe as the returned pointer may be released later.private voiddestroy()(package private) static voidfreeBio(long bio) intReturns the size of the buffer used by the BIO for non-application based writesbooleanDeprecated.private static booleanisCertificateCompressionDisabled(int mode) final booleanisClient()Returns thetrueif and only if this context is for client-side.(package private) static booleanisJdkSignatureFallbackEnabled(java.util.Map.Entry<SslContextOption<?>, java.lang.Object>... ctxOptions) Check if JDK signature fallback is enabled in the given context options.(package private) static intmaxCertificateListBytes(int maxCertificateListBytes) private static longfinal javax.net.ssl.SSLEnginenewEngine(ByteBufAllocator alloc) Returns a new server-sideSSLEnginewith the current configuration.final javax.net.ssl.SSLEnginenewEngine(ByteBufAllocator alloc, java.lang.String peerHost, int peerPort) Creates a newSSLEngineusing advisory peer information.(package private) javax.net.ssl.SSLEnginenewEngine0(ByteBufAllocator alloc, java.lang.String peerHost, int peerPort, boolean jdkCompatibilityMode) protected final SslHandlernewHandler(ByteBufAllocator alloc, boolean startTls) Create a new SslHandler.protected SslHandlernewHandler(ByteBufAllocator alloc, boolean startTls, java.util.concurrent.Executor executor) Create a new SslHandler.protected final SslHandlernewHandler(ByteBufAllocator alloc, java.lang.String peerHost, int peerPort, boolean startTls) Create a new SslHandler.protected SslHandlernewHandler(ByteBufAllocator alloc, java.lang.String peerHost, int peerPort, boolean startTls, java.util.concurrent.Executor executor) private static int(package private) static OpenSslKeyMaterialProviderproviderFor(javax.net.ssl.KeyManagerFactory factory, java.lang.String password) Returns theOpenSslKeyMaterialProviderthat should be used for OpenSSL.final intrefCnt()Returns the reference count of this object.final booleanrelease()Decreases the reference count by1and deallocates this object if the reference count reaches at0.final booleanrelease(int decrement) Decreases the reference count by the specifieddecrementand deallocates this object if the reference count reaches at0.final ReferenceCountedretain()Increases the reference count by1.final ReferenceCountedretain(int increment) Increases the reference count by the specifiedincrement.private static ReferenceCountedOpenSslEngineretrieveEngine(OpenSslEngineMap engines, long ssl) abstract OpenSslSessionContextReturns theSSLSessionContextobject held by this context.voidsetBioNonApplicationBufferSize(int bioNonApplicationBufferSize) Set the size of the buffer used by the BIO for non-application based writes (e.g.(package private) static voidsetKeyMaterial(long ctx, java.security.cert.X509Certificate[] keyCertChain, java.security.PrivateKey key, java.lang.String keyPassword) final voidDeprecated.voidsetRejectRemoteInitiatedRenegotiation(boolean rejectRemoteInitiatedRenegotiation) Deprecated.final voidsetTicketKeys(byte[] keys) Deprecated.(package private) static OpenSslKeyMaterialProvidersetupSecurityProviderSignatureSource(ReferenceCountedOpenSslContext thiz, long ctx, java.security.cert.X509Certificate[] keyCertChain, java.security.PrivateKey key, java.util.function.Function<OpenSslKeyMaterialManager, io.netty.internal.tcnative.CertificateCallback> toCallback) final voidsetUseTasks(boolean useTasks) Deprecated.final longDeprecated.this method is considered unsafe as the returned pointer may be released later.final OpenSslSessionStatsstats()Deprecated.use}invalid @link
{@link #sessionContext#stats()(package private) static longtoBIO(ByteBufAllocator allocator, PemEncoded pem) (package private) static longtoBIO(ByteBufAllocator allocator, java.security.cert.X509Certificate... certChain) (package private) static longtoBIO(ByteBufAllocator allocator, java.security.PrivateKey key) (package private) static OpenSslApplicationProtocolNegotiatorTranslate aApplicationProtocolConfigobject to aOpenSslApplicationProtocolNegotiatorobject.final ReferenceCountedtouch()Records the current access location of this object for debugging purposes.final ReferenceCountedtouch(java.lang.Object hint) Records the current access location of this object with an additional arbitrary information for debugging purposes.(package private) static booleanuseExtendedTrustManager(javax.net.ssl.X509TrustManager trustManager) private static byte[]verifyResult(byte[] result) Methods inherited from class SslContext
attributes, buildKeyManagerFactory, buildKeyManagerFactory, buildKeyStore, buildTrustManagerFactory, buildTrustManagerFactory, buildTrustManagerFactory, defaultClientProvider, defaultServerProvider, deriveSessionIdContext, generateKeySpec, isServer, keyStorePassword, newClientContext, newClientContext, newClientContext, newClientContext, newClientContext, newClientContext, newClientContext, newClientContext, newClientContext, newClientContext, newClientContext, newClientContext, newClientContext, newClientContextInternal, newClientContextInternal, newHandler, newHandler, newHandler, newHandler, newServerContext, newServerContext, newServerContext, newServerContext, newServerContext, newServerContext, newServerContext, newServerContext, newServerContext, newServerContext, newServerContext, newServerContextInternal, nextProtocols, sessionCacheSize, sessionTimeout, toApplicationProtocolConfig, toPrivateKey, toPrivateKey, toPrivateKey, toPrivateKeyInternal, toX509Certificates, toX509Certificates, toX509CertificatesInternalMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
DEFAULT_CERTIFICATE_COMPRESSION_CONFIG
-
logger
-
DEFAULT_USE_JDK_PROVIDERS
private static final boolean DEFAULT_USE_JDK_PROVIDERS -
DEFAULT_BIO_NON_APPLICATION_BUFFER_SIZE
private static final int DEFAULT_BIO_NON_APPLICATION_BUFFER_SIZE -
MIN_MAX_CERTIFICATE_LIST_BYTES
private static final int MIN_MAX_CERTIFICATE_LIST_BYTES- See Also:
-
USE_TASKS
static final boolean USE_TASKS -
DH_KEY_LENGTH
private static final java.lang.Integer DH_KEY_LENGTH -
leakDetector
-
VERIFY_DEPTH
protected static final int VERIFY_DEPTH- See Also:
-
CLIENT_ENABLE_SESSION_TICKET
static final boolean CLIENT_ENABLE_SESSION_TICKET -
CLIENT_ENABLE_SESSION_TICKET_TLSV13
static final boolean CLIENT_ENABLE_SESSION_TICKET_TLSV13 -
SERVER_ENABLE_SESSION_TICKET
static final boolean SERVER_ENABLE_SESSION_TICKET -
SERVER_ENABLE_SESSION_TICKET_TLSV13
static final boolean SERVER_ENABLE_SESSION_TICKET_TLSV13 -
SERVER_ENABLE_SESSION_CACHE
static final boolean SERVER_ENABLE_SESSION_CACHE -
CLIENT_ENABLE_SESSION_CACHE
static final boolean CLIENT_ENABLE_SESSION_CACHE -
ctx
protected long ctxThe OpenSSL SSL_CTX object.ctxLockmust be hold while using ctx! -
unmodifiableCiphers
private final java.util.List<java.lang.String> unmodifiableCiphers -
apn
-
mode
private final int mode -
leak
-
refCnt
-
keyCertChain
final java.security.cert.Certificate[] keyCertChain -
clientAuth
-
protocols
final java.lang.String[] protocols -
endpointIdentificationAlgorithm
final java.lang.String endpointIdentificationAlgorithm -
serverNames
final java.util.List<javax.net.ssl.SNIServerName> serverNames -
hasTLSv13Cipher
final boolean hasTLSv13Cipher -
hasTmpDhKeys
final boolean hasTmpDhKeys -
groups
final java.lang.String[] groups -
enableOcsp
final boolean enableOcsp -
engines
-
ctxLock
final java.util.concurrent.locks.ReadWriteLock ctxLock -
credentials
-
bioNonApplicationBufferSize
private volatile int bioNonApplicationBufferSize -
NONE_PROTOCOL_NEGOTIATOR
-
tlsFalseStart
final boolean tlsFalseStart
-
-
Constructor Details
-
ReferenceCountedOpenSslContext
ReferenceCountedOpenSslContext(java.lang.Iterable<java.lang.String> ciphers, CipherSuiteFilter cipherFilter, OpenSslApplicationProtocolNegotiator apn, int mode, java.security.cert.Certificate[] keyCertChain, ClientAuth clientAuth, java.lang.String[] protocols, boolean startTls, java.lang.String endpointIdentificationAlgorithm, boolean enableOcsp, boolean leakDetection, java.util.List<javax.net.ssl.SNIServerName> serverNames, ResumptionController resumptionController, java.util.Map.Entry<SslContextOption<?>, java.lang.Object>[] ctxOptions, java.util.List<OpenSslCredential> credentials) throws javax.net.ssl.SSLException - Throws:
javax.net.ssl.SSLException
-
-
Method Details
-
isCertificateCompressionDisabled
private static boolean isCertificateCompressionDisabled(int mode) -
opensslSelectorFailureBehavior
private static int opensslSelectorFailureBehavior(ApplicationProtocolConfig.SelectorFailureBehavior behavior) -
maxCertificateListBytes
static int maxCertificateListBytes(int maxCertificateListBytes) -
addCredential
- Throws:
javax.net.ssl.SSLException
-
cipherSuites
public final java.util.List<java.lang.String> cipherSuites()Description copied from class:SslContextReturns the list of enabled cipher suites, in the order of preference.- Specified by:
cipherSuitesin classSslContext
-
applicationProtocolNegotiator
Description copied from class:SslContextReturns the object responsible for negotiating application layer protocols for the TLS NPN/ALPN extensions.- Specified by:
applicationProtocolNegotiatorin classSslContext
-
isClient
public final boolean isClient()Description copied from class:SslContextReturns thetrueif and only if this context is for client-side.- Specified by:
isClientin classSslContext
-
newEngine
public final javax.net.ssl.SSLEngine newEngine(ByteBufAllocator alloc, java.lang.String peerHost, int peerPort) Description copied from class:SslContextCreates a newSSLEngineusing advisory peer information.If
SslProvider.OPENSSL_REFCNTis used then the object must be released. One way to do this is to wrap in aSslHandlerand insert it into a pipeline. SeeSslContext.newHandler(ByteBufAllocator, String, int).- Specified by:
newEnginein classSslContext- Parameters:
peerHost- the non-authoritative name of the hostpeerPort- the non-authoritative port- Returns:
- a new
SSLEngine
-
newHandler
Description copied from class:SslContextCreate a new SslHandler.- Overrides:
newHandlerin classSslContext- See Also:
-
newHandler
protected final SslHandler newHandler(ByteBufAllocator alloc, java.lang.String peerHost, int peerPort, boolean startTls) Description copied from class:SslContextCreate a new SslHandler.- Overrides:
newHandlerin classSslContext- See Also:
-
newHandler
protected SslHandler newHandler(ByteBufAllocator alloc, boolean startTls, java.util.concurrent.Executor executor) Description copied from class:SslContextCreate a new SslHandler.- Overrides:
newHandlerin classSslContext- See Also:
-
newHandler
protected SslHandler newHandler(ByteBufAllocator alloc, java.lang.String peerHost, int peerPort, boolean startTls, java.util.concurrent.Executor executor) - Overrides:
newHandlerin classSslContext
-
newEngine0
javax.net.ssl.SSLEngine newEngine0(ByteBufAllocator alloc, java.lang.String peerHost, int peerPort, boolean jdkCompatibilityMode) -
newEngine
Returns a new server-sideSSLEnginewith the current configuration.- Specified by:
newEnginein classSslContext- Returns:
- a new
SSLEngine
-
context
@Deprecated public final long context()Deprecated.this method is considered unsafe as the returned pointer may be released later. Dont use it!Returns the pointer to theSSL_CTXobject for thisReferenceCountedOpenSslContext. Be aware that it is freed as soon as theObject.finalize()method is called. At this point0will be returned. -
stats
Deprecated.use}invalid @link
{@link #sessionContext#stats()Returns the stats of this context. -
setRejectRemoteInitiatedRenegotiation
@Deprecated public void setRejectRemoteInitiatedRenegotiation(boolean rejectRemoteInitiatedRenegotiation) Deprecated.Specify if remote initiated renegotiation is supported or not. If not supported and the remote side tries to initiate a renegotiation aSSLHandshakeExceptionwill be thrown during decoding. -
getRejectRemoteInitiatedRenegotiation
@Deprecated public boolean getRejectRemoteInitiatedRenegotiation()Deprecated.- Returns:
truebecause renegotiation is not supported.
-
setBioNonApplicationBufferSize
public void setBioNonApplicationBufferSize(int bioNonApplicationBufferSize) Set the size of the buffer used by the BIO for non-application based writes (e.g. handshake, renegotiation, etc...). -
getBioNonApplicationBufferSize
public int getBioNonApplicationBufferSize()Returns the size of the buffer used by the BIO for non-application based writes -
setTicketKeys
@Deprecated public final void setTicketKeys(byte[] keys) Deprecated.Sets the SSL session ticket keys of this context. -
sessionContext
Description copied from class:SslContextReturns theSSLSessionContextobject held by this context.- Specified by:
sessionContextin classSslContext
-
sslCtxPointer
@Deprecated public final long sslCtxPointer()Deprecated.this method is considered unsafe as the returned pointer may be released later. Dont use it!Returns the pointer to theSSL_CTXobject for thisReferenceCountedOpenSslContext. Be aware that it is freed as soon as therelease()method is called. At this point0will be returned. -
setPrivateKeyMethod
Deprecated.Set theOpenSslPrivateKeyMethodto use. This allows to offload private-key operations if needed. This method is currently only supported whenBoringSSLis used.- Parameters:
method- method to use.
-
setUseTasks
@Deprecated public final void setUseTasks(boolean useTasks) Deprecated. -
destroy
private void destroy() -
certificates
protected static java.security.cert.X509Certificate[] certificates(byte[][] chain) -
chooseTrustManager
@Deprecated protected static javax.net.ssl.X509TrustManager chooseTrustManager(javax.net.ssl.TrustManager[] managers) Deprecated.This method is kept for API backwards compatibility. -
chooseTrustManager
static javax.net.ssl.X509TrustManager chooseTrustManager(javax.net.ssl.TrustManager[] managers, ResumptionController resumptionController) -
chooseX509KeyManager
protected static javax.net.ssl.X509KeyManager chooseX509KeyManager(javax.net.ssl.KeyManager[] kms) -
toNegotiator
Translate aApplicationProtocolConfigobject to aOpenSslApplicationProtocolNegotiatorobject.- Parameters:
config- The configuration which defines the translation- Returns:
- The results of the translation
-
useExtendedTrustManager
static boolean useExtendedTrustManager(javax.net.ssl.X509TrustManager trustManager) -
refCnt
public final int refCnt()Description copied from interface:ReferenceCountedReturns the reference count of this object. If0, it means this object has been deallocated.- Specified by:
refCntin interfaceReferenceCounted
-
retain
Description copied from interface:ReferenceCountedIncreases the reference count by1.- Specified by:
retainin interfaceReferenceCounted
-
retain
Description copied from interface:ReferenceCountedIncreases the reference count by the specifiedincrement.- Specified by:
retainin interfaceReferenceCounted
-
touch
Description copied from interface:ReferenceCountedRecords 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:
touchin interfaceReferenceCounted
-
touch
Description copied from interface:ReferenceCountedRecords 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:
touchin interfaceReferenceCounted
-
release
public final boolean release()Description copied from interface:ReferenceCountedDecreases the reference count by1and deallocates this object if the reference count reaches at0.- Specified by:
releasein interfaceReferenceCounted- Returns:
trueif and only if the reference count became0and this object has been deallocated
-
release
public final boolean release(int decrement) Description copied from interface:ReferenceCountedDecreases the reference count by the specifieddecrementand deallocates this object if the reference count reaches at0.- Specified by:
releasein interfaceReferenceCounted- Returns:
trueif and only if the reference count became0and this object has been deallocated
-
setKeyMaterial
static void setKeyMaterial(long ctx, java.security.cert.X509Certificate[] keyCertChain, java.security.PrivateKey key, java.lang.String keyPassword) throws javax.net.ssl.SSLException - Throws:
javax.net.ssl.SSLException
-
isJdkSignatureFallbackEnabled
@SafeVarargs static boolean isJdkSignatureFallbackEnabled(java.util.Map.Entry<SslContextOption<?>, java.lang.Object>... ctxOptions) Check if JDK signature fallback is enabled in the given context options. -
freeBio
static void freeBio(long bio) -
toBIO
static long toBIO(ByteBufAllocator allocator, java.security.PrivateKey key) throws java.lang.Exception Return the pointer to a in-memory BIO or0if thekeyisnull. The BIO contains the content of thekey.- Throws:
java.lang.Exception
-
toBIO
static long toBIO(ByteBufAllocator allocator, java.security.cert.X509Certificate... certChain) throws java.lang.Exception Return the pointer to a in-memory BIO or0if thecertChainisnull. The BIO contains the content of thecertChain.- Throws:
java.lang.Exception
-
toBIO
- Throws:
java.lang.Exception
-
newBIO
- Throws:
java.lang.Exception
-
providerFor
static OpenSslKeyMaterialProvider providerFor(javax.net.ssl.KeyManagerFactory factory, java.lang.String password) Returns theOpenSslKeyMaterialProviderthat should be used for OpenSSL. Depending on the givenKeyManagerFactorythis may cache theOpenSslKeyMaterialfor better performance if it can ensure that the same material is always returned for the same alias. -
certChainToKeyManagerFactory
static javax.net.ssl.KeyManagerFactory certChainToKeyManagerFactory(java.security.cert.X509Certificate[] keyCertChain, java.security.PrivateKey key, java.lang.String keyPassword, java.lang.String keyStore) throws java.lang.Exception - Throws:
java.lang.Exception
-
setupSecurityProviderSignatureSource
static OpenSslKeyMaterialProvider setupSecurityProviderSignatureSource(ReferenceCountedOpenSslContext thiz, long ctx, java.security.cert.X509Certificate[] keyCertChain, java.security.PrivateKey key, java.util.function.Function<OpenSslKeyMaterialManager, io.netty.internal.tcnative.CertificateCallback> toCallback) throws java.lang.Exception - Throws:
java.lang.Exception
-
retrieveEngine
private static ReferenceCountedOpenSslEngine retrieveEngine(OpenSslEngineMap engines, long ssl) throws javax.net.ssl.SSLException - Throws:
javax.net.ssl.SSLException
-
verifyResult
private static byte[] verifyResult(byte[] result) throws java.security.SignatureException - Throws:
java.security.SignatureException
-