public final class TlsContextOptions extends CrtResource
| Modifier and Type | Class and Description |
|---|---|
static class |
TlsContextOptions.TlsVersions |
CrtResource.ResourceInstance| Modifier and Type | Field and Description |
|---|---|
List<String> |
alpnList
Sets the ALPN protocol list that will be provided when a TLS connection
starts e.g.
|
TlsContextOptions.TlsVersions |
minTlsVersion
Sets the minimum acceptable TLS version that the
TlsContext will
allow. |
TlsCipherPreference |
tlsCipherPreference
Sets the TLS Cipher Preferences that can be negotiated and used during the
TLS Connection.
|
boolean |
verifyPeer
Set whether or not the peer should be verified.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
canReleaseReferencesImmediately()
Determines whether a resource releases its dependencies at the same time the native handle is released or if it waits.
|
static TlsContextOptions |
createDefaultClient()
Helper which creates a default set of TLS options for the current platform
|
static TlsContextOptions |
createDefaultServer()
Helper which creates a default set of TLS options for the current platform
|
static TlsContextOptions |
createWithMtls(String certificate,
String privateKey)
Helper which creates TLS options using a certificate and private key
|
static TlsContextOptions |
createWithMtlsFromPath(String certificatePath,
String privateKeyPath)
Helper which creates TLS options using a certificate and private key
|
static TlsContextOptions |
createWithMtlsPkcs12(String pkcs12Path,
String pkcs12Password)
OSX only - Helper which creates TLS options using PKCS12
|
long |
getNativeHandle()
returns the native handle associated with this CRTResource.
|
void |
initMtls(String certificate,
String privateKey)
Sets the certificate/key pair that identifies this TLS host.
|
void |
initMtlsFromPath(String certificatePath,
String privateKeyPath)
Sets the path to the certificate that identifies this TLS host.
|
void |
initMtlsPkcs12(String pkcs12Path,
String pkcs12Password)
OSX only - Initializes MTLS with PKCS12 file and password
|
static boolean |
isAlpnSupported()
Returns whether or not ALPN is supported on the current platform
|
static boolean |
isCipherPreferenceSupported(TlsCipherPreference cipherPref)
Returns whether or not the current platform can be configured to a specific TlsCipherPreference.
|
void |
overrideDefaultTrustStore(String caRoot)
Helper function to provide a TlsContext-local trust store
|
void |
overrideDefaultTrustStoreFromPath(String caPath,
String caFile)
Helper function to provide a TlsContext-local trust store
|
protected void |
releaseNativeHandle()
Frees the native resources associated with this instance
|
void |
setCipherPreference(TlsCipherPreference cipherPref) |
TlsContextOptions |
withAlpnList(String alpnList)
Sets the ALPN protocols list for any connections using this TlsContext
|
TlsContextOptions |
withCertificateAuthority(String caRoot)
Specifies the certificate authority to use.
|
TlsContextOptions |
withCertificateAuthorityFromPath(String caDirPath,
String caFilePath)
Specifies the certificate authority to use.
|
TlsContextOptions |
withCipherPreference(TlsCipherPreference cipherPref)
Sets the ciphers that the TlsContext will be able to use
|
TlsContextOptions |
withMinimumTlsVersion(TlsContextOptions.TlsVersions version)
Sets the minimum TLS version that the TlsContext will allow.
|
TlsContextOptions |
withMtls(String certificate,
String privateKey)
Enables mutual TLS (mTLS) on this TlsContext
|
TlsContextOptions |
withMtlsFromPath(String certificatePath,
String privateKeyPath)
Enables mutual TLS (mTLS) on this TlsContext
|
TlsContextOptions |
withMtlsPkcs12(String pkcs12Path,
String pkcs12Password)
Apple platforms only, specifies mTLS using PKCS#12
|
TlsContextOptions |
withVerifyPeer()
Enables TLS peer verification of certificates
|
TlsContextOptions |
withVerifyPeer(boolean verify)
Sets whether or not TLS will validate the certificate from the peer.
|
acquireNativeHandle, addRef, addReferenceTo, close, collectNativeResource, collectNativeResources, decRef, getResourceLogDescription, isNull, logNativeResources, releaseReferences, removeReferenceTo, setDescription, swapReferenceTo, waitForNoResourcespublic TlsContextOptions.TlsVersions minTlsVersion
TlsContext will
allow. Not compatible with setCipherPreference() API.
Select from TlsVersions, a good default is TlsVersions.TLS_VER_SYS_DEFAULTS
as this will update if the OS TLS is updatedpublic TlsCipherPreference tlsCipherPreference
public List<String> alpnList
public boolean verifyPeer
public long getNativeHandle()
CrtResourcegetNativeHandle in class CrtResourceprotected boolean canReleaseReferencesImmediately()
canReleaseReferencesImmediately in class CrtResourceprotected void releaseNativeHandle()
releaseNativeHandle in class CrtResourcepublic void setCipherPreference(TlsCipherPreference cipherPref)
public void initMtlsFromPath(String certificatePath, String privateKeyPath)
certificatePath - Path to PEM format certificateprivateKeyPath - Path to PEM format private keypublic void initMtls(String certificate, String privateKey) throws IllegalArgumentException
certificate - PEM armored certificateprivateKey - PEM armored private keyIllegalArgumentException - If the certificate or privateKey are not in PEM format or if they contain chainspublic void initMtlsPkcs12(String pkcs12Path, String pkcs12Password)
pkcs12Path - Path to PKCS12 filepkcs12Password - PKCS12 passwordpublic static boolean isAlpnSupported()
public static boolean isCipherPreferenceSupported(TlsCipherPreference cipherPref)
cipherPref - The TlsCipherPreference to checkpublic void overrideDefaultTrustStoreFromPath(String caPath, String caFile)
caPath - Path to the local trust store. Can be null.caFile - Path to the root certificate. Must be in PEM format.public void overrideDefaultTrustStore(String caRoot) throws IllegalArgumentException
caRoot - Buffer containing the root certificate chain. Must be in PEM format.IllegalArgumentException - if the CA Root PEM file is malformedpublic static TlsContextOptions createDefaultClient()
public static TlsContextOptions createDefaultServer()
public static TlsContextOptions createWithMtlsFromPath(String certificatePath, String privateKeyPath)
certificatePath - Path to a PEM format certificateprivateKeyPath - Path to a PEM format private keypublic static TlsContextOptions createWithMtls(String certificate, String privateKey) throws IllegalArgumentException
certificate - String containing a PEM format certificateprivateKey - String containing a PEM format private keyIllegalArgumentException - If either PEM fails to parsepublic static TlsContextOptions createWithMtlsPkcs12(String pkcs12Path, String pkcs12Password)
pkcs12Path - The path to a PKCS12 file @see #setPkcs12Path(String)pkcs12Password - The PKCS12 password @see #setPkcs12Password(String)public TlsContextOptions withCipherPreference(TlsCipherPreference cipherPref)
cipherPref - The preference set of ciphers to usepublic TlsContextOptions withMinimumTlsVersion(TlsContextOptions.TlsVersions version)
version - Minimum acceptable TLS versionpublic TlsContextOptions withAlpnList(String alpnList)
alpnList - Semi-colon delimited list of supported ALPN protocolspublic TlsContextOptions withMtls(String certificate, String privateKey)
certificate - mTLS certificate, in PEM formatprivateKey - mTLS private key, in PEM formatpublic TlsContextOptions withMtlsFromPath(String certificatePath, String privateKeyPath)
certificatePath - path to mTLS certificate, in PEM formatprivateKeyPath - path to mTLS private key, in PEM formatpublic TlsContextOptions withCertificateAuthority(String caRoot)
caRoot - Certificate Authority, in PEM formatpublic TlsContextOptions withCertificateAuthorityFromPath(String caDirPath, String caFilePath)
caDirPath - Path to certificate directory, e.g. /etc/ssl/certscaFilePath - Path to ceritificate authority, in PEM formatpublic TlsContextOptions withMtlsPkcs12(String pkcs12Path, String pkcs12Password)
pkcs12Path - Path to PKCS#12 certificate, in PEM formatpkcs12Password - PKCS#12 passwordpublic TlsContextOptions withVerifyPeer(boolean verify)
verify - true to verify peers, false to ignore certspublic TlsContextOptions withVerifyPeer()
withVerifyPeer(boolean)Copyright © 2021. All rights reserved.