Lollipop 上的握手失败 [英] Handshake fail on Lollipop
问题描述
我正在尝试执行 HTTP POST,但出现两个不同的错误:
I'm trying to do a HTTP POST but I get two different errors:
javax.net.ssl.SSLHandshakeException: Handshake failed
net.ssl.SSLPeerUnverifiedException: No peer certificate
我通过此处指定的解决方法修复了无对等证书错误:https://stackoverflow.com/a/4837230/4254419
I fixed the No peer certificate error through a workaround as specified here: https://stackoverflow.com/a/4837230/4254419
虽然修复了错误,但它会抛出一个新错误,即握手失败
but while that fixes the error, it throws a new error instead, which is Handshake failed
我知道它不安全,我不在乎,它不适用于生产,所以我不太关心安全性.是否有解决此问题的方法?
I know it's not safe and I don't care, it's not for production so I care less about security. Is there a fix for this issue?
推荐答案
我遇到了同样的问题.我找到了一个链接 https://code.google.com/p/android/issues/detail?id=88313 在那里我找到了一个代码:
I had the same problem. I found a link https://code.google.com/p/android/issues/detail?id=88313 where I found a code:
public class MySSLSocketFactory extends SSLSocketFactory {
SSLContext sslContext = SSLContext.getInstance("TLS");
...
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
final SSLSocket sslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
sslSocket.setEnabledCipherSuites(sslSocket.getSupportedCipherSuites());
return sslSocket;
}
@Override
public Socket createSocket() throws IOException {
final SSLSocket sslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket();
sslSocket.setEnabledCipherSuites(sslSocket.getSupportedCipherSuites());
return sslSocket;
}
}
您可以使用您提供的链接中的 MySSLSocketFactory
代码,但您需要覆盖我上面写的两个方法 createSocket
.这也不是最好的解决方案,您以后可能会遇到一些安全问题,因为对于连接,它可以使用一些旧的密码算法.
You can use code of MySSLSocketFactory
from the link you've provided but you need to override two methods createSocket
as I've wrote above.
Also it's not the best solution you can have some security issue later, because for connection it can use some old cipher algorithm.
希望这会有所帮助.
这篇关于Lollipop 上的握手失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!