Skip to content

Instantly share code, notes, and snippets.

@alces
Last active October 9, 2019 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alces/6f0a3a0a06dbf74186a75fa269ffa059 to your computer and use it in GitHub Desktop.
Save alces/6f0a3a0a06dbf74186a75fa269ffa059 to your computer and use it in GitHub Desktop.
Java "one-liner" for testing SSL connections (truststores, client auth, etc)
import java.io.*;
import java.net.*;
/**
* Open URL passed as the first command-line argument and read the first line from it
*
* Example usage for testing client auth:
* java -Djavax.net.ssl.trustStore=/path/to/truststore.jks \
* -Djavax.net.ssl.trustStorePassword=myword \
* -Djavax.net.ssl.keyStore=/path/to/keystore.jks \
* -Djavax.net.ssl.keyStorePassword=myword \
* UrlConnectTest https://my.url:port
*/
public class UrlConnectTest {
public static void main (String args[]) throws IOException, MalformedURLException {
InputStream s = new URL(args[0]).openStream();
BufferedReader r = new BufferedReader(new InputStreamReader(s));
System.out.println(r.readLine());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment