Created
November 1, 2013 18:28
-
-
Save samrocketman/7269673 to your computer and use it in GitHub Desktop.
A java file which will aide in testing certificate validation of a service.
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
//javac 1.6.0_31 | |
/* | |
Compile: | |
javac sslTest.java | |
Usage (similar to telnet): | |
java sslTest somehost someport | |
e.g. | |
java sslTest my.gitlabhost.com 443 | |
Successful expected output: | |
Protocol is TLSv1 | |
Closing connection. | |
*/ | |
import java.net.*; | |
import java.io.*; | |
import java.security.*; | |
import javax.net.ssl.*; | |
public class sslTest { | |
public static void main(String[] args) { | |
if (args.length < 2) { | |
System.out.println("Usage: java sslTest somehost someport"); | |
return; | |
} | |
int port = 0; | |
if(args[1] == null){ | |
port = 443; // default https port | |
}else{ | |
port = Integer.parseInt(args[1]); | |
} | |
String host = args[0]; | |
try{ | |
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); | |
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); | |
SSLSocket socket = (SSLSocket) factory.createSocket(host, port); | |
SSLSession session = socket.getSession(); | |
System.out.println("Protocol is " + session.getProtocol()); | |
// just close it | |
System.out.println("Closing connection."); | |
socket.close(); | |
}catch (IOException e) { | |
System.err.println(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment