问题
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());
}
回答1:
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.
来源:https://stackoverflow.com/questions/39275309/ssl-handshake-excetion-failure-in-ssl-library-usually-a-protocol-error