SSL support for VNC proxy
[invirt/packages/invirt-vnc-client.git] / VNCProxyConnectSocketFactory.java
index c0386f1..d05fcf6 100644 (file)
 
 import java.applet.*;
 import java.net.*;
+import javax.net.ssl.*;
 import java.io.*;
 
 class VNCProxyConnectSocketFactory implements SocketFactory {
 
+    SSLSocketFactory factory;
+    
+    public VNCProxyConnectSocketFactory() {
+       try {
+           SSLContext c = SSLContext.getInstance("SSL");
+           c.init(null,
+                  new TrustManager[] { new SIPBTrustManager() },
+                  null);
+           factory =
+               (SSLSocketFactory)c.getSocketFactory();
+       } catch (Exception e) {
+           e.printStackTrace();
+       }
+    }
+
   public Socket createSocket(String host, int port, Applet applet)
     throws IOException {
 
@@ -57,8 +73,10 @@ class VNCProxyConnectSocketFactory implements SocketFactory {
 
     System.out.println("VNCProxy CONNECT via proxy " + host +
                       " port " + port + " to vm " + vmname);
-    VNCProxyConnectSocket s =
-      new VNCProxyConnectSocket(host, port, vmname, authtoken);
+    SSLSocket ssls = (SSLSocket)factory.createSocket(host, port);
+    ssls.startHandshake();
+    VNCProxyConnectSocketWrapper s =
+      new VNCProxyConnectSocketWrapper(ssls, vmname, authtoken);
 
     return (Socket)s;
   }