3 import java.security.*;
4 import java.security.cert.*;
7 import javax.net.ssl.*;
10 private static boolean stop;
11 public static void main(String[] s) throws Exception {
12 if (s.length != 1 || s[0].indexOf('@')==-1) {
13 System.err.println("usage: java -jar mcs.jar <username>@<hostname>");
17 final String user = s[0].substring(0, s[0].indexOf('@'));
18 String host = s[0].substring(s[0].indexOf('@')+1);
19 System.out.print("password for "+s[0]+": ");
25 System.out.print("\010*");
26 try { Thread.currentThread().sleep(1); }
27 catch(InterruptedException ie) { ie.printStackTrace(); }
31 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
32 final String password = in.readLine();
36 Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
37 TrustManager[] trustAllCerts = new TrustManager[] {
38 new X509TrustManager() {
39 public X509Certificate[] getAcceptedIssuers() { return null; }
40 public void checkServerTrusted(X509Certificate[] certs, String authType)
41 throws CertificateException { return; }
42 public void checkClientTrusted(X509Certificate[] certs, String authType)
43 throws CertificateException { return; }
46 SSLContext sc = SSLContext.getInstance("SSL");
47 sc.init(null, trustAllCerts, new SecureRandom());
48 HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
49 HostnameVerifier hv = new HostnameVerifier() {
50 public boolean verify(String urlHostName, SSLSession session) {
52 HttpsURLConnection.setDefaultHostnameVerifier(hv);
54 Authenticator.setDefault(new Authenticator() {
55 protected PasswordAuthentication getPasswordAuthentication() {
56 return new PasswordAuthentication (user, password.toCharArray());
61 HttpURLConnection con;
65 System.out.println("*** requesting welcome.ssi...");
66 con = (HttpURLConnection)new URL("https://"+host+"/private/welcome.ssi").openConnection();
67 ((HttpsURLConnection)con).setHostnameVerifier(new HostnameVerifier() {
68 public boolean verify(String hostname, SSLSession session) { return true; } });
69 br = new BufferedReader(new InputStreamReader(con.getInputStream()));
70 for(String ss = br.readLine(); ss!=null; ss=br.readLine())
71 System.err.println(ss);
76 System.out.println("*** requesting rc_frame.ssi...");
77 con = (HttpURLConnection)new URL("https://"+host+"/private/rc_frame.ssi").openConnection();
78 ((HttpsURLConnection)con).setHostnameVerifier(new HostnameVerifier() {
79 public boolean verify(String hostname, SSLSession session) { return true; } });
80 br = new BufferedReader(new InputStreamReader(con.getInputStream()));
81 for(String ss = br.readLine(); ss!=null; ss=br.readLine()) {
82 System.err.println(ss);
83 if (ss.startsWith("ac =\"")) {
84 ss = ss.substring(5).trim();
85 while(ss.charAt(ss.length()-1)=='\"')
86 ss = ss.substring(0, ss.length()-1);
94 McsClient.go(host, user, token);