获取javax.net.ssl.SSLHandshakeException:在Android 5.0.2中由peer关闭连接 [英] Getting javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0.2
问题描述
首先,我已经搜索了互联网并且已经调试了3天。
First, I've already searched the internet and have been debugging for 3 days.
这是确切的错误,
javax.net.ssl.SSLHandshakeException: Connection closed by peer
at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:302)
at com.android.okhttp.Connection.upgradeToTls(Connection.java:197)
at com.android.okhttp.Connection.connect(Connection.java:151)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:208)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
at com.aws.wiremo.common.CommonFunctions.sendRequestEx(CommonFunctions.java:618)
at com.aws.wiremo.common.CommonFunctions.sendRequest(CommonFunctions.java:556)
at com.aws.wiremo.screen.kdo.LoadingScreen$MakeRequest.doInBackground(LoadingScreen.java:146)
at com.aws.wiremo.screen.kdo.LoadingScreen$MakeRequest.doInBackground(LoadingScreen.java:125)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
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:818)
由于保密原因,我无法发布代码。
没有由StackTrace给出的异常引起的,所以我无法真正诊断出问题。
以下是我可以分享的一些信息。
Due to confidentiality reasons, I can't post the codes.
There's no caused by exception given by the StackTrace so i can't really diagnose the problem.
Here are some information I can share.
- 请求被发送到< a href =https:// [IP_address]:443 / =nofollow noreferrer> https:// [IP_address]:443 /
- 我发送对特殊硬件的请求,如控制盒。我只能通过POST请求编写和检索数据。
- 我在CustomTrustManager的checkServerTrusted方法中收到的证书链的CN不是IP地址而不是DNS,更像是仅限单词(即CN = commonname)。
- 我的HostNameVerifier暂时是ALLOW_ALL_HOSTNAME_VERIFIER(我认为可能会解决第3个信息的问题?)。
- 我正在使用SSLContext.getInstance(TLS),我的协议是TLSv1,TLSv1.1和TLSv1.2。
- 正在使用的证书是自签名的。
- 在checkServerTrusted方法中,信任管理员始终信任X509Certificate链(我创建了一个始终信任证书的trustManager)。
- Request is being sent to https://[IP_address]:443/
- I am sending a request to a special hardware, like a control box. I can only write and retrieve data through POST requests.
- The certificate chain that I receive in my CustomTrustManager's checkServerTrusted method has a CN that is not an IP address and not a DNS, more like a word only (i.e. CN=commonname).
- My HostNameVerifier is ALLOW_ALL_HOSTNAME_VERIFIER temporarily (which i think might solve the problem with the 3rd info?).
- I am using SSLContext.getInstance("TLS") and my protocols are TLSv1, TLSv1.1, and TLSv1.2.
- The certificate being used is self-signed.
- In checkServerTrusted method, the X509Certificate chain is always trusted by a trustmanager (I made a trustManager that always trusts the certificate).
任何输入都将受到赞赏。
Any inputs will be appreciated.
推荐答案
我的问题的答案是我评论了用于将生成的私钥添加到密钥存储区的代码,因此SSL HandShake在客户端身份验证期间失败离子。
The answer to my problem was that I commented the code for adding my generated private key to my key store so the SSL HandShake fails during client authentication.
我希望这个答案可以帮助别人。
I hope this answer can help somebody.
这篇关于获取javax.net.ssl.SSLHandshakeException:在Android 5.0.2中由peer关闭连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!