1 package org.ibex.net.ssl;
3 import org.ibex.net.SSL;
7 public static void main(String[] args) throws Exception {
9 if(args.length == 1 && args[0].equals("check")) System.exit(check());
10 if(args.length < 2) { System.err.println("Usage: SSL host port"); }
11 String host = args[0];
12 int port = Integer.parseInt(args[1]);
13 SSL ssl = new SSL(host,port);
15 ssl.getOutputStream().write(SSL.getBytes("GET / HTTP/1.0\r\nHost: " + host + "\r\n\r\n"));
16 cat(ssl.getInputStream());
20 ssl = new SSL(host,port,ssl.getSessionState());
21 ssl.getOutputStream().write(SSL.getBytes("GET / HTTP/1.0\r\nHost: " + host + "\r\n\r\n"));
22 cat(ssl.getInputStream());
25 private static void cat(InputStream is) throws IOException { cat(is,100,null); }
26 private static void cat(InputStream is, int count, String check) throws IOException {
27 BufferedReader br = new BufferedReader(new InputStreamReader(is));
30 while((line = br.readLine()) != null && --count >= 0) {
32 if(!line.startsWith(check)) throw new Error("\"" + check + "\" check failed");
35 System.out.println(line);
37 } catch(SSL.PrematureCloseExn e) { /* ignore */ }
39 public static int check() throws Exception {
40 byte[] ciphers = new byte[] {
41 SSL.TLS_RSA_WITH_AES_256_CBC_SHA,SSL.TLS_RSA_WITH_AES_128_CBC_SHA,
42 SSL.SSL_RSA_WITH_RC4_128_SHA,SSL.SSL_RSA_WITH_RC4_128_MD5
44 String[] hosts = new String[] {
45 "ssl.brianweb.net", "www.zaks.com", "www.paypal.com", "www99.americanexpress.com", "www.cnbank.com", "gmail.google.com"
47 int[] blacklisted = new int[] { 0,3,2,3,3,0 };
48 for(int i=0;i<hosts.length;i++) {
49 for(int j=0;j<ciphers.length;j++) {
50 for(int tls=0;tls<2;tls++) {
51 String host = hosts[i];
52 byte[] cipherPref = new byte[] {ciphers[j]};
53 if((blacklisted[i]&(1<<j)) != 0) continue;
54 if(j<2 && tls==0) continue;
55 System.err.println("Testing " + host + " with " + Integer.toHexString(ciphers[j]) + " tls: " + (tls==0?"off":"on"));
56 SSL ssl = new SSL(host,443,false);
58 ssl.negotiate(cipherPref);
59 ssl.getOutputStream().write(SSL.getBytes("GET / HTTP/1.0\r\nHost: " + host + "\r\n\r\n"));
60 cat(ssl.getInputStream(),5,"HTTP/1.");