use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project lucene-solr by apache.
the class SSLTestConfig method buildClientSSLContext.
/**
* Builds a new SSLContext for HTTP <b>clients</b> to use when communicating with servers which have
* been configured based on the settings of this object.
*
* NOTE: Uses a completely insecure {@link SecureRandom} instance to prevent tests from blocking
* due to lack of entropy, also explicitly allows the use of self-signed
* certificates (since that's what is almost always used during testing).
*/
public SSLContext buildClientSSLContext() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {
assert isSSLMode();
SSLContextBuilder builder = SSLContexts.custom();
builder.setSecureRandom(NotSecurePsuedoRandom.INSTANCE);
// NOTE: KeyStore & TrustStore are swapped because they are from configured from server perspective...
// we are a client - our keystore contains the keys the server trusts, and vice versa
builder.loadTrustMaterial(buildKeyStore(keyStore, getKeyStorePassword()), new TrustSelfSignedStrategy()).build();
if (isClientAuthMode()) {
builder.loadKeyMaterial(buildKeyStore(trustStore, getTrustStorePassword()), getTrustStorePassword().toCharArray());
}
return builder.build();
}
use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project lucene-solr by apache.
the class SSLTestConfig method buildServerSSLContext.
/**
* Builds a new SSLContext for jetty servers which have been configured based on the settings of
* this object.
*
* NOTE: Uses a completely insecure {@link SecureRandom} instance to prevent tests from blocking
* due to lack of entropy, also explicitly allows the use of self-signed
* certificates (since that's what is almost always used during testing).
* almost always used during testing).
*/
public SSLContext buildServerSSLContext() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {
assert isSSLMode();
SSLContextBuilder builder = SSLContexts.custom();
builder.setSecureRandom(NotSecurePsuedoRandom.INSTANCE);
builder.loadKeyMaterial(buildKeyStore(keyStore, getKeyStorePassword()), getKeyStorePassword().toCharArray());
if (isClientAuthMode()) {
builder.loadTrustMaterial(buildKeyStore(trustStore, getTrustStorePassword()), new TrustSelfSignedStrategy()).build();
}
return builder.build();
}
use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project vcell by virtualcell.
the class VCellApiClient method initClient.
private void initClient() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
SSLContextBuilder builder = new SSLContextBuilder();
if (bIgnoreCertProblems) {
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
}
SSLConnectionSocketFactory sslsf = null;
if (bIgnoreHostMismatch) {
X509HostnameVerifier hostNameVerifier = new AllowAllHostnameVerifier();
sslsf = new SSLConnectionSocketFactory(builder.build(), hostNameVerifier);
} else {
sslsf = new SSLConnectionSocketFactory(builder.build());
}
httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).setRedirectStrategy(new DefaultRedirectStrategy()).build();
httpClientContext = HttpClientContext.create();
}
use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project janusgraph by JanusGraph.
the class SSLConfigurationCallback method customizeHttpClient.
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
final SSLContext sslcontext;
final TrustStrategy trustStrategy = allowSelfSignedCertificates ? new TrustSelfSignedStrategy() : null;
try {
if (StringUtils.isNotEmpty(trustStoreFile)) {
sslContextBuilder.loadTrustMaterial(new File(trustStoreFile), trustStorePassword.toCharArray(), trustStrategy);
} else {
sslContextBuilder.loadTrustMaterial(trustStrategy);
}
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException e) {
throw new RuntimeException("Invalid trust store file " + trustStoreFile, e);
} catch (IOException e) {
throw new RuntimeException("Unable to load trust store data from " + trustStoreFile, e);
}
try {
if (StringUtils.isNotEmpty(keyStoreFile)) {
sslContextBuilder.loadKeyMaterial(new File(keyStoreFile), keyStorePassword.toCharArray(), keyPassword.toCharArray());
}
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | UnrecoverableKeyException e) {
throw new RuntimeException("Invalid key store file " + keyStoreFile, e);
} catch (IOException e) {
throw new RuntimeException("Unable to load key store data from " + keyStoreFile, e);
}
try {
sslcontext = sslContextBuilder.build();
} catch (KeyManagementException | NoSuchAlgorithmException e) {
throw new RuntimeException("SSL context initialization failed", e);
}
httpClientBuilder.setSSLContext(sslcontext);
if (disableHostNameVerification) {
httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier());
}
return httpClientBuilder;
}
use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project jetty-bootstrap by teknux-org.
the class AbstractJettyBootstrapTest method get.
protected SimpleResponse get(String url) throws IllegalStateException, IOException, JettyBootstrapException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
SimpleResponse simpleResponse = new SimpleResponse();
CloseableHttpClient httpClient;
HttpGet httpGet;
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(SOCKET_TIMEOUT).build();
if (ssl) {
SSLContextBuilder sSLContextBuilder = new SSLContextBuilder();
sSLContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sSLConnectionSocketFactory = new SSLConnectionSocketFactory(sSLContextBuilder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
httpClient = HttpClients.custom().setSSLSocketFactory(sSLConnectionSocketFactory).build();
httpGet = new HttpGet("https://" + HOST + ":" + getPort() + url);
} else {
httpClient = HttpClients.createDefault();
httpGet = new HttpGet("http://" + HOST + ":" + getPort() + url);
}
httpGet.setConfig(requestConfig);
CloseableHttpResponse response = null;
try {
response = httpClient.execute(httpGet);
simpleResponse.setStatusCode(response.getStatusLine().getStatusCode());
simpleResponse.setContent(IOUtils.toString(response.getEntity().getContent()));
} finally {
if (response != null) {
response.close();
}
httpClient.close();
}
return simpleResponse;
}
Aggregations