First, I've already searched the internet and have been debugging for 3 days.
This is the exact error,
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)
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.
- 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.