// JVM will try to negotiate TLS1.2, then will fallback to TLS1.0, if
// TLS1.2 is not supported.
SSLContext sslContext = SSLContext.getInstance(SSL_VERSION_TO_USE);
// Trust all certificates (FIXME: insecure)
sslContext.init(null, new TrustManager[] {new TrustAllX509TrustManager(sslState)}, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
sslSocket = (SSLSocket)sslSocketFactory.createSocket(socket, address.getHostName(), address.getPort(), true);
sslSocket.startHandshake();