initial import
[org.ibex.crypto.git] / src / org / ibex / net / ssl / Test.java
1 package org.ibex.net.ssl;
2
3 import org.ibex.net.SSL;
4 import java.io.*;
5
6 public class Test {
7     public static void main(String[] args) throws Exception {
8         SSL.debugOn = true;
9         if(args.length < 2) { System.err.println("Usage: SSL host port"); }
10         String host = args[0];
11         int port = Integer.parseInt(args[1]);
12         SSL ssl = new SSL(host,port);
13         //ssl.setTLS(false);
14         ssl.getOutputStream().write(SSL.getBytes("GET / HTTP/1.0\r\nHost: " + host + "\r\n\r\n"));
15         cat(ssl.getInputStream());
16         ssl.close();
17         
18         // try to resume
19         ssl = new SSL(host,port,ssl.getSessionState());
20         ssl.getOutputStream().write(SSL.getBytes("GET / HTTP/1.0\r\nHost: " + host + "\r\n\r\n"));
21         cat(ssl.getInputStream());
22         ssl.close();
23     }
24     private static void cat(InputStream is) throws IOException {
25         BufferedReader br = new BufferedReader(new InputStreamReader(is));
26         String line;
27         int count = 100;
28         try {
29             while((line = br.readLine()) != null && --count >= 0) System.out.println(line);
30         } catch(SSL.PrematureCloseExn e) { /* ignore */ }
31     }
32 }