use of com.netflix.spinnaker.kork.exceptions.SystemException in project kork by spinnaker.
the class InsecureOkHttpClientBuilderProvider method setSSLSocketFactory.
private OkHttpClient.Builder setSSLSocketFactory(OkHttpClient.Builder builder, ServiceEndpoint service) {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustManagers = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
} };
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustManagers, null);
builder.sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustManagers[0]);
builder.hostnameVerifier((hostname, session) -> true);
} catch (Exception e) {
log.error("Unable to set ssl socket factory for {}", service.getBaseUrl(), e);
throw new SystemException(format("Unable to set ssl socket factory for (%s)", service.getBaseUrl()), e);
}
return builder;
}
use of com.netflix.spinnaker.kork.exceptions.SystemException in project kork by spinnaker.
the class DefaultOkHttpClientBuilderProvider method setSSLSocketFactory.
protected OkHttpClient.Builder setSSLSocketFactory(OkHttpClient.Builder builder, ServiceEndpoint serviceEndpoint) {
if ((okHttpClientConfigurationProperties.getKeyStore() == null && okHttpClientConfigurationProperties.getTrustStore() == null) || serviceEndpoint.isUseDefaultSslSocketFactory()) {
return builder;
}
try {
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore ks = KeyStore.getInstance(okHttpClientConfigurationProperties.getKeyStoreType());
ks.load(new FileInputStream(okHttpClientConfigurationProperties.getKeyStore()), okHttpClientConfigurationProperties.getKeyStorePassword().toCharArray());
keyManagerFactory.init(ks, okHttpClientConfigurationProperties.getKeyStorePassword().toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore ts = KeyStore.getInstance(okHttpClientConfigurationProperties.getTrustStoreType());
ts.load(new FileInputStream(okHttpClientConfigurationProperties.getTrustStore()), okHttpClientConfigurationProperties.getTrustStorePassword().toCharArray());
trustManagerFactory.init(ts);
SecureRandom secureRandom = SecureRandom.getInstance(okHttpClientConfigurationProperties.getSecureRandomInstanceType());
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), secureRandom);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
checkState(trustManagers.length == 1, "Found multiple trust managers; don't know which one to use");
checkState(trustManagers[0] instanceof X509TrustManager, "Configured TrustManager is a %s, not an X509TrustManager; don't know how to configure it", trustManagers[0].getClass().getSimpleName());
builder.sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustManagers[0]);
} catch (Exception e) {
log.error("Unable to set ssl socket factory for {}", serviceEndpoint.getBaseUrl(), e);
throw new SystemException(format("Unable to set ssl socket factory for (%s)", serviceEndpoint.getBaseUrl()), e);
}
return builder;
}
Aggregations