SSL握手异常:SSL库中的失败,通常是协议错误 [英] SSL Handshake Excetion : Failure in SSL library, usually a protocol error
问题描述
我正在使用带有android v4.4.2(Java)的物理设备和 java_websockets 和尝试连接到websocket时出现此错误。
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)
我找到了这个答案我尝试实施但没有任何变化。这就是我得到 NoSSLv3SocketFactory
的代码。它进入try catch直到最后一行 mWebSocketClient.connect()
但它没有进入catch, onError
记录错误。
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.
这是websocket设置代码。
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());
}
推荐答案
Socket socket = noSSLv3Factory.createSocket(uri.getHost(), 80);
如果我正确理解你的代码你正试图连接到在端口80上保护WebSocket。虽然理论上有人可以设置这样的服务器,但这是不太可能的。端口80用于http而不是https,因此用于 ws://
而不是 wss://。安全Websockets(
wss://`)通常在端口443上处理,其中也完成了https。
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.
这篇关于SSL握手异常:SSL库中的失败,通常是协议错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!