use of javax.net.ssl.HttpsURLConnection in project ignite by apache.
the class TcpDiscoveryKubernetesIpFinder method getRegisteredAddresses.
/**
* {@inheritDoc}
*/
@Override
public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
init();
Collection<InetSocketAddress> addrs = new ArrayList<>();
try {
if (log.isDebugEnabled())
log.debug("Getting Apache Ignite endpoints from: " + url);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setHostnameVerifier(trustAllHosts);
conn.setSSLSocketFactory(ctx.getSocketFactory());
conn.addRequestProperty("Authorization", "Bearer " + serviceAccountToken(accountToken));
// Sending the request and processing a response.
ObjectMapper mapper = new ObjectMapper();
Endpoints endpoints = mapper.readValue(conn.getInputStream(), Endpoints.class);
if (endpoints != null) {
if (endpoints.subsets != null && !endpoints.subsets.isEmpty()) {
for (Subset subset : endpoints.subsets) {
if (subset.addresses != null && !subset.addresses.isEmpty()) {
for (Address address : subset.addresses) {
addrs.add(new InetSocketAddress(address.ip, 0));
if (log.isDebugEnabled())
log.debug("Added an address to the list: " + address.ip);
}
}
}
}
}
} catch (Exception e) {
throw new IgniteSpiException("Failed to retrieve Ignite pods IP addresses.", e);
}
return addrs;
}
use of javax.net.ssl.HttpsURLConnection in project aware-client by denzilferreira.
the class SSLManager method getRemoteCertificateExpiration.
/**
* Based on https://www.experts-exchange.com/questions/27668989/Getting-SSL-Certificate-expiry-date.html
* Improved to wait 5 seconds for the connection
* @param url
* @return
*/
public static Date getRemoteCertificateExpiration(URL url) {
try {
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
// 5 seconds to connect
conn.setConnectTimeout(5000);
// 10 seconds to acknowledge the response
conn.setReadTimeout(10000);
long now = System.currentTimeMillis();
while (conn.getResponseCode() != HttpsURLConnection.HTTP_OK || now - System.currentTimeMillis() <= 5000) {
// noop - wait up to 5 seconds to retrieve the certificate
}
// retrieve the N-length signing chain for the server certificates
// certs[0] is the server's certificate
// certs[1] - certs[N-1] are the intermediate authorities that signed the cert
// certs[N] is the root certificate authority of the chain
Certificate[] certs = conn.getServerCertificates();
if (certs.length > 0 && certs[0] instanceof X509Certificate) {
// certs[0] is an X.509 certificate, return its "notAfter" date
return ((X509Certificate) certs[0]).getNotAfter();
}
// connection is not HTTPS or server is not signed with an X.509 certificate, return null
return null;
} catch (SSLPeerUnverifiedException spue) {
// connection to server is not verified, unable to get certificates
Log.d(Aware.TAG, "Certificates: " + spue.getMessage());
return null;
} catch (IllegalStateException ise) {
// shouldn't get here -- indicates attempt to get certificates before
// connection is established
Log.d(Aware.TAG, "Certificates: " + ise.getMessage());
return null;
} catch (IOException ioe) {
// error connecting to URL -- this must be caught last since
// other exceptions are subclasses of IOException
Log.d(Aware.TAG, "Certificates: " + ioe.getMessage());
return null;
}
}
use of javax.net.ssl.HttpsURLConnection in project cxf by apache.
the class SSLv3Test method testSSLv3ServerNotAllowedByDefault.
@org.junit.Test
public void testSSLv3ServerNotAllowedByDefault() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = SSLv3Test.class.getResource("sslv3-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
System.setProperty("https.protocols", "SSLv3");
URL service = new URL("https://localhost:" + PORT);
HttpsURLConnection connection = (HttpsURLConnection) service.openConnection();
connection.setHostnameVerifier(new DisableCNCheckVerifier());
SSLContext sslContext = SSLContext.getInstance("SSL");
KeyStore trustedCertStore = KeyStore.getInstance("jks");
try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", SSLv3Test.class)) {
trustedCertStore.load(keystore, null);
}
TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
tmf.init(trustedCertStore);
TrustManager[] trustManagers = tmf.getTrustManagers();
sslContext.init(null, trustManagers, new java.security.SecureRandom());
connection.setSSLSocketFactory(sslContext.getSocketFactory());
try {
connection.connect();
fail("Failure expected on an SSLv3 connection attempt");
} catch (IOException ex) {
// expected
}
System.clearProperty("https.protocols");
bus.shutdown(true);
}
use of javax.net.ssl.HttpsURLConnection in project cxf by apache.
the class SSLv3Test method testSSLv3ServerAllowed.
@org.junit.Test
public void testSSLv3ServerAllowed() throws Exception {
// Doesn't work with IBM JDK
if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
return;
}
SpringBusFactory bf = new SpringBusFactory();
URL busFile = SSLv3Test.class.getResource("sslv3-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
System.setProperty("https.protocols", "SSLv3");
URL service = new URL("https://localhost:" + PORT2);
HttpsURLConnection connection = (HttpsURLConnection) service.openConnection();
connection.setHostnameVerifier(new DisableCNCheckVerifier());
SSLContext sslContext = SSLContext.getInstance("SSL");
KeyStore trustedCertStore = KeyStore.getInstance("jks");
try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", SSLv3Test.class)) {
trustedCertStore.load(keystore, null);
}
TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
tmf.init(trustedCertStore);
TrustManager[] trustManagers = tmf.getTrustManagers();
sslContext.init(null, trustManagers, new java.security.SecureRandom());
connection.setSSLSocketFactory(sslContext.getSocketFactory());
connection.connect();
connection.disconnect();
System.clearProperty("https.protocols");
bus.shutdown(true);
}
use of javax.net.ssl.HttpsURLConnection in project OpenGrok by OpenGrok.
the class Query method createHttpsUrlConnection.
private HttpsURLConnection createHttpsUrlConnection(URL url) {
try {
System.setProperty("jsse.enableSNIExtension", "false");
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
} };
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
return (HttpsURLConnection) url.openConnection();
} catch (Exception ex) {
handleException(ex);
}
return null;
}
Aggregations