package com.dwave.rmi.ssl; /* * RMISSLClientSocketFactory * * Copyright (C) 2000 D-Wave Systems Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.io.*; import java.net.*; import java.rmi.server.*; import javax.net.ssl.*; import com.sun.net.ssl.*; import java.util.Properties; import com.sun.net.ssl.internal.ssl.*; /** * RMISSLClientSocketFactory * * @author Michael Coury * @version 1.0, 10/06/2000 */ public class RMISSLClientSocketFactory implements RMIClientSocketFactory, Serializable { SSLSocket socket=null; boolean completed=false; public Socket createSocket(String host, int port) throws IOException { try { System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol"); java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); SSLContext ctx; KeyManagerFactory kmf; ctx = SSLContext.getInstance("TLS"); kmf = KeyManagerFactory.getInstance("SunX509"); kmf.init(null,null); ctx.init(kmf.getKeyManagers(), null, null); SSLSocketFactory factory = (SSLSocketFactory) ctx.getSocketFactory(); socket = (SSLSocket)factory.createSocket(host, port); String[] suites = socket.getSupportedCipherSuites(); socket.setEnabledCipherSuites(suites); socket.addHandshakeCompletedListener(new HandshakeCompletedListener() { public void handshakeCompleted(HandshakeCompletedEvent hce) { completed=true; } }); SSLSession session = socket.getSession(); while(!completed); socket.setSoLinger(true, 600); } catch(Exception e) { e.printStackTrace(); } return socket; } }