use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project docker-client by spotify.
the class DefaultDockerClient method getSchemeRegistry.
private Registry<ConnectionSocketFactory> getSchemeRegistry(final Builder builder) {
final SSLConnectionSocketFactory https;
if (builder.dockerCertificatesStore == null) {
https = SSLConnectionSocketFactory.getSocketFactory();
} else {
https = new SSLConnectionSocketFactory(builder.dockerCertificatesStore.sslContext(), builder.dockerCertificatesStore.hostnameVerifier());
}
final RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.<ConnectionSocketFactory>create().register("https", https).register("http", PlainConnectionSocketFactory.getSocketFactory());
if (builder.uri.getScheme().equals(UNIX_SCHEME)) {
registryBuilder.register(UNIX_SCHEME, new UnixConnectionSocketFactory(builder.uri));
}
return registryBuilder.build();
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project ovirt-engine-sdk-java by oVirt.
the class ConnectionBuilder45 method createConnectionSocketFactoryRegistry.
private Registry createConnectionSocketFactoryRegistry() {
String protocol = getProtocol();
Registry registry = null;
// Create SSL/TLS or plain connection:
if (HTTP_PROTOCOL.equals(protocol)) {
ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
registry = RegistryBuilder.<ConnectionSocketFactory>create().register(HTTP_PROTOCOL, plainsf).build();
} else if (HTTPS_PROTOCOL.equals(protocol)) {
try {
LayeredConnectionSocketFactory sslsf = null;
if (this.insecure) {
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, new TrustManager[] { noCaTrustManager }, null);
sslsf = new SSLConnectionSocketFactory(sslcontext, NoopHostnameVerifier.INSTANCE);
} else {
SSLContextBuilder sslContextBuilder = SSLContexts.custom();
if (trustStoreFile != null) {
sslContextBuilder.loadTrustMaterial(new File(trustStoreFile), this.trustStorePassword != null ? this.trustStorePassword.toCharArray() : null);
}
SSLContext sslContext = sslContextBuilder.build();
sslsf = new SSLConnectionSocketFactory(sslContext, new DefaultHostnameVerifier());
}
registry = RegistryBuilder.<ConnectionSocketFactory>create().register(HTTPS_PROTOCOL, sslsf).build();
} catch (NoSuchAlgorithmException e) {
throw new Error(NO_TLS_ERROR, e);
} catch (KeyManagementException e) {
throw new Error(BAD_KEY_ERROR, e);
} catch (KeyStoreException e) {
throw new Error(KEY_STORE_ERROR, e);
} catch (FileNotFoundException e) {
throw new Error(KEY_STORE_FILE_NOT_FOUND_ERROR, e);
} catch (CertificateException e) {
throw new Error(CERTIFICATE_ERROR, e);
} catch (IOException e) {
throw new Error(IO_ERROR, e);
}
} else {
throw new Error(BAD_PROTOCOL_ERROR + protocol);
}
return registry;
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project opacclient by opacapp.
the class AdditionalKeyStoresSSLSocketFactory method create.
/**
* Creates a customized keystore
*
* @param socketFactory The class that should be used to instantiate a new socket factory, must
* be a subclass of {@link SSLConnectionSocketFactory}.
* @return a new {@link SSLConnectionSocketFactory}
*/
public static SSLConnectionSocketFactory create(Class<?> socketFactory, X509TrustManager trustManager) throws NoSuchAlgorithmException, KeyManagementException {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { trustManager }, null);
if (socketFactory != null) {
try {
return (SSLConnectionSocketFactory) socketFactory.getDeclaredConstructor(SSLContext.class).newInstance(sslContext);
} catch (Exception e) {
// Fall back to default
e.printStackTrace();
}
}
return new SSLConnectionSocketFactory(sslContext);
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project opacclient by opacapp.
the class HttpClientFactory method getNewApacheHttpClient.
/**
* Create a new HttpClient.
*
* @param tls_only If this is true, only TLS v1 and newer will be used, SSLv3 will be disabled.
* We highly recommend to set this to true, if possible. This is currently a
* no-op on the default implementation and only used in the Android
* implementation!
*/
public HttpClient getNewApacheHttpClient(boolean customssl, boolean tls_only, boolean allCipherSuites, boolean disguise_app) {
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setRedirectStrategy(new CustomRedirectStrategy());
if (disguise_app) {
builder.setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, " + "like Gecko) Chrome/43.0.2357.130 Safari/537.36\t");
} else {
builder.setUserAgent(user_agent);
}
if (customssl && ssl_store_path != null) {
try {
if (trust_store == null) {
trust_store = getKeyStore();
}
SSLConnectionSocketFactory sf = AdditionalKeyStoresSSLSocketFactory.create(getSocketFactoryClass(tls_only, allCipherSuites), new AdditionalKeyStoresSSLSocketFactory.AdditionalKeyStoresTrustManager(trust_store));
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sf).build();
HttpClientConnectionManager ccm = new PoolingHttpClientConnectionManager(registry);
builder.setConnectionManager(ccm);
return builder.build();
} catch (Exception e) {
e.printStackTrace();
return builder.build();
}
} else {
return builder.build();
}
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project ais-sdk by huaweicloudsdk.
the class AccessServiceImpl method getDefaultHttpClient.
private CloseableHttpClient getDefaultHttpClient() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS().build();
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());
return HttpClients.custom().setSSLSocketFactory(sslSocketFactory).build();
}
Aggregations