use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project intellij-community by JetBrains.
the class AuthenticationService method getClient.
@NotNull
private HttpClient getClient(@NotNull SVNURL repositoryUrl) {
// TODO: Implement algorithm of resolving necessary enabled protocols (TLSv1 vs SSLv3) instead of just using values from Settings.
SSLContext sslContext = createSslContext(repositoryUrl);
List<String> supportedProtocols = getSupportedSslProtocols();
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext, ArrayUtil.toStringArray(supportedProtocols), null, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
// TODO: Seems more suitable here to read timeout values directly from config file - without utilizing SvnAuthenticationManager.
final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
if (haveDataForTmpConfig()) {
IdeHttpClientHelpers.ApacheHttpClient4.setProxyIfEnabled(requestConfigBuilder);
IdeHttpClientHelpers.ApacheHttpClient4.setProxyCredentialsIfEnabled(credentialsProvider);
}
return HttpClients.custom().setSSLSocketFactory(socketFactory).setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(getAuthenticationManager().getReadTimeout(repositoryUrl)).build()).setDefaultRequestConfig(requestConfigBuilder.setConnectTimeout(getAuthenticationManager().getConnectTimeout(repositoryUrl)).build()).setDefaultCredentialsProvider(credentialsProvider).build();
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project wildfly by wildfly.
the class WebSecurityCERTTestCase method getHttpsClient.
private static CloseableHttpClient getHttpsClient(String alias) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
JBossJSSESecurityDomain jsseSecurityDomain = new JBossJSSESecurityDomain("client-cert");
jsseSecurityDomain.setKeyStorePassword("changeit");
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
URL keystore = tccl.getResource("security/client.keystore");
jsseSecurityDomain.setKeyStoreURL(keystore.getPath());
jsseSecurityDomain.setClientAlias(alias);
jsseSecurityDomain.reloadKeyAndTrustStore();
KeyManager[] keyManagers = jsseSecurityDomain.getKeyManagers();
TrustManager[] trustManagers = jsseSecurityDomain.getTrustManagers();
ctx.init(keyManagers, trustManagers, null);
HostnameVerifier verifier = (string, ssls) -> true;
//SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
SSLConnectionSocketFactory ssf = new SSLConnectionSocketFactory(ctx, verifier);
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", ssf).build();
HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registry);
return HttpClientBuilder.create().setSSLSocketFactory(ssf).setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionManager(ccm).build();
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project ats-framework by Axway.
the class HttpClient method setupSSL.
/**
* Setup SSL. Pass the trusted certificates and client private key and certificate,
* if applicable.
*
* @param httpClientBuilder The client builder
* @throws HttpException
*/
private void setupSSL(HttpClientBuilder httpClientBuilder) throws HttpException {
try {
SSLContextBuilder sslContextBuilder = SSLContexts.custom();
sslContextBuilder.loadTrustMaterial(convertToKeyStore(trustedServerCertificates), new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return checkIsTrusted(chain);
}
});
if (clientSSLKeyStore != null) {
sslContextBuilder.loadKeyMaterial(clientSSLKeyStore, "".toCharArray());
}
SSLContext sslContext = sslContextBuilder.build();
// Allow all supported protocols
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, supportedProtocols, supportedCipherSuites, new NoopHostnameVerifier());
httpClientBuilder.setSSLSocketFactory(sslsf);
} catch (Exception e) {
throw new HttpException("Exception occurred when setting up SSL.", e);
}
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project ats-framework by Axway.
the class HttpsClient method connect.
/**
* Connect to a remote host using basic authentication.
*
* @param hostname the host to connect to
* @param userName the user name
* @param password the password for the provided user name
* @throws FileTransferException
*/
@Override
public void connect(String hostname, String userName, String password) throws FileTransferException {
super.connect(hostname, userName, password);
// trust everybody
try {
SSLContext sslContext = SslUtils.getTrustAllSSLContext();
SSLConnectionSocketFactory ssf = new SSLConnectionSocketFactory(sslContext, encryptionProtocols, cipherSuites, new NoopHostnameVerifier());
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", ssf).build();
HttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
this.httpBuilder.setConnectionManager(connectionManager).setSchemePortResolver(new DefaultSchemePortResolver());
this.httpClient = this.httpBuilder.build();
} catch (Exception e) {
throw new FileTransferException("Error setting trust manager", e);
}
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project spark by perwendel.
the class SparkTestUtil method httpClientBuilder.
private HttpClientBuilder httpClientBuilder() {
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(getSslFactory(), (paramString, paramSSLSession) -> true);
Registry<ConnectionSocketFactory> socketRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", sslConnectionSocketFactory).build();
BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(socketRegistry);
return HttpClientBuilder.create().setConnectionManager(connManager);
}
Aggregations