only initialize trust managers if CA certificate is provided (#43)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b46b59e4a0
commit
dfb6d0a37c
@ -1,3 +1,8 @@
|
||||
## unreleased
|
||||
|
||||
### Fixes
|
||||
* Only initialize custom trust managers, if CA certificate is actually provided (#43)
|
||||
|
||||
## 0.9.1 (2021-01-03)
|
||||
|
||||
### Improvements
|
||||
|
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>de.stklcode.jvault</groupId>
|
||||
<artifactId>jvault-connector</artifactId>
|
||||
<version>0.9.1</version>
|
||||
<version>0.9.2-SNAPSHOT</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
@ -367,18 +367,22 @@ public final class RequestHelper implements Serializable {
|
||||
*/
|
||||
private SSLConnectionSocketFactory createSSLSocketFactory() throws TlsException {
|
||||
try {
|
||||
// Create Keystore with trusted certificate.
|
||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keyStore.load(null, null);
|
||||
keyStore.setCertificateEntry("trustedCert", trustedCaCert);
|
||||
|
||||
// Initialize TrustManager.
|
||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
tmf.init(keyStore);
|
||||
|
||||
// Create context using this TrustManager.
|
||||
// Create context..
|
||||
SSLContext context = SSLContext.getInstance(tlsVersion);
|
||||
context.init(null, tmf.getTrustManagers(), new SecureRandom());
|
||||
|
||||
if (trustedCaCert != null) {
|
||||
// Create Keystore with trusted certificate.
|
||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keyStore.load(null, null);
|
||||
keyStore.setCertificateEntry("trustedCert", trustedCaCert);
|
||||
|
||||
// Initialize TrustManager.
|
||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
tmf.init(keyStore);
|
||||
context.init(null, tmf.getTrustManagers(), null);
|
||||
} else {
|
||||
context.init(null, null, null);
|
||||
}
|
||||
|
||||
return new SSLConnectionSocketFactory(
|
||||
context,
|
||||
|
Loading…
x
Reference in New Issue
Block a user