Created
April 6, 2011 15:27
-
-
Save caspian311/905856 to your computer and use it in GitHub Desktop.
print out what encryption algorithm you're using in a HTTPS connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.URL; | |
import java.security.cert.CertificateException; | |
import java.security.cert.X509Certificate; | |
import javax.net.ssl.HostnameVerifier; | |
import javax.net.ssl.HttpsURLConnection; | |
import javax.net.ssl.SSLContext; | |
import javax.net.ssl.SSLSession; | |
import javax.net.ssl.SSLSocketFactory; | |
import javax.net.ssl.TrustManager; | |
import javax.net.ssl.X509TrustManager; | |
public class Connection { | |
public static void main(String[] args) throws Exception { | |
HttpsURLConnection connection = (HttpsURLConnection) new URL( | |
"https://localhost:8443").openConnection(); | |
connection.setHostnameVerifier(new HostnameVerifier() { | |
@Override | |
public boolean verify(String hostname, SSLSession session) { | |
return true; | |
} | |
}); | |
SSLContext context = SSLContext.getInstance("TLS"); | |
context.init(null, new TrustManager[] { new X509TrustManager() { | |
@Override | |
public void checkClientTrusted(X509Certificate[] chain, | |
String authType) throws CertificateException { | |
} | |
@Override | |
public void checkServerTrusted(X509Certificate[] chain, | |
String authType) throws CertificateException { | |
} | |
@Override | |
public X509Certificate[] getAcceptedIssuers() { | |
return null; | |
} | |
} }, null); | |
SSLSocketFactory socketFactory = context.getSocketFactory(); | |
connection.setSSLSocketFactory(socketFactory); | |
connection.connect(); | |
System.out.println(connection.getCipherSuite()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment