Created working Anonymous TLS example
This commit is contained in:
parent
3ea5b1ec06
commit
3399ca2619
|
|
@ -32,6 +32,11 @@ import javax.net.ssl.SSLSocketFactory;
|
||||||
*/
|
*/
|
||||||
public class AnonymousSocketFactory extends SocketFactory {
|
public class AnonymousSocketFactory extends SocketFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Socket createSocket() throws IOException {
|
||||||
|
return fixSocket((SSLSocket) SSLSocketFactory.getDefault().createSocket());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
|
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
|
||||||
return fixSocket((SSLSocket) SSLSocketFactory.getDefault().createSocket(host, port));
|
return fixSocket((SSLSocket) SSLSocketFactory.getDefault().createSocket(host, port));
|
||||||
|
|
@ -51,7 +56,7 @@ public class AnonymousSocketFactory extends SocketFactory {
|
||||||
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
|
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
|
||||||
return fixSocket((SSLSocket) SSLSocketFactory.getDefault().createSocket(address, port, localAddress, localPort));
|
return fixSocket((SSLSocket) SSLSocketFactory.getDefault().createSocket(address, port, localAddress, localPort));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Socket fixSocket(SSLSocket ssl) {
|
private Socket fixSocket(SSLSocket ssl) {
|
||||||
List<String> cs = new LinkedList<>();
|
List<String> cs = new LinkedList<>();
|
||||||
// not happy with this code. Without it, SSL throws a "Remote host closed connection during handshake" error
|
// not happy with this code. Without it, SSL throws a "Remote host closed connection during handshake" error
|
||||||
|
|
@ -62,7 +67,7 @@ public class AnonymousSocketFactory extends SocketFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ssl.setEnabledCipherSuites(cs.toArray(new String[]{}));
|
ssl.setEnabledCipherSuites(cs.toArray(new String[]{}));
|
||||||
return ssl;
|
return ssl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SocketFactory getDefault() {
|
public static SocketFactory getDefault() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue