return;
}
public HttpsURLConnection openSecureConnection(URL url) throws Exception {
// we assume the URL is https - if it is not, its an error so just let the cast throw exception
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
TrustManager[] trustManagers;
SSLContext sslContext = SSLContext.getInstance(getSecureSocketProtocol());
if (getTruststoreFile() == null) {
// we are configured to not care about authenticating the server, just encrypt but don't worry about certificates
trustManagers = new TrustManager[] { NO_OP_TRUST_MANAGER };
connection.setHostnameVerifier(NO_OP_HOSTNAME_VERIFIER);
} else {
// We need to configure our SSL connection with the agent's truststore so we can authenticate the server.
// First, create a KeyStore, but load it with our truststore entries.
KeyStore keyStore = KeyStore.getInstance(getTruststoreType());
keyStore.load(new FileInputStream(getTruststoreFile()), getTruststorePassword().toCharArray());
// now create a truststore manager instance and initialize it with our KeyStore we created with all our truststore entries
TrustManagerFactory tmf = TrustManagerFactory.getInstance(getTruststoreAlgorithm());
tmf.init(keyStore);
trustManagers = tmf.getTrustManagers();
}
sslContext.init(null, trustManagers, null);
connection.setSSLSocketFactory(sslContext.getSocketFactory());
return connection;
}