use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project microservices by pwillhan.
the class BasicHttpsSecurityApplicationTests method socketFactory.
private SSLConnectionSocketFactory socketFactory() throws Exception {
char[] password = "password".toCharArray();
KeyStore truststore = KeyStore.getInstance("PKCS12");
truststore.load(new ClassPathResource("rod.p12").getInputStream(), password);
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadKeyMaterial(truststore, password);
builder.loadTrustMaterial(truststore, new TrustSelfSignedStrategy());
return new SSLConnectionSocketFactory(builder.build(), new NoopHostnameVerifier());
}
use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project microservices by pwillhan.
the class X509ApplicationTests method socketFactory.
private SSLConnectionSocketFactory socketFactory() throws Exception {
char[] password = "password".toCharArray();
KeyStore truststore = KeyStore.getInstance("PKCS12");
truststore.load(new ClassPathResource("rod.p12").getInputStream(), password);
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadKeyMaterial(truststore, password);
builder.loadTrustMaterial(truststore, new TrustSelfSignedStrategy());
return new SSLConnectionSocketFactory(builder.build(), new NoopHostnameVerifier());
}
use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project syncope by apache.
the class HttpUtils method createHttpsClient.
private static CloseableHttpClient createHttpsClient() {
CloseableHttpClient chc = null;
try {
final SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
chc = HttpClients.custom().setSSLSocketFactory(new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE)).build();
} catch (Exception ex) {
// ignore
}
return chc;
}
use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project ofbiz-framework by apache.
the class UtilHttp method getAllowAllHttpClient.
public static CloseableHttpClient getAllowAllHttpClient(String jksStoreFileName, String jksStorePassword) {
try {
// Trust own CA and all self-signed certs
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(FileUtil.getFile(jksStoreFileName), jksStorePassword.toCharArray(), new TrustSelfSignedStrategy()).build();
// No host name verifier
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
return httpClient;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
return HttpClients.createDefault();
}
}
use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project JFramework by gugumall.
the class JHttp method createSelfSigned.
/**
* @param certFilePath
* @param password
* @param keyStoreType
* @return
* @throws Exception
*/
public static JHttp createSelfSigned(String certFilePath, String password, String[] protocols) throws Exception {
JHttp jhttp = new JHttp();
SSLContext ctx = SSLContexts.custom().loadTrustMaterial(new File(certFilePath), password.toCharArray(), new TrustSelfSignedStrategy()).build();
ctx.init(null, new TrustManager[] { new MyTrustManager() }, null);
SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(ctx, protocols, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier());
jhttp.poolingmgr = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", factory).build(), null, null, null, 5000, TimeUnit.MILLISECONDS);
jhttp.poolingmgr.setDefaultMaxPerRoute(100);
jhttp.poolingmgr.setMaxTotal(1000);
return jhttp;
}
Aggregations