use of java.security.KeyManagementException in project ddf by codice.
the class CometDClient method doTrustAllCertificates.
private void doTrustAllCertificates() throws NoSuchAlgorithmException, KeyManagementException {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
HostnameVerifier hostnameVerifier = (s, sslSession) -> s.equalsIgnoreCase(sslSession.getPeerHost());
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
}
use of java.security.KeyManagementException in project ddf by codice.
the class SolrHttpWrapper method getSslContext.
private SSLContext getSslContext() {
String keystorePath = System.getProperty(SecurityConstants.KEYSTORE_PATH);
String keystorePassword = System.getProperty(SecurityConstants.KEYSTORE_PASSWORD);
String truststorePath = System.getProperty(SecurityConstants.TRUSTSTORE_PATH);
String truststorePassword = System.getProperty(SecurityConstants.TRUSTSTORE_PASSWORD);
if (keystorePath == null || keystorePassword == null || truststorePath == null || truststorePassword == null) {
throw new IllegalArgumentException("KeyStore and TrustStore system properties must be set.");
}
KeyStore trustStore = getKeyStore(truststorePath, truststorePassword);
KeyStore keyStore = getKeyStore(keystorePath, keystorePassword);
SSLContext sslContext;
try {
sslContext = SSLContexts.custom().loadKeyMaterial(keyStore, keystorePassword.toCharArray()).loadTrustMaterial(trustStore).useTLS().build();
} catch (UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
LOGGER.error("Unable to create secure HttpClient for Solr. The server should not be used in this state.", e);
return null;
}
sslContext.getDefaultSSLParameters().setNeedClientAuth(true);
sslContext.getDefaultSSLParameters().setWantClientAuth(true);
return sslContext;
}
use of java.security.KeyManagementException in project pact-jvm by DiUS.
the class InsecureHttpsRequest method setupInsecureSSL.
private void setupInsecureSSL() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
HttpClientBuilder b = HttpClientBuilder.create();
// setup a Trust Strategy that allows all certificates.
//
TrustStrategy trustStrategy = (chain, authType) -> true;
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
b.setSSLContext(sslContext);
// don't check Hostnames, either.
// -- use SSLConnectionSocketFactory.getDefaultHostnameVerifier(), if you don't want to weaken
HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
// here's the special part:
// -- need to create an SSL Socket Factory, to use our weakened "trust strategy";
// -- and create a Registry, to register it.
//
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
// now, we create connection-manager using our Registry.
// -- allows multi-threaded use
PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
b.setConnectionManager(connMgr);
// finally, build the HttpClient;
// -- done!
this.httpclient = b.build();
}
use of java.security.KeyManagementException in project ddf by codice.
the class HttpSolrClientFactory method getSslContext.
private static SSLContext getSslContext() {
if (//
System.getProperty("javax.net.ssl.keyStore") == null || //
System.getProperty("javax.net.ssl.keyStorePassword") == null || //
System.getProperty("javax.net.ssl.trustStore") == null || System.getProperty("javax.net.ssl.trustStorePassword") == null) {
throw new IllegalArgumentException("KeyStore and TrustStore system properties must be set.");
}
KeyStore trustStore = getKeyStore(System.getProperty("javax.net.ssl.trustStore"), System.getProperty("javax.net.ssl.trustStorePassword"));
KeyStore keyStore = getKeyStore(System.getProperty("javax.net.ssl.keyStore"), System.getProperty("javax.net.ssl.keyStorePassword"));
SSLContext sslContext = null;
try {
sslContext = SSLContexts.custom().loadKeyMaterial(keyStore, System.getProperty("javax.net.ssl.keyStorePassword").toCharArray()).loadTrustMaterial(trustStore).useTLS().build();
} catch (UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
throw new IllegalArgumentException("Unable to use javax.net.ssl.keyStorePassword to load key material to create SSL context for Solr client.");
}
sslContext.getDefaultSSLParameters().setNeedClientAuth(true);
sslContext.getDefaultSSLParameters().setWantClientAuth(true);
return sslContext;
}
use of java.security.KeyManagementException in project android_frameworks_base by crdroidandroid.
the class SSLCertificateSocketFactory method makeSocketFactory.
private SSLSocketFactory makeSocketFactory(KeyManager[] keyManagers, TrustManager[] trustManagers) {
try {
OpenSSLContextImpl sslContext = OpenSSLContextImpl.getPreferred();
sslContext.engineInit(keyManagers, trustManagers, null);
sslContext.engineGetClientSessionContext().setPersistentCache(mSessionCache);
return sslContext.engineGetSocketFactory();
} catch (KeyManagementException e) {
Log.wtf(TAG, e);
// Fallback
return (SSLSocketFactory) SSLSocketFactory.getDefault();
}
}
Aggregations