Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
VNCProxyConnectSocketFactory.java in package_tags/sipb-xen-vnc-client/1/code – xvm Please file new bugs on Launchpad: Invirt or XVM (if you're not sure which, just pick one) Search: Login Help/Guide About Trac Preferences Wiki Timeline Roadmap Browse Source View Tickets Search Context Navigation ← Previous Revision Latest Revision Next Revision → Blame Revision Log source: package_tags/sipb-xen-vnc-client/1/code/VNCProxyConnectSocketFactory.java @ 736 View diff against: View revision: Visit: trunkbranches/wsgi Last change on this file since 736 was 143, checked in by quentin, 16 years ago SSL support for VNC proxy File size: 2.8 KB Line   1 // 2 //  Copyright (C) 2002 Constantin Kaplinsky, Inc.  All Rights Reserved. 3 //  Copyright 2007 MIT Student Information Processing Board 4 // 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. 9 // 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. 14 // 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, 18 //  USA. 19 // 20 21 // 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. 25 // 26 27 import java.applet.*; 28 import java.net.*; 29 import javax.net.ssl.*; 30 import java.io.*; 31 32 class VNCProxyConnectSocketFactory implements SocketFactory { 33 34     SSLSocketFactory factory; 35     36     public VNCProxyConnectSocketFactory() { 37         try { 38             SSLContext c = SSLContext.getInstance("SSL"); 39             c.init(null, 40                    new TrustManager[] { new SIPBTrustManager() }, 41                    null); 42             factory = 43                 (SSLSocketFactory)c.getSocketFactory(); 44         } catch (Exception e) { 45             e.printStackTrace(); 46         } 47     } 48 49   public Socket createSocket(String host, int port, Applet applet) 50     throws IOException { 51 52     return createSocket(host, port, 53                         applet.getParameter("VMNAME"), 54                         applet.getParameter("AUTHTOKEN")); 55   } 56 57   public Socket createSocket(String host, int port, String[] args) 58     throws IOException { 59 60     return createSocket(host, port, 61                         readArg(args, "VMNAME"), 62                         readArg(args, "AUTHTOKEN")); 63   } 64 65   public Socket createSocket(String host, int port, 66                              String vmname, String authtoken) 67     throws IOException { 68 69     if (vmname == null || authtoken == null) { 70       System.out.println("Incomplete parameter list for VNCProxyConnectSocket"); 71       return new Socket(host, port); 72     } 73 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); 80 81     return (Socket)s; 82   } 83 84   private String readArg(String[] args, String name) { 85 86     for (int i = 0; i < args.length; i += 2) { 87       if (args[i].equalsIgnoreCase(name)) { 88         try { 89           return args[i+1]; 90         } catch (Exception e) { 91           return null; 92         } 93       } 94     } 95     return null; 96   } 97 } 98 Note: See TracBrowser for help on using the repository browser. Download in other formats: Plain Text Original Format Powered by Trac 1.0.2 By Edgewall Software. Visit the Trac open source project at http://trac.edgewall.org/