javax.net.ssl.SSLException:4.4.2设备上的peer关闭连接(适用于6.0.1) [英] javax.net.ssl.SSLException: Connection closed by peer on 4.4.2 device (works on 6.0.1)

查看:148
本文介绍了javax.net.ssl.SSLException:4.4.2设备上的peer关闭连接(适用于6.0.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在我的应用上执行同步时遇到此错误有问题。主要问题是相同的代码适用于Android 6.0.1设备,但在4.4.2设备上,我收到此错误:

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:

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.access$100(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.

推荐答案

这里的关键是强制TLS 1.2协议,基于这个链接在这里。

Key here is to force TLS 1.2 protocol, based on this link here.

只有我需要的东西在这里更正是直接强制TLS 1.2协议,如下所示:

Only thing that I needed to correct here is to force TLS 1.2 protocol directly, like this:

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
    }
}

这篇关于javax.net.ssl.SSLException:4.4.2设备上的peer关闭连接(适用于6.0.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆