crossbario / autobahn-java

WebSocket & WAMP in Java for Android and Java 8
https://crossbar.io/autobahn
MIT License
1.52k stars 425 forks source link

Allow settings TLS protocols in WebSocket options #374

Open 0xAliHn opened 6 years ago

0xAliHn commented 6 years ago

I am using android API 19 for my project. But as mentioned in the android developer https://developer.android.com/reference/javax/net/ssl/SSLSocket.html documentation TLSv1.2 protocols is not enabled by default in android API <20.

As I am using API 19 and we must need to enable TLSv1.2 for successful handshaking. Currently getting below error: connection close, Notification: 5 reason: WebSockets internal error (javax.net.ssl.SSLException: Read error: ssl=0xb7747000: I/O error during system call, Software caused connection abort)

This can be handled using below implementation in CustomSocketFactory/SocketFactory:

private Socket enableTLSOnSocket(Socket socket) {
        if(socket != null && (socket instanceof SSLSocket)) {
            ((SSLSocket)socket).setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1.2"});
        }
        return socket;
    }

Would you please help us to implement this in your autobahn java library or any API exposure will be appreciated.

oberstet commented 6 years ago

I think best would be to expose knobs for a user to choose the TLS versions desired. Eg some users might opt for "1.2 only" ..

oberstet commented 6 years ago

signatures of the new knobs on WebSocketOptions should mirror SSLSocket :

public void setTLSEnabledProtocols(String[] protocols);
public String[] getTLSEnabledProtocols();