import java.io.*;importjava.net.UnknownHostException;import java.security.*;import java.security.cert.*;import java.util.*;import javax.net.ssl.*;importjavax.security.cert.X509Certificate;import org.bouncycastle.crypto.tls.*;importorg.bouncycastle.jce.provider.BouncyCastleProvider;public class TLSSocketConnectionFactory extendsSSLSocketFactory {static{if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
Security.addProvider(newBouncyCastleProvider());
}
}
@Overridepublic Socket createSocket(Socket socket, final String host, intport,boolean arg3) throwsIOException {if (socket == null) {
socket= newSocket();
}if (!socket.isConnected()) {
socket.connect(newInetSocketAddress(host, port));
}final TlsClientProtocol tlsClientProtocol = new TlsClientProtocol(socket.getInputStream(), socket.getOutputStream(), newSecureRandom());return_createSSLSocket(host, tlsClientProtocol);
}
@Overridepublic String[] getDefaultCipherSuites() { return null; }
@Overridepublic String[] getSupportedCipherSuites() { return null; }
@Overridepublic Socket createSocket(String host, int port) throws IOException, UnknownHostException { throw newUnsupportedOperationException(); }
@Overridepublic Socket createSocket(InetAddress host, int port) throws IOException { throw newUnsupportedOperationException(); }
@Overridepublic Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException { return null; }
@Overridepublic Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { throw newUnsupportedOperationException(); }private SSLSocket _createSSLSocket(final String host, finalTlsClientProtocol tlsClientProtocol) {return newSSL