Skip to content

Instantly share code, notes, and snippets.

@cornet
Created October 7, 2015 15:19
Show Gist options
  • Save cornet/f77b09cbf3f56f8082da to your computer and use it in GitHub Desktop.
Save cornet/f77b09cbf3f56f8082da to your computer and use it in GitHub Desktop.
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import javax.net.ssl.SSLServerSocketFactory;
/*
* * Source from Christopher Schultz
* * @see http://markmail.org/message/zn4namfhypyxum23
* */
public class SSLInfo
{
public static void main(String[] args)
throws Exception
{
SSLServerSocketFactory ssf =
(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
String[] defaultCiphers = ssf.getDefaultCipherSuites();
String[] availableCiphers = ssf.getSupportedCipherSuites();
TreeMap ciphers = new TreeMap();
for(int i=0; i<availableCiphers.length; ++i )
ciphers.put(availableCiphers[i], Boolean.FALSE);
for(int i=0; i<defaultCiphers.length; ++i )
ciphers.put(defaultCiphers[i], Boolean.TRUE);
System.out.println("Default\tCipher");
for(Iterator i = ciphers.entrySet().iterator(); i.hasNext(); ) {
Map.Entry cipher=(Map.Entry)i.next();
if(Boolean.TRUE.equals(cipher.getValue()))
System.out.print('*');
else
System.out.print(' ');
System.out.print('\t');
System.out.println(cipher.getKey());
}
}
}
/*
* Makes simple connection to SSL enabled site.
* Useful for debugging SSL Exceptions :)
*
* To Run:
* $ javac SSLTest.java
* $ java -Djavax.net.debug=all SSLTest
*
*/
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
public class SSLTest {
/**
* @param args
* @throws IOException
* @throws UnknownHostException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException,
UnknownHostException, IOException {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
Socket s = SSLSocketFactory.getDefault()
.createSocket("api.sandbox.freeagent.com", 443);
OutputStream out = s.getOutputStream();
out.write("Say hello".getBytes("UTF8"));
out.close();
s.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment