1 23 package org.objectweb.joram.client.jms.tcp; 24 25 import fr.dyade.aaa.util.*; 26 27 import java.io.*; 28 import java.net.*; 29 import java.util.*; 30 31 import java.io.FileInputStream ; 32 import java.security.KeyStore ; 33 import java.security.SecureRandom ; 34 import javax.net.SocketFactory; 35 import javax.net.ssl.KeyManagerFactory; 36 import javax.net.ssl.TrustManagerFactory; 37 import javax.net.ssl.TrustManager; 38 import javax.net.ssl.SSLContext; 39 import javax.jms.*; 40 41 import org.objectweb.joram.client.jms.FactoryParameters; 42 import org.objectweb.joram.shared.JoramTracing; 43 import org.objectweb.util.monolog.api.BasicLevel; 44 45 public class ReliableSSLTcpClient extends ReliableTcpClient { 46 47 private final static String CIPHER = "org.objectweb.joram.cipherList"; 48 private final static String KS = "org.objectweb.joram.keystore"; 49 private final static String KS_PASS = "org.objectweb.joram.keystorepass"; 50 private final static String KS_TYPE = "org.objectweb.joram.keystoretype"; 51 private final static String SSLCONTEXT = "org.objectweb.joram.sslCtx"; 52 53 public ReliableSSLTcpClient() { 54 super(); 55 } 56 57 protected Socket createSocket(String hostName, int port) 58 throws Exception { 59 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 60 JoramTracing.dbgClient.log( 61 BasicLevel.DEBUG, 62 "ReliableSSLTcpClient.createSocket(" + 63 hostName+"," + port + ")"); 64 65 SocketFactory socketFactory = createSocketFactory(); 66 return socketFactory.createSocket(hostName, port); 67 } 68 69 private static SocketFactory createSocketFactory() 70 throws Exception { 71 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 72 JoramTracing.dbgClient.log( 73 BasicLevel.DEBUG, "ReliableSSLTcpClient.createSocketFactory()"); 74 75 char[] keyStorePass = System.getProperty(KS_PASS,"jorampass").toCharArray(); 76 String keystoreFile = System.getProperty(KS,"./joram_ks"); 77 String sslContext = System.getProperty(SSLCONTEXT,"SSL"); 78 String ksType = System.getProperty(KS_TYPE,"JKS"); 79 80 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 81 JoramTracing.dbgClient.log( 82 BasicLevel.DEBUG, "SSLTcpProxyService.createSocketFactory : keystoreFile=" + 83 keystoreFile); 84 85 KeyStore keystore = KeyStore.getInstance(ksType); 86 keystore.load(new FileInputStream (keystoreFile),keyStorePass); 87 88 KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); 89 kmf.init(keystore,keyStorePass); 90 91 TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); 92 tmf.init(keystore); 93 TrustManager[] trustManagers = tmf.getTrustManagers(); 94 95 SSLContext ctx = SSLContext.getInstance(sslContext); 96 SecureRandom securerandom = SecureRandom.getInstance("SHA1PRNG"); 97 ctx.init(kmf.getKeyManagers(),trustManagers,securerandom); 99 100 return (SocketFactory) ctx.getSocketFactory(); 101 } 102 } 103 | Popular Tags |