From 3399ca2619a6bbb0721e63597e1aa78237e2dd42 Mon Sep 17 00:00:00 2001 From: Gideon le Grange Date: Sun, 3 Jan 2016 20:43:02 +0200 Subject: [PATCH] Created working Anonymous TLS example --- src/main/java/examples/AnonymousSocketFactory.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/examples/AnonymousSocketFactory.java b/src/main/java/examples/AnonymousSocketFactory.java index 45eeab8..d7bc1f3 100644 --- a/src/main/java/examples/AnonymousSocketFactory.java +++ b/src/main/java/examples/AnonymousSocketFactory.java @@ -32,6 +32,11 @@ import javax.net.ssl.SSLSocketFactory; */ public class AnonymousSocketFactory extends SocketFactory { + @Override + public Socket createSocket() throws IOException { + return fixSocket((SSLSocket) SSLSocketFactory.getDefault().createSocket()); + } + @Override public Socket createSocket(String host, int port) throws IOException, UnknownHostException { 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 { return fixSocket((SSLSocket) SSLSocketFactory.getDefault().createSocket(address, port, localAddress, localPort)); } - + private Socket fixSocket(SSLSocket ssl) { List cs = new LinkedList<>(); // 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[]{})); - return ssl; + return ssl; } public static SocketFactory getDefault() {