1 11 12 package org.jivesoftware.messenger.net; 13 14 import org.jivesoftware.util.Log; 15 16 import javax.net.ssl.KeyManagerFactory; 17 import javax.net.ssl.SSLContext; 18 import javax.net.ssl.SSLServerSocketFactory; 19 import javax.net.ssl.TrustManagerFactory; 20 import java.io.IOException ; 21 import java.net.InetAddress ; 22 import java.net.ServerSocket ; 23 import java.security.KeyStore ; 24 25 31 public class SSLJiveServerSocketFactory extends SSLServerSocketFactory { 32 33 public static SSLServerSocketFactory getInstance(String algorithm, 34 KeyStore keystore, 35 KeyStore truststore) throws 36 IOException { 37 38 try { 39 SSLContext sslcontext = SSLContext.getInstance(algorithm); 40 SSLServerSocketFactory factory; 41 KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); 42 keyFactory.init(keystore, SSLConfig.getKeyPassword().toCharArray()); 43 TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 44 trustFactory.init(truststore); 45 46 sslcontext.init(keyFactory.getKeyManagers(), 47 trustFactory.getTrustManagers(), 48 new java.security.SecureRandom ()); 49 factory = sslcontext.getServerSocketFactory(); 50 return new SSLJiveServerSocketFactory(factory); 51 } 52 catch (Exception e) { 53 Log.error(e); 54 throw new IOException (e.getMessage()); 55 } 56 } 57 58 private SSLServerSocketFactory factory; 59 60 private SSLJiveServerSocketFactory(SSLServerSocketFactory factory) { 61 this.factory = factory; 62 } 63 64 public ServerSocket createServerSocket(int i) throws IOException { 65 return factory.createServerSocket(i); 66 } 67 68 public ServerSocket createServerSocket(int i, int i1) throws IOException { 69 return factory.createServerSocket(i, i1); 70 } 71 72 public ServerSocket createServerSocket(int i, int i1, InetAddress inetAddress) throws IOException { 73 return factory.createServerSocket(i, i1, inetAddress); 74 } 75 76 public String [] getDefaultCipherSuites() { 77 return factory.getDefaultCipherSuites(); 78 } 79 80 public String [] getSupportedCipherSuites() { 81 return factory.getSupportedCipherSuites(); 82 } 83 } 84 | Popular Tags |