public final class TlsContextOptions extends CrtResource
Modifier and Type | Class and Description |
---|---|
static class |
TlsContextOptions.TlsVersions |
Constructor and Description |
---|
TlsContextOptions()
Creates a new set of options that can be used to create a
TlsContext |
Modifier and Type | Method and Description |
---|---|
void |
close()
Frees the native resources associated with this instance
|
static TlsContextOptions |
createDefaultClient()
Helper which creates a default set of TLS options for the current platform
|
static TlsContextOptions |
createWithMTLS(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
|
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
|
void |
overrideDefaultTrustStore(String caPath,
String caFile)
Helper function to provide a TlsContext-local trust store
|
void |
setAlpnList(String alpn)
Sets the ALPN protocol list that will be provided when a TLS connection
starts
|
void |
setMinimumTlsVersion(TlsContextOptions.TlsVersions version)
Sets the minimum acceptable TLS version that the
TlsContext will allow |
void |
setVerifyPeer(boolean verify)
Set whether or not the peer should be verified.
|
acquire, getAllocatedNativeResourceCount, getAllocatedNativeResources, isNull, native_ptr, own, release
public TlsContextOptions() throws CrtRuntimeException
TlsContext
CrtRuntimeException
- If the system is not able to allocate space for a native tls context options structurepublic void close()
close
in interface AutoCloseable
close
in class CrtResource
public void setMinimumTlsVersion(TlsContextOptions.TlsVersions version)
TlsContext
will allowversion
- Select from TlsVersions, a good default is TlsVersions.TLS_VER_SYS_DEFAULTS
as this will update if the OS TLS is updatedpublic void setAlpnList(String alpn)
alpn
- The ALPN protocol to use, e.g. "x-amzn-mqtt-ca"public void initMTLSFromPath(String certificatePath, String privateKeyPath)
certificatePath
- Path to PEM format certificateprivateKeyPath
- Path to PEM format private keypublic void initMTLSPkcs12(String pkcs12Path, String pkcs12Password)
pkcs12Path
- Path to PKCS12 filepkcs12Password
- PKCS12 passwordpublic void setVerifyPeer(boolean verify)
verify
- true to verify peers, false to skip verificationpublic static boolean isAlpnSupported()
public void overrideDefaultTrustStore(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 static TlsContextOptions createDefaultClient() throws CrtRuntimeException
CrtRuntimeException
- @see TlsContextOptions.TlsContextOptions()public static TlsContextOptions createWithMTLS(String certificatePath, String privateKeyPath) throws CrtRuntimeException
certificatePath
- Path to a PEM format certificateprivateKeyPath
- Path to a PEM format private keyCrtRuntimeException
- @see #constructor()public static TlsContextOptions createWithMTLSPkcs12(String pkcs12Path, String pkcs12Password) throws CrtRuntimeException
pkcs12Path
- The path to a PKCS12 file @see #setPkcs12Path(String)pkcs12Password
- The PKCS12 password @see #setPkcs12Password(String)CrtRuntimeException
- @see #constructor()Copyright © 2019. All rights reserved.