Trying to connect to an HTTPS endpoint using TLS1.2 with a self-signed certificate, getting "Connection closed by peer"

589 views
Skip to first unread message

Sebastien ARBOGAST

unread,
Jun 5, 2018, 6:55:11 AM6/5/18
to ksoap2-android
Hello,

I'm desperately trying to connect to an HTTPS endpoint that seems to be using TLS1.2, with what I think is a self-signed certificate in a BKS keystore.
As you can see I'm not sure about a lot of things, since it's the first time I'm trying to do SOAP on Android.

Here is how I'm configuring my transport, based on various bits I found around this mailing list and StackOverflow:

protected Transport createTransport() {
Transport transport = super.createTransport();
try {
if(transport instanceof HttpsTransportSE) {
HttpsTransportSE httpsTransport = (HttpsTransportSE)transport;
if(httpsTransport.getServiceConnection() instanceof HttpsServiceConnectionSE) {
HttpsServiceConnectionSE httpsServiceConnection = (HttpsServiceConnectionSE)httpsTransport.getServiceConnection();
httpsServiceConnection.setSSLSocketFactory(getSSLSocketFactory());
}
}
} catch (IOException e) {
Log.e(TAG, "Could not add key store", e);
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "Could not add key store", e);
} catch (KeyStoreException e) {
Log.e(TAG, "Could not add key store", e);
} catch (KeyManagementException e) {
Log.e(TAG, "Could not add key store", e);
}
this.transport = transport;
return transport;
}

private SSLSocketFactory getSSLSocketFactory() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, tmf.getTrustManagers(), null);
return new Tls12SocketFactory(context.getSocketFactory());
}

Where Tls12SocketFactory is the class shared in this discussion: https://groups.google.com/forum/#!topic/ksoap2-android/x2ns8t1htdM

But I'm always getting the same exception:

W/System.err: 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:351)
                  at be.brusafe.brusafeplus.security.Tls12SocketFactory$DelegateSSLSocket.startHandshake(Tls12SocketFactory.java:164)
                  at com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:192)
                  at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:149)
                  at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)
                  at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)
                  at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
                  at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
                  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
                  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
                  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
                  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
                  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:258)
W/System.err:     at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
                  at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(Unknown Source:0)
                  at org.ksoap2.transport.HttpsServiceConnectionSE.openOutputStream(HttpsServiceConnectionSE.java:127)
                  at com.easywsdl.exksoap2.mtom.MTOMTransportImplementation.sendData(MTOMTransportImplementation.java:65)
                  at com.easywsdl.exksoap2.transport.AdvancedHttpsTransportSE.sendData(AdvancedHttpsTransportSE.java:39)
                  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:184)

How could I troubleshoot what's going on?

Best regards,

Sébastien Arbogast
Reply all
Reply to author
Forward
0 new messages