Changeset 850:aafbb3d3b3eb
- Timestamp:
- 02/04/12 23:14:59 (4 months ago)
- Branch:
- default
- Children:
- 852:5a74670b3de6, 853:27b5e31d681d
- Location:
- kraken-sslscan
- Files:
-
- 2 edited
-
pom.xml (modified) (1 diff)
-
src/main/java/org/krakenapps/sslscan/SslScanner.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kraken-sslscan/pom.xml
r844 r850 26 26 <Export-Package>org.krakenapps.sslscan</Export-Package> 27 27 <Import-Package>*</Import-Package> 28 <Main-Class>org.krakenapps.sslscan.SslScanner</Main-Class> 28 29 </instructions> 29 30 </configuration> -
kraken-sslscan/src/main/java/org/krakenapps/sslscan/SslScanner.java
r844 r850 2 2 3 3 import java.io.IOException; 4 import java.io.InputStream;5 import java.net.InetAddress;6 import java.net.MalformedURLException;7 4 import java.net.Socket; 8 import java.net.URL;9 import java.net.URLConnection;10 import java.net.UnknownHostException;11 5 import java.security.NoSuchAlgorithmException; 12 6 import java.security.SecureRandom; … … 14 8 import java.security.cert.X509Certificate; 15 9 16 import javax.net.ssl.HostnameVerifier; 17 import javax.net.ssl.HttpsURLConnection; 10 import javax.net.SocketFactory; 11 import javax.net.ssl.HandshakeCompletedEvent; 12 import javax.net.ssl.HandshakeCompletedListener; 18 13 import javax.net.ssl.SSLContext; 19 import javax.net.ssl.SSLSession; 20 import javax.net.ssl.SSLSocketFactory; 14 import javax.net.ssl.SSLHandshakeException; 15 import javax.net.ssl.SSLParameters; 16 import javax.net.ssl.SSLSocket; 21 17 import javax.net.ssl.TrustManager; 22 18 import javax.net.ssl.X509TrustManager; 23 19 20 import sun.security.validator.ValidatorException; 21 22 @SuppressWarnings("restriction") 24 23 public class SslScanner { 24 private SSLContext ctx; 25 25 26 public static void main(String[] args) throws Exception { 26 HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { 27 new SslScanner().run(args); 28 } 29 30 public void run(String[] args) throws Exception { 31 if (args.length < 2) { 32 System.out.println("SSL Cipher Suite Scanner, xeraph@nchovy.com"); 33 System.out.println("Usage: java -jar kraken-sslscan.jar [hostname] [port]"); 34 return; 35 } 36 37 ctx = SSLContext.getDefault(); 38 String hostname = args[0]; 39 Integer port = Integer.valueOf(args[1]); 40 41 checkCertificate(hostname, port); 42 checkAllCipherSuites(ctx, hostname, port); 43 } 44 45 private void checkCertificate(String hostname, int port) throws Exception { 46 try { 47 checkCipherSuite(hostname, port, null); 48 } catch (SSLHandshakeException e) { 49 if (e.getCause() instanceof ValidatorException) { 50 System.out.println("Warning: Invalid Certificate, Ignoring.."); 51 System.out.println(">> " + e.getCause().getMessage()); 52 53 ctx = SSLContext.getInstance("SSL"); 54 ctx.init(null, trustAllCerts, new SecureRandom()); 55 } 56 } 57 } 58 59 private void checkAllCipherSuites(SSLContext ctx, String hostname, Integer port) throws NoSuchAlgorithmException { 60 SSLParameters sslParams = ctx.getSupportedSSLParameters(); 61 for (String cipher : sslParams.getCipherSuites()) { 62 try { 63 checkCipherSuite(hostname, port, cipher); 64 System.out.println("PASS " + cipher); 65 } catch (IOException e) { 66 System.out.println("FAIL " + cipher); 67 } 68 } 69 } 70 71 public void checkCipherSuite(String hostname, int port, String cipher) throws IOException { 72 SocketFactory socketFactory = ctx.getSocketFactory(); 73 Socket socket = socketFactory.createSocket(hostname, port); 74 SSLSocket sslSocket = (SSLSocket) socket; 75 76 if (cipher != null) 77 sslSocket.setEnabledCipherSuites(new String[] { cipher }); 78 79 sslSocket.addHandshakeCompletedListener(new HandshakeCompletedListener() { 27 80 @Override 28 public boolean verify(String hostname, SSLSession session) { 29 System.out.println(hostname); 30 System.out.println(session); 31 System.out.println("CIPHER SUITE: " + session.getCipherSuite()); 32 return true; 81 public void handshakeCompleted(HandshakeCompletedEvent e) { 33 82 } 34 83 }); 35 36 TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {37 @Override38 public X509Certificate[] getAcceptedIssuers() {39 return null;40 }41 84 42 @Override 43 public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 44 } 85 sslSocket.startHandshake(); 86 } 45 87 46 @Override 47 public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { 48 } 49 } }; 50 51 SSLContext sc = SSLContext.getInstance("SSL"); 52 sc.init(null, trustAllCerts, new SecureRandom()); 53 HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); 54 URLConnection con = new URL("https://xtm8000").openConnection(); 55 byte[] b = new byte[8096]; 56 57 StringBuilder sb = new StringBuilder(); 58 InputStream is = con.getInputStream(); 59 while (true) { 60 int readBytes = is.read(b); 61 if (readBytes <= 0) 62 break; 63 64 sb.append(new String(b, 0, readBytes)); 88 TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { 89 @Override 90 public X509Certificate[] getAcceptedIssuers() { 91 return null; 65 92 } 66 93 67 System.out.println("read " + sb.toString().length() + " chars"); 68 } 94 @Override 95 public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 96 } 97 98 @Override 99 public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { 100 } 101 } }; 102 69 103 }
Note: See TracChangeset
for help on using the changeset viewer.
