1

I am using a physical device with android v4.4.2 (Java) with java_websockets and I get this error when attempting to connect to the websocket.

javax.net.ssl.SSLHandshakeException: 
javax.net.ssl.SSLProtocolException: 
SSL handshake aborted: ssl=0x7aa38588: 
Failure in SSL library, usually a protocol error
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:
unknown protocol (external/openssl/ssl/s23_clnt.c:769 0x73a81cfc:0x00000000)

I have found this answer and I tried implementing it but nothing changes. That is where I get the code for NoSSLv3SocketFactory. It goes into the try catch until the last line mWebSocketClient.connect() but it doesn't go into the catch, the onError logs the error.

This is the websocket setup code.

...
String complete = wsBase + ep;
URI uri = new URI(complete);

mWebSocketClient = new WebSocketClient(uri, new Draft_17()) 
{
            @Override
            public void onOpen(ServerHandshake serverHandshake) 
            {
                Log.i("Websocket", "Opened");
            }

            @Override
            public void onMessage(String s) 
            {
                final String message = s;
                runOnUiThread(new Runnable() 
                {
                    @Override
                    public void run() 
                    {
                        Log.i("onMessage", "running");
                    }
                });
            }

            @Override
            public void onClose(int i, String s, boolean b) 
            {
                Log.i("Websocket", "Closed " + s);
            }

            @Override
            public void onError(Exception e) 
            {
                Log.i("Websocket", "Error " + e.getMessage());
            }
        };

        try 
        {
            // Stuff I thought might have fixed it but didn't
            SSLContext sslcontext = SSLContext.getInstance("TLSv1");

            sslcontext.init(null,
                    null,
                    null);
            SSLSocketFactory noSSLv3Factory = new NoSSLv3SocketFactory(sslcontext.getSocketFactory());

            Socket socket = noSSLv3Factory.createSocket(uri.getHost(), 80);
            mWebSocketClient.setSocket(socket);
            mWebSocketClient.connect();
        } 

        catch (Exception e)
        {
            Log.i("Websocket", e.getMessage());
        }
Community
  • 1
  • 1
CookieMonster
  • 492
  • 6
  • 18

1 Answers1

0
        Socket socket = noSSLv3Factory.createSocket(uri.getHost(), 80);

If I understand your code correctly you are trying to connect to a secure WebSocket on port 80. While in theory somebody could setup a server like this it is very unlikely. Port 80 is used for http not https and thus for ws:// and not wss://. Secure Websockets (wss://`) are usually handled on port 443 where also https is done.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
  • For testing purposes, it doesn't matter if it is secure or not. The (internal) server I am connecting to is not secured and is http, not https. – CookieMonster Sep 01 '16 at 17:50
  • In other words, I am just trying achieve any connection at all to work on other things in the app. – CookieMonster Sep 01 '16 at 17:51
  • @CookieMonster: If the internal server is http only you cannot do a secure websocket connection. While I personally have no experience with this library it looks like that there are examples so you should base your experiments on an example which does not use SSL. – Steffen Ullrich Sep 01 '16 at 18:55
  • So all this stuff was an attempted fix for a different issue, turns out in my initial problem was that I was using `SSLSocketFactory` instead of `SocketFactory` to fix yet another issue. Now this error is gone ... back to my initial other problem ... Don't worry about it, thanks though – CookieMonster Sep 01 '16 at 19:04