java javax.net.ssl.SSLException:连接由 4.4.2 设备上的对等方关闭(适用于 6.0.1)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36888852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javax.net.ssl.SSLException: Connection closed by peer on 4.4.2 device (works on 6.0.1)
提问by robigroza
I have a problem with getting this error when I'm performing sync on my app. Main problem is that same code works on Android 6.0.1 device, but on 4.4.2 device, I'm getting this error:
当我在我的应用程序上执行同步时,我遇到了这个错误的问题。主要问题是相同的代码适用于 Android 6.0.1 设备,但在 4.4.2 设备上,我收到此错误:
javax.net.ssl.SSLException: Connection closed by peer
at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:406)
at okhttp3.internal.io.RealConnection.connectTls(RealConnection.java:188)
at okhttp3.internal.io.RealConnection.connectSocket(RealConnection.java:145)
at okhttp3.internal.io.RealConnection.connect(RealConnection.java:108)
at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:188)
at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:127)
at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:289)
at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:241)
at okhttp3.RealCall.getResponse(RealCall.java:240)
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
at okhttp3.RealCall.access0(RealCall.java:30)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
where I'm unable to request data from server.
我无法从服务器请求数据的地方。
If you need more data, feel free to ask. Thanks.
如果您需要更多数据,请随时询问。谢谢。
采纳答案by robigroza
Key here is to force TLS 1.2 protocol, based on thislink here.
这里的关键是根据这里的链接强制使用 TLS 1.2 协议。
Only thing that I needed to correct here is to force TLS 1.2 protocol directly, like this:
我唯一需要在这里更正的是直接强制使用 TLS 1.2 协议,如下所示:
private class NoSSLv3SSLSocket extends DelegateSSLSocket {
private NoSSLv3SSLSocket(SSLSocket delegate) {
super(delegate);
}
@Override
public void setEnabledProtocols(String[] protocols) {
super.setEnabledProtocols(new String[]{"TLSv1.2"}); // force to use only TLSv1.2 here
}
}