-
-
Save repomaa/30deb679a298ae4333f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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) { | |
} | |
... | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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