Guest User

TestCiphers

a guest
Apr 26th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. public class TestCiphers {
  2.     public static void main(String[] args)
  3.             throws Exception
  4.             {
  5.                 SSLContext ctx = SSLContext.getInstance("TLSv1");
  6.                 // Create an empty TrustManagerFactory to avoid loading default CA
  7.                 KeyStore ks = KeyStore.getInstance("JKS");
  8.                 TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
  9.                 tmf.init(ks);
  10.                 ctx.init(null, tmf.getTrustManagers(), null);
  11.                 SSLSocket socket = (SSLSocket) ctx.getSocketFactory().createSocket("mozilla.org", 443);
  12.                 printSupportedCiphers(socket);
  13.                 printEnabledCiphers(socket);
  14.             }
  15.  
  16.             private static void printSupportedCiphers(SSLSocket socket)
  17.             {
  18.                 printInfos("Supported cipher suites", socket.getSupportedCipherSuites());
  19.             }
  20.  
  21.             private static void printEnabledCiphers(SSLSocket socket)
  22.             {
  23.                 printInfos("Enabled cipher suites", socket.getEnabledCipherSuites());
  24.             }
  25.  
  26.             private static void printInfos(String prefix, String[] values)
  27.             {
  28.                 System.out.println(prefix + ":");
  29.                 for (int i = 0; i < values.length; i++)
  30.                     System.out.println("  " + values[i]);
  31.             }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment