- final String keystorePassword = properties.getProperty("key-store-password");
- SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(
- SSLContexts.custom()
- .loadKeyMaterial(ResourceUtils.getFile(properties.getProperty("key-store")),
- keystorePassword.toCharArray(), keystorePassword.toCharArray())
- .loadTrustMaterial(null, new TrustSelfSignedStrategy())
- .build(),
- NoopHostnameVerifier.INSTANCE);
+ final String keyPassword = properties.getProperty("key-password");
+ final String keystorePassword = properties.getProperty("keystore-password");
+ final String truststorePassword = properties.getProperty("truststore-password");
+ final boolean isTrustStoreUsed = Boolean.parseBoolean(properties.getProperty("isTrustStoreUsed"));
+ SSLContextBuilder builder = SSLContexts.custom()
+ .loadKeyMaterial(ResourceUtils.getFile(properties.getProperty("key-store")),
+ keystorePassword.toCharArray(), keyPassword.toCharArray());
+ if (isTrustStoreUsed) {
+ builder.loadTrustMaterial(ResourceUtils.getFile(properties.getProperty("trust-store")),
+ truststorePassword.toCharArray());
+ } else {
+ builder.loadTrustMaterial(null, new TrustAllStrategy());
+ }
+ SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);