--- /dev/null
+package mcsClient;
+import java.io.*;
+import java.security.*;
+import java.security.cert.*;
+import java.net.*;
+import javax.net.*;
+import javax.net.ssl.*;
+
+public class Main {
+ private static boolean stop;
+ public static void main(String[] s) throws Exception {
+ if (s.length != 1 || s[0].indexOf('@')==-1) {
+ System.err.println("usage: java -jar mcs.jar <username>@<hostname>");
+ System.exit(-1);
+ }
+
+ final String user = s[0].substring(0, s[0].indexOf('@'));
+ String host = s[0].substring(s[0].indexOf('@')+1);
+ System.out.print("password for "+s[0]+": ");
+
+ stop = false;
+ new Thread() {
+ public void run() {
+ while (!stop) {
+ System.out.print("\010*");
+ try { Thread.currentThread().sleep(1); }
+ catch(InterruptedException ie) { ie.printStackTrace(); }
+ }
+ }
+ }.start();
+ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+ final String password = in.readLine();
+ stop = true;
+ System.out.println();
+
+ Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
+ TrustManager[] trustAllCerts = new TrustManager[] {
+ new X509TrustManager() {
+ public X509Certificate[] getAcceptedIssuers() { return null; }
+ public void checkServerTrusted(X509Certificate[] certs, String authType)
+ throws CertificateException { return; }
+ public void checkClientTrusted(X509Certificate[] certs, String authType)
+ throws CertificateException { return; }
+ }
+ };
+ SSLContext sc = SSLContext.getInstance("SSL");
+ sc.init(null, trustAllCerts, new SecureRandom());
+ HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
+ HostnameVerifier hv = new HostnameVerifier() {
+ public boolean verify(String urlHostName, SSLSession session) {
+ return true; } };
+ HttpsURLConnection.setDefaultHostnameVerifier(hv);
+
+ Authenticator.setDefault(new Authenticator() {
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication (user, password.toCharArray());
+ }
+ });
+
+ BufferedReader br;
+ HttpURLConnection con;
+
+ System.out.println();
+ System.out.println();
+ System.out.println("*** requesting welcome.ssi...");
+ con = (HttpURLConnection)new URL("https://"+host+"/private/welcome.ssi").openConnection();
+ ((HttpsURLConnection)con).setHostnameVerifier(new HostnameVerifier() {
+ public boolean verify(String hostname, SSLSession session) { return true; } });
+ br = new BufferedReader(new InputStreamReader(con.getInputStream()));
+ for(String ss = br.readLine(); ss!=null; ss=br.readLine())
+ System.err.println(ss);
+
+ String token = null;
+ System.out.println();
+ System.out.println();
+ System.out.println("*** requesting rc_frame.ssi...");
+ con = (HttpURLConnection)new URL("https://"+host+"/private/rc_frame.ssi").openConnection();
+ ((HttpsURLConnection)con).setHostnameVerifier(new HostnameVerifier() {
+ public boolean verify(String hostname, SSLSession session) { return true; } });
+ br = new BufferedReader(new InputStreamReader(con.getInputStream()));
+ for(String ss = br.readLine(); ss!=null; ss=br.readLine()) {
+ System.err.println(ss);
+ if (ss.startsWith("ac =\"")) {
+ ss = ss.substring(5).trim();
+ while(ss.charAt(ss.length()-1)=='\"')
+ ss = ss.substring(0, ss.length()-1);
+ token = ss;
+ }
+ }
+
+ System.out.println();
+ System.out.println();
+ if (token!=null)
+ McsClient.go(host, user, token);
+ }
+}