public class SslContextBuilder extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
TLS_VERSION_1_2
TLS version 1.2.
|
static String |
TLS_VERSION_1_3
TLS version 1.3.
|
| Constructor and Description |
|---|
SslContextBuilder()
Creates an SSL context builder.
|
SslContextBuilder(String protocol)
Creates an SSL context builder for the given TLS protocol version.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addClientKey(byte[] privateKey,
InputStream certificate)
Adds the given client key and the associated self-signed certificate.
|
void |
addClientKey(byte[] privateKey,
InputStream certificate,
InputStream... certificationChain)
Adds the given client key and the associated certificate and certification chain to the key store.
|
void |
addClientKey(InputStream privateKey,
InputStream certificate)
Adds the given client key and the associated self-signed certificate.
|
void |
addClientKey(InputStream privateKey,
InputStream certificate,
InputStream... certificationChain)
Adds the given client key and the associated certificate and certification chain to the key store.
|
void |
addClientKey(String privateKeyPath,
String certificatePath,
String... certificationChainPaths)
Adds the given client key and the associated certificate and certification chain to the key store.
|
void |
addServerCertificate(InputStream certificate)
Adds the given server certificate to the trust store.
|
void |
addServerCertificate(String certificatePath)
Adds the given server certificate to the trust store.
|
SSLContext |
build()
Creates an SSL context using the populated trust store and an empty key store.
|
SSLContext |
build(String keyStorePassword)
Creates an SSL context using the populated trust store and an the populated key store, using the given key store
password.
|
public static final String TLS_VERSION_1_2
public static final String TLS_VERSION_1_3
public SslContextBuilder()
throws GeneralSecurityException
GeneralSecurityException - if an exception occurs while initializing the trust store or the key store.public SslContextBuilder(String protocol) throws GeneralSecurityException
protocol - the TLS protocol version string.GeneralSecurityException - if an exception occurs while initializing the trust store or the key store.SSLContext.getInstance(String)public void addClientKey(byte[] privateKey,
InputStream certificate)
throws GeneralSecurityException
privateKey - the private key to add.certificate - the associated certificate.GeneralSecurityException - if the certificates could not be loaded or the private key could not be added.public void addClientKey(byte[] privateKey,
InputStream certificate,
InputStream... certificationChain)
throws GeneralSecurityException
privateKey - the private key to add.certificate - the associated certificate.certificationChain - the certification chain, ordered, the root certificate at the end.GeneralSecurityException - if the certificates could not be loaded or the private key could not be added.public void addClientKey(InputStream privateKey, InputStream certificate) throws IOException, GeneralSecurityException
privateKey - the private key to add.certificate - the associated certificate.GeneralSecurityException - if the certificate could not be loaded or the private key could not be added.IOException - if the given privateKey could not be read.public void addClientKey(InputStream privateKey, InputStream certificate, InputStream... certificationChain) throws IOException, GeneralSecurityException
privateKey - the private key to add.certificate - the associated certificate.certificationChain - the certification chain, ordered, the root certificate at the end.GeneralSecurityException - if the certificate could not be loaded or the private key could not be added.IOException - if the given privateKey could not be read.public void addClientKey(String privateKeyPath, String certificatePath, String... certificationChainPaths) throws IOException, GeneralSecurityException
Class.getResourceAsStream(String)).privateKeyPath - the path to the private key to add.certificatePath - the path to the associated certificate.certificationChainPaths - the paths to the certification chain, ordered, the root certificate at the end.GeneralSecurityException - if the certificate could not be loaded or the private key could not be added.IOException - if the given privateKey could not be read.public void addServerCertificate(InputStream certificate) throws GeneralSecurityException
certificate - the certificate to add.GeneralSecurityException - if the certificate could not be loaded or added.public void addServerCertificate(String certificatePath) throws GeneralSecurityException, IOException
Class.getResourceAsStream(String)).certificatePath - the path to the certificate to add.GeneralSecurityException - if the certificate could not be loaded or added.IOException - if an I/O occurs when loading the resource.public SSLContext build() throws GeneralSecurityException
GeneralSecurityException - if an exception occurred while creating the SSL context.public SSLContext build(String keyStorePassword) throws GeneralSecurityException
keyStorePassword - the password of the key store.GeneralSecurityException - if an exception occurred while creating the SSL context.