1 6 package org.jfox.ioc.connector.jrmps; 7 8 import java.io.IOException ; 9 import java.io.Serializable ; 10 import java.net.ServerSocket ; 11 import java.rmi.server.RMIServerSocketFactory ; 12 import java.security.KeyStore ; 13 import javax.net.ssl.KeyManagerFactory; 14 import javax.net.ssl.SSLContext; 15 16 19 20 public class JRMPSServerSocketFactory implements RMIServerSocketFactory , Serializable { 21 private String SSLKeyFile = "jfox.keystore"; 22 private String password = "jfox.org"; 23 24 public JRMPSServerSocketFactory(String SSLKeyFile, String password) { 25 this.SSLKeyFile = SSLKeyFile; 26 this.password = password; 27 } 28 29 public ServerSocket createServerSocket(int port) throws IOException { 30 try { 31 KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); 32 keyStore.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(SSLKeyFile), password.toCharArray()); 33 KeyManagerFactory keyMgr = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); 34 keyMgr.init(keyStore, password.toCharArray()); 35 36 39 SSLContext sslCtx = SSLContext.getInstance("TLS"); 40 sslCtx.init(keyMgr.getKeyManagers(), null, null); 41 return sslCtx.getServerSocketFactory().createServerSocket(port); 42 } 43 catch(Exception e) { 44 e.printStackTrace(); 45 return null; 46 } 47 } 48 49 public static void main(String [] args) { 50 51 } 52 } 53 54 | Popular Tags |