1 package org.objectweb.celtix.bus.transports.https; 2 3 4 import java.io.IOException ; 5 import java.net.InetAddress ; 6 import java.net.Socket ; 7 import java.net.UnknownHostException ; 8 import java.util.logging.Handler ; 9 import java.util.logging.Level ; 10 import java.util.logging.Logger ; 11 12 import javax.net.ssl.SSLSocket; 13 import javax.net.ssl.SSLSocketFactory; 14 15 import org.objectweb.celtix.common.logging.LogUtils; 16 17 class SSLSocketFactoryWrapper extends SSLSocketFactory { 18 19 private static final Logger LOG = LogUtils.getL7dLogger(SSLSocketFactoryWrapper.class); 20 21 private SSLSocketFactory sslSocketFactory; 22 private String [] ciphers; 23 24 public SSLSocketFactoryWrapper(SSLSocketFactory sslSocketFactoryParam, String [] ciphersParam) { 25 sslSocketFactory = sslSocketFactoryParam; 26 ciphers = ciphersParam; 27 } 28 29 30 public String [] getDefaultCipherSuites() { 31 return sslSocketFactory.getDefaultCipherSuites(); 32 } 33 34 public String [] getSupportedCipherSuites() { 35 return sslSocketFactory.getSupportedCipherSuites(); 36 } 37 38 public Socket createSocket(Socket s, String host, int port, boolean autoClose) 39 throws IOException , UnknownHostException { 40 41 SSLSocket socket = null; 42 socket = (SSLSocket)sslSocketFactory.createSocket(s, host, port, autoClose); 43 if ((socket != null) && (ciphers != null)) { 44 socket.setEnabledCipherSuites(ciphers); 45 } 46 47 return socket; 48 } 49 50 public Socket createSocket(String host, int port) throws IOException , UnknownHostException { 51 SSLSocket socket = null; 52 socket = (SSLSocket)sslSocketFactory.createSocket(host, port); 53 if ((socket != null) && (ciphers != null)) { 54 socket.setEnabledCipherSuites(ciphers); 55 } 56 if (socket == null) { 57 LogUtils.log(LOG, Level.SEVERE, "PROBLEM_CREATING_OUTBOUND_REQUEST_SOCKET", 58 new Object []{host, port}); 59 } 60 return socket; 61 } 62 63 64 public Socket createSocket(String host, int port, InetAddress localHost, int localPort) 65 throws IOException , UnknownHostException { 66 SSLSocket socket = null; 67 socket = (SSLSocket)sslSocketFactory.createSocket(host, port, localHost, localPort); 68 if ((socket != null) && (ciphers != null)) { 69 socket.setEnabledCipherSuites(ciphers); 70 } 71 72 if (socket == null) { 73 LogUtils.log(LOG, Level.SEVERE, "PROBLEM_CREATING_OUTBOUND_REQUEST_SOCKET", 74 new Object []{host, port}); 75 } 76 return socket; 77 } 78 79 80 public Socket createSocket(InetAddress host, int port) throws IOException { 81 SSLSocket socket = null; 82 socket = (SSLSocket)sslSocketFactory.createSocket(host, port); 83 if ((socket != null) && (ciphers != null)) { 84 socket.setEnabledCipherSuites(ciphers); 85 } 86 87 if (socket == null) { 88 LogUtils.log(LOG, Level.SEVERE, "PROBLEM_CREATING_OUTBOUND_REQUEST_SOCKET", 89 new Object []{host, port}); 90 } 91 return socket; 92 } 93 94 95 public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) 96 throws IOException { 97 SSLSocket socket = null; 98 socket = (SSLSocket)sslSocketFactory.createSocket(address, port, localAddress, localPort); 99 if ((socket != null) && (ciphers != null)) { 100 socket.setEnabledCipherSuites(ciphers); 101 } 102 103 if (socket == null) { 104 LogUtils.log(LOG, Level.SEVERE, "PROBLEM_CREATING_OUTBOUND_REQUEST_SOCKET", 105 new Object []{address, port}); 106 } 107 return socket; 108 } 109 110 113 protected void addLogHandler(Handler handler) { 114 LOG.addHandler(handler); 115 } 116 } | Popular Tags |