Skip to content

Instantly share code, notes, and snippets.

@repomaa repomaa/MainClass.java Secret
Created Sep 17, 2012

Embed
What would you like to do?
...
public static void main(String[] args){
...
MySSLSocketFactory.init();
Field field = SSLSocketFactory.class.getDeclaredFields()[0];
field.setAccessible(true);
try {
field.set(null, new MySSLSocketFactory());
} catch (Exception e) {
}
...
}
...
package logic;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.net.SocketFactory;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
public class MySSLSocketFactory extends SSLSocketFactory {
private static SocketFactory defaultFactory;
private final static String[] protocols = new String[]{"TLSv1"};
@Override
public Socket createSocket(Socket s, String host, int port,
boolean autoClose) throws IOException {
Socket socket = defaultFactory.createSocket(host, port);
((SSLSocket) socket).setEnabledProtocols(protocols);
return socket;
}
@Override
public String[] getDefaultCipherSuites() {
return protocols;
}
@Override
public String[] getSupportedCipherSuites() {
return protocols;
}
@Override
public Socket createSocket(String host, int port) throws IOException,
UnknownHostException {
Socket socket = defaultFactory.createSocket(host, port);
((SSLSocket) socket).setEnabledProtocols(protocols);
return socket;
}
@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
Socket socket = defaultFactory.createSocket(host, port);
((SSLSocket) socket).setEnabledProtocols(protocols);
return socket;
}
@Override
public Socket createSocket(String host, int port, InetAddress localHost,
int localPort) throws IOException, UnknownHostException {
Socket socket = defaultFactory.createSocket(host, port, localHost, localPort);
((SSLSocket) socket).setEnabledProtocols(protocols);
return socket;
}
@Override
public Socket createSocket(InetAddress address, int port,
InetAddress localAddress, int localPort) throws IOException {
Socket socket = defaultFactory.createSocket(address, port, localAddress, localPort);
((SSLSocket) socket).setEnabledProtocols(protocols);
return socket;
}
public static void init() {
defaultFactory = SSLSocketFactory.getDefault();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.