use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project validator by validator.
the class PrudentHttpEntityResolver method setParams.
/**
* Sets the timeouts of the HTTP client.
*
* @param connectionTimeout
* timeout until connection established in milliseconds. Zero
* means no timeout.
* @param socketTimeout
* timeout for waiting for data in milliseconds. Zero means no
* timeout.
* @param maxRequests
* maximum number of connections to a particular host
*/
public static void setParams(int connectionTimeout, int socketTimeout, int maxRequests) {
PrudentHttpEntityResolver.maxRequests = maxRequests;
PoolingHttpClientConnectionManager phcConnMgr;
//
Registry<ConnectionSocketFactory> registry = //
RegistryBuilder.<ConnectionSocketFactory>create().register("http", //
PlainConnectionSocketFactory.getSocketFactory()).register("https", //
SSLConnectionSocketFactory.getSocketFactory()).build();
HttpClientBuilder builder = HttpClients.custom().useSystemProperties();
builder.setRedirectStrategy(new LaxRedirectStrategy());
builder.setMaxConnPerRoute(maxRequests);
builder.setMaxConnTotal(Integer.parseInt(System.getProperty("nu.validator.servlet.max-total-connections", "200")));
if ("true".equals(System.getProperty("nu.validator.xml.promiscuous-ssl", "true"))) {
//
try {
SSLContext promiscuousSSLContext = //
new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
}).build();
builder.setSslcontext(promiscuousSSLContext);
//
HostnameVerifier verifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
//
SSLConnectionSocketFactory promiscuousSSLConnSocketFactory = new SSLConnectionSocketFactory(promiscuousSSLContext, verifier);
registry = //
RegistryBuilder.<ConnectionSocketFactory>create().register("https", //
promiscuousSSLConnSocketFactory).register("http", //
PlainConnectionSocketFactory.getSocketFactory()).build();
} catch (KeyManagementException | KeyStoreException | NoSuchAlgorithmException | NumberFormatException e) {
e.printStackTrace();
}
}
phcConnMgr = new PoolingHttpClientConnectionManager(registry);
phcConnMgr.setDefaultMaxPerRoute(maxRequests);
phcConnMgr.setMaxTotal(200);
builder.setConnectionManager(phcConnMgr);
RequestConfig.Builder config = RequestConfig.custom();
config.setCircularRedirectsAllowed(true);
config.setMaxRedirects(Integer.parseInt(System.getProperty("nu.validator.servlet.max-redirects", "20")));
config.setConnectTimeout(connectionTimeout);
config.setCookieSpec(CookieSpecs.BEST_MATCH);
config.setSocketTimeout(socketTimeout);
config.setCookieSpec(CookieSpecs.IGNORE_COOKIES);
client = builder.setDefaultRequestConfig(config.build()).build();
}
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();
}
}
Aggregations