use of org.apache.http.conn.ssl.SSLSocketFactory in project oxAuth by GluuFederation.
the class Utils method createHttpClientTrustAll.
public static HttpClient createHttpClientTrustAll() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}, new X509HostnameVerifier() {
@Override
public void verify(String host, SSLSocket ssl) throws IOException {
}
@Override
public void verify(String host, X509Certificate cert) throws SSLException {
}
@Override
public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException {
}
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
registry.register(new Scheme("https", 443, sf));
ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
return new DefaultHttpClient(ccm);
}
use of org.apache.http.conn.ssl.SSLSocketFactory in project android_frameworks_base by DirtyUnicorns.
the class AbstractProxyTest method testConnectViaHttpProxyToHttps.
private void testConnectViaHttpProxyToHttps(ProxyConfig proxyConfig) throws Exception {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), true);
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.UPGRADE_TO_SSL_AT_END).clearHeaders());
server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via a secure proxy"));
server.play();
HttpClient httpProxyClient = newHttpClient();
SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
httpProxyClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", sslSocketFactory, 443));
HttpGet request = new HttpGet("https://android.com/foo");
proxyConfig.configure(server, httpProxyClient, request);
HttpResponse response = httpProxyClient.execute(request);
assertEquals("this response comes via a secure proxy", contentToString(response));
RecordedRequest connect = server.takeRequest();
assertEquals("Connect line failure on proxy " + proxyConfig, "CONNECT android.com:443 HTTP/1.1", connect.getRequestLine());
assertContains(connect.getHeaders(), "Host: android.com");
RecordedRequest get = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", get.getRequestLine());
assertContains(get.getHeaders(), "Host: android.com");
}
use of org.apache.http.conn.ssl.SSLSocketFactory in project android_frameworks_base by DirtyUnicorns.
the class AbstractProxyTest method testConnectToHttps.
public void testConnectToHttps() throws Exception {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via HTTPS"));
server.play();
HttpClient httpClient = newHttpClient();
SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", sslSocketFactory, server.getPort()));
HttpResponse response = httpClient.execute(new HttpGet("https://localhost:" + server.getPort() + "/foo"));
assertEquals("this response comes via HTTPS", contentToString(response));
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}
use of org.apache.http.conn.ssl.SSLSocketFactory in project qi4j-sdk by Qi4j.
the class AbstractSecureJettyTest method beforeSecure.
@Before
public void beforeSecure() throws GeneralSecurityException, IOException {
// Trust HTTP Client
KeyStore truststore = KeyStore.getInstance("JCEKS");
truststore.load(new FileInputStream(TRUSTSTORE_FILE), KS_PASSWORD.toCharArray());
AllowAllHostnameVerifier verifier = new AllowAllHostnameVerifier();
DefaultHttpClient trustClient = new DefaultHttpClient();
SSLSocketFactory trustSslFactory = new SSLSocketFactory(truststore);
trustSslFactory.setHostnameVerifier(verifier);
SchemeRegistry trustSchemeRegistry = trustClient.getConnectionManager().getSchemeRegistry();
trustSchemeRegistry.unregister(HTTPS);
trustSchemeRegistry.register(new Scheme(HTTPS, HTTPS_PORT, trustSslFactory));
trustHttpClient = trustClient;
// Mutual HTTP Client
KeyStore keystore = KeyStore.getInstance("JCEKS");
keystore.load(new FileInputStream(CLIENT_KEYSTORE_FILE), KS_PASSWORD.toCharArray());
DefaultHttpClient mutualClient = new DefaultHttpClient();
SSLSocketFactory mutualSslFactory = new SSLSocketFactory(keystore, KS_PASSWORD, truststore);
mutualSslFactory.setHostnameVerifier(verifier);
SchemeRegistry mutualSchemeRegistry = mutualClient.getConnectionManager().getSchemeRegistry();
mutualSchemeRegistry.unregister(HTTPS);
mutualSchemeRegistry.register(new Scheme(HTTPS, HTTPS_PORT, mutualSslFactory));
mutualHttpClient = mutualClient;
}
use of org.apache.http.conn.ssl.SSLSocketFactory in project java-chassis by ServiceComb.
the class HttpsClient method getHttpsClient.
public static HttpClient getHttpsClient(HttpsConfigInfoBean configBean) {
try {
SSLContext sslContext = createSSLContext(configBean);
SSLSocketFactory sf = new SSLSocketFactory(sslContext);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, SO_TIMEOUT);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), PORT_80));
registry.register(new Scheme("https", sf, PORT_443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (RuntimeException e) {
LOGGER.error("Get https client runtime exception: {}", FortifyUtils.getErrorInfo(e));
return new DefaultHttpClient();
} catch (GeneralSecurityException | IOException e) {
LOGGER.error("Get https client exception: {}", FortifyUtils.getErrorInfo(e));
return new DefaultHttpClient();
}
}
Aggregations