use of streamer.ssl.TrustAllX509TrustManager in project cloudstack by apache.
the class SocketWrapperImpl method upgradeToSsl.
@Override
public void upgradeToSsl() {
if (sslSocket != null)
// Already upgraded
return;
if (verbose)
System.out.println("[" + this + "] INFO: Upgrading socket to SSL.");
try {
// Use most secure implementation of SSL available now.
// JVM will try to negotiate TLS1.2, then will fallback to TLS1.0, if
// TLS1.2 is not supported.
SSLContext sslContext = SSLUtils.getSSLContext();
// Trust all certificates (FIXME: insecure)
sslContext.init(null, new TrustManager[] { new TrustAllX509TrustManager(sslState) }, null);
SSLSocketFactory sslSocketFactory = new SecureSSLSocketFactory(sslContext);
sslSocket = (SSLSocket) sslSocketFactory.createSocket(socket, address.getHostName(), address.getPort(), true);
sslSocket.setEnabledProtocols(SSLUtils.getSupportedProtocols(sslSocket.getEnabledProtocols()));
sslSocket.startHandshake();
InputStream sis = sslSocket.getInputStream();
source.setInputStream(sis);
OutputStream sos = sslSocket.getOutputStream();
sink.setOutputStream(sos);
} catch (Exception e) {
throw new RuntimeException("Cannot upgrade socket to SSL: " + e.getMessage(), e);
}
}
Aggregations