more advanced make check
[org.ibex.crypto.git] / src / org / ibex / net / ssl / Test.java
index aa43ccb..10e0656 100644 (file)
@@ -6,6 +6,7 @@ import java.io.*;
 public class Test {
     public static void main(String[] args) throws Exception {
         SSL.debugOn = true;
+        if(args.length == 1 && args[0].equals("check")) System.exit(check());
         if(args.length < 2) { System.err.println("Usage: SSL host port"); }
         String host = args[0];
         int port = Integer.parseInt(args[1]);
@@ -21,12 +22,46 @@ public class Test {
         cat(ssl.getInputStream());
         ssl.close();
     }
-    private static void cat(InputStream is) throws IOException {
+    private static void cat(InputStream is) throws IOException { cat(is,100,null); }
+    private static void cat(InputStream is, int count, String check) throws IOException {
         BufferedReader br = new BufferedReader(new InputStreamReader(is));
         String line;
-        int count = 100;
         try {
-            while((line = br.readLine()) != null && --count >= 0) System.out.println(line);
+            while((line = br.readLine()) != null && --count >= 0) {
+                if(check != null) {
+                    if(!line.startsWith(check)) throw new Error("\"" + check + "\" check failed");
+                    check = null;
+                }
+                System.out.println(line);
+            }
         } catch(SSL.PrematureCloseExn e) { /* ignore */ }
     }
+    public static int check() throws Exception {
+        byte[] ciphers = new byte[] {
+            SSL.TLS_RSA_WITH_AES_256_CBC_SHA,SSL.TLS_RSA_WITH_AES_128_CBC_SHA,
+            SSL.SSL_RSA_WITH_RC4_128_SHA,SSL.SSL_RSA_WITH_RC4_128_MD5
+        };
+        String[] hosts = new String[] { 
+            "ssl.brianweb.net", "www.zaks.com", "www.paypal.com", "www99.americanexpress.com", "www.cnbank.com", "gmail.google.com"
+        };
+        int[] blacklisted = new int[] { 0,3,2,3,3,0 };
+        for(int i=0;i<hosts.length;i++) {
+            for(int j=0;j<ciphers.length;j++) {
+                for(int tls=0;tls<2;tls++) {
+                    String host = hosts[i];
+                    byte[] cipherPref = new byte[] {ciphers[j]};
+                    if((blacklisted[i]&(1<<j)) != 0) continue;
+                    if(j<2 && tls==0) continue;
+                    System.err.println("Testing " + host + " with " + Integer.toHexString(ciphers[j]) + " tls: " + (tls==0?"off":"on"));
+                    SSL ssl = new SSL(host,443,false);
+                    ssl.setTLS(tls!=0);
+                    ssl.negotiate(cipherPref);
+                    ssl.getOutputStream().write(SSL.getBytes("GET / HTTP/1.0\r\nHost: " + host + "\r\n\r\n"));
+                    cat(ssl.getInputStream(),5,"HTTP/1.");
+                    ssl.close();
+                }
+            }
+        }
+        return 0;
+    }
 }