use of javax.net.ssl.HostnameVerifier in project OpenAM by OpenRock.
the class ClusterStateService method checkServerUp.
/**
* Internal method for checking health status using sock.connect()
* <p/>
* TODO -- Use a better mechanism for alive status. 10.1+.
*
* @param info server info instance
* @return true if server is up, false otherwise
*/
private boolean checkServerUp(StateInfo info) {
if (info == null) {
return false;
}
if (localServerId.equals(info.id)) {
return true;
}
boolean result = false;
Socket sock = null;
InputStream is = null;
try {
/*
* If we need to check for a front end proxy, we need
* to send a request.
*/
if (!doRequest) {
sock = new Socket();
sock.connect(info.address, timeout);
result = true;
} else {
HttpURLConnection connection = null;
int responseCode = 0;
try {
connection = (HttpURLConnection) info.url.openConnection();
connection.setConnectTimeout(timeout);
connection.setReadTimeout(timeout);
if (connection instanceof HttpsURLConnection) {
((HttpsURLConnection) connection).setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}
is = connection.getInputStream();
responseCode = connection.getResponseCode();
readStream(is);
} catch (IOException ioe) {
if (connection != null) {
readStream(connection.getErrorStream());
}
}
result = responseCode == HttpURLConnection.HTTP_OK;
}
} catch (Exception ex) {
result = false;
} finally {
if (sock != null) {
try {
sock.close();
} catch (IOException ioe) {
//ignored
}
}
IOUtils.closeIfNotNull(is);
}
return result;
}
use of javax.net.ssl.HostnameVerifier 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 javax.net.ssl.HostnameVerifier in project jedis by xetorthio.
the class SSLJedisTest method connectWithShardInfoAndCustomSocketFactory.
/**
* Tests opening an SSL/TLS connection to redis with a custom socket factory.
*/
@Test
public void connectWithShardInfoAndCustomSocketFactory() throws Exception {
final URI uri = URI.create("rediss://localhost:6390");
final SSLSocketFactory sslSocketFactory = createTrustStoreSslSocketFactory();
final SSLParameters sslParameters = new SSLParameters();
HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, hostnameVerifier);
shardInfo.setPassword("foobared");
Jedis jedis = new Jedis(shardInfo);
jedis.get("foo");
jedis.disconnect();
jedis.close();
}
use of javax.net.ssl.HostnameVerifier in project NoHttp by yanzhenjie.
the class OkHttpNetworkExecutor method execute.
@Override
public Network execute(IBasicRequest request) throws Exception {
URL url = new URL(request.url());
HttpURLConnection connection = URLConnectionFactory.getInstance().open(url, request.getProxy());
connection.setConnectTimeout(request.getConnectTimeout());
connection.setReadTimeout(request.getReadTimeout());
connection.setInstanceFollowRedirects(false);
if (connection instanceof HttpsURLConnection) {
SSLSocketFactory sslSocketFactory = request.getSSLSocketFactory();
if (sslSocketFactory != null)
((HttpsURLConnection) connection).setSSLSocketFactory(sslSocketFactory);
HostnameVerifier hostnameVerifier = request.getHostnameVerifier();
if (hostnameVerifier != null)
((HttpsURLConnection) connection).setHostnameVerifier(hostnameVerifier);
}
// Base attribute
connection.setRequestMethod(request.getRequestMethod().toString());
connection.setDoInput(true);
boolean isAllowBody = request.getRequestMethod().allowRequestBody();
connection.setDoOutput(isAllowBody);
// Adds all request header to connection.
Headers headers = request.headers();
// To fix bug: accidental EOFException before API 19.
List<String> values = headers.getValues(Headers.HEAD_KEY_CONNECTION);
if (values == null || values.size() == 0)
headers.add(Headers.HEAD_KEY_CONNECTION, Headers.HEAD_VALUE_CONNECTION_KEEP_ALIVE);
if (isAllowBody)
headers.set(Headers.HEAD_KEY_CONTENT_LENGTH, Long.toString(request.getContentLength()));
Map<String, String> requestHeaders = headers.toRequestHeaders();
for (Map.Entry<String, String> headerEntry : requestHeaders.entrySet()) {
String headKey = headerEntry.getKey();
String headValue = headerEntry.getValue();
Logger.i(headKey + ": " + headValue);
connection.setRequestProperty(headKey, headValue);
}
// 5. Connect
connection.connect();
return new OkHttpNetwork(connection);
}
use of javax.net.ssl.HostnameVerifier in project intellij-community by JetBrains.
the class IpnbConnection method configureHttpsConnection.
private void configureHttpsConnection() {
HttpsURLConnection.setDefaultSSLSocketFactory(CertificateManager.getInstance().getSslContext().getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession session) {
return myURI.getHost().equals(s);
}
});
}
Aggregations