NullPointerException on SSLParametersImpl
brunonmelo opened this issue · comments
Hello everyone, here is my problem:
I'm successful made a connection to a SOAP webservice that need a certificate authentication the establish a connection, using the Eclipse, with this code:
SoapSerializationEnvelope envelope = SoapEnvelopeCreator.createSOAPRequest();
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
androidHttpTransport.call(SOAP_ACTION), envelope);
result = (SoapObject) envelope.getResponse();
It's a very simple code, not fancy at all.
And I make the connection configuration using this code:
private void setupSystem() {
System.clearProperty("javax.net.ssl.keyStore");
System.clearProperty("javax.net.ssl.keyStorePassword");
System.clearProperty("javax.net.ssl.trustStore");
System.clearProperty("javax.net.ssl.trustStorePassword");
System.clearProperty("https.protocols");
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
System.setProperty("javax.net.ssl.keyStore", this.infoCert.getCertPath());
System.setProperty("javax.net.ssl.keyStorePassword", this.infoCert.getCertPassword());
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStore", "src/main/resources/cacerts/cacertsProd");
System.setProperty("javax.net.ssl.trustStorePassword", CACERT_PASSWORD);
System.setProperty("https.protocols", "TLSv1.2");
}
It worked fine on my Eclipse's tests but, when I tried to use the same code on an Android device, I get this error:
FATAL EXCEPTION: AsyncTask #1
yada yada..
Caused by: java.lang.NullPointerException:
Attempt to invoke virtual method 'java.lang.Object com.android.org.conscrypt.SSLParametersImpl.clone()' on a null object reference
at com.android.org.conscrypt.OpenSSLSocketFactoryImpl.createSocket(OpenSSLSocketFactoryImpl.java:102)
at com.android.okhttp.Connection.upgradeToTls(Connection.java:171)
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:382)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:217)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
at org.ksoap2.transport.ServiceConnectionSE.openOutputStream(ServiceConnectionSE.java:130)
at org.ksoap2.transport.HttpTransportSE.sendData(HttpTransportSE.java:295)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:184)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
at mypackage(SendRequisition.java:124)
I don't get it. What am I doing wrong and how do I solve this?
Hmm, that's the first time I've seen calls to set System
properties in that way. I can't look at the documentation myself, but I think the better way is to configure the encryption configuration in an OkHttpClient
yourself or find a way to do it in HttpTransport
. Avoid getting encryption implementations, and any configuration really, by using a String
. Better to use an enum or constant that's in the framework as not all devices support all the same crypto algorithms.
Hey Kisty!
So, do you suggest that I remove this calls to set System configurations, all right.
But when I make the the encryption configuration on an OkHttpClient
, how could I make a call a Soap webServer passing the Soap Envelope?
Because, for what I understand, I need to do the configuration of the SSL encryption, and, the configuration for the SOAPs connection by hand, and calling using the OkHttpClient
and not the HttpTransportSE
, right?
No changes on this - closing as part of clean up.