2 // Copyright (C) 2002 Constantin Kaplinsky, Inc. All Rights Reserved.
3 // Copyright 2007 MIT Student Information Processing Board
5 // This is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This software is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this software; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // VNCProxyConnectSocketFactory.java together with VNCProxyConnectSocket.java
23 // implement an alternate way to connect to VNC servers via one or two
24 // VNCProxy proxies supporting the VNCProxy CONNECT method.
29 import javax.net.ssl.*;
32 class VNCProxyConnectSocketFactory implements SocketFactory {
34 SSLSocketFactory factory;
36 public VNCProxyConnectSocketFactory() {
38 SSLContext c = SSLContext.getInstance("SSL");
40 new TrustManager[] { new SIPBTrustManager() },
43 (SSLSocketFactory)c.getSocketFactory();
44 } catch (Exception e) {
49 public Socket createSocket(String host, int port, Applet applet)
52 return createSocket(host, port,
53 applet.getParameter("VMNAME"),
54 applet.getParameter("AUTHTOKEN"));
57 public Socket createSocket(String host, int port, String[] args)
60 return createSocket(host, port,
61 readArg(args, "VMNAME"),
62 readArg(args, "AUTHTOKEN"));
65 public Socket createSocket(String host, int port,
66 String vmname, String authtoken)
69 if (vmname == null || authtoken == null) {
70 System.out.println("Incomplete parameter list for VNCProxyConnectSocket");
71 return new Socket(host, port);
74 System.out.println("VNCProxy CONNECT via proxy " + host +
75 " port " + port + " to vm " + vmname);
76 SSLSocket ssls = (SSLSocket)factory.createSocket(host, port);
77 ssls.startHandshake();
78 VNCProxyConnectSocketWrapper s =
79 new VNCProxyConnectSocketWrapper(ssls, vmname, authtoken);
84 private String readArg(String[] args, String name) {
86 for (int i = 0; i < args.length; i += 2) {
87 if (args[i].equalsIgnoreCase(name)) {
90 } catch (Exception e) {