Created
March 11, 2014 06:59
-
-
Save ehdez73/9480832 to your computer and use it in GitHub Desktop.
Test host certificate
This file contains hidden or 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.io.IOException; | |
| import java.net.UnknownHostException; | |
| import java.security.cert.Certificate; | |
| import javax.net.ssl.HttpsURLConnection; | |
| import javax.net.ssl.SSLSocket; | |
| import javax.net.ssl.SSLSocketFactory; | |
| public class CertTest { | |
| public static void main(String[] args) throws UnknownHostException, IOException { | |
| int port = 443; | |
| String hostname = "google.es"; | |
| System.setProperty("javax.net.debug", "ssl"); | |
| SSLSocketFactory factory = HttpsURLConnection.getDefaultSSLSocketFactory(); | |
| SSLSocket socket = (SSLSocket) factory.createSocket(hostname, port); | |
| socket.startHandshake(); | |
| Certificate[] serverCerts = socket.getSession().getPeerCertificates(); | |
| System.out.println("number of found certificates: " + serverCerts.length); | |
| for (Certificate certificate : serverCerts) { | |
| System.out.println(certificate.getPublicKey()); | |
| System.out.println(certificate); | |
| } | |
| socket.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment