Javax.net.ssl.SSLException: SSL handshake canceled. Connection reset via peer when calling webservice Android.

I call https webservice and its work is great before, but now when I try to call it, it gives me the following errors.

Log Errors:

12-23 06:28:11.969: W/System.err(3014): javax.net.ssl.SSLException: SSL handshake aborted: ssl=0x1cc160: I/O error during system call, Connection reset by peer 12-23 06:28:11.979: W/System.err(3014): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method) 12-23 06:28:11.979: W/System.err(3014): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:474) 12-23 06:28:11.979: W/System.err(3014): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.<init>(OpenSSLSocketImpl.java:750) 12-23 06:28:11.979: W/System.err(3014): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:692) 12-23 06:28:11.979: W/System.err(3014): at crittercism.android.aa.getInputStream(Unknown Source) 12-23 06:28:11.979: W/System.err(3014): at org.apache.http.impl.io.SocketInputBuffer.<init>(SocketInputBuffer.java:93) 12-23 06:28:11.979: W/System.err(3014): at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:83) 12-23 06:28:11.979: W/System.err(3014): at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:170) 12-23 06:28:11.979: W/System.err(3014): at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:106) 12-23 06:28:11.979: W/System.err(3014): at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:129) 12-23 06:28:11.979: W/System.err(3014): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:171) 12-23 06:28:11.989: W/System.err(3014): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 12-23 06:28:11.989: W/System.err(3014): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 12-23 06:28:11.989: W/System.err(3014): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359) 12-23 06:28:11.989: W/System.err(3014): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 12-23 06:28:11.989: W/System.err(3014): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 12-23 06:28:11.989: W/System.err(3014): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 

I use the following code to call https webservice.

 public static void trustAllHosts() { X509TrustManager easyTrustManager = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { // Oh, I am easy! } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { // Oh, I am easy! } public X509Certificate[] getAcceptedIssuers() { return null; } }; // Create a trust manager that does not validate certificate chains TrustManager[] trustAllCerts = new TrustManager[] { easyTrustManager }; // Install the all-trusting trust manager try { SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection .setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (Exception e) { e.printStackTrace(); } } public static HttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore .getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory .getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager( params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } } 

MySSLSocketFactory.java

 public class MySSLSocketFactory extends SSLSocketFactory { SSLContext sslContext = SSLContext.getInstance("TLS"); public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(truststore); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext.init(null, new TrustManager[] { tm }, null); } @Override public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException { return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose); } @Override public Socket createSocket() throws IOException { return sslContext.getSocketFactory().createSocket(); } } 

It has been working fine before, but now it is failing. There are no changes on the server.

I already mentioned

I tested it both in Wi-Fi and in mobile data. The application does not work in both.

If anyone encounters this problem before, please help me solve it.

+16
java android ssl web-services
Dec 23 '13 at 10:19
source share
4 answers

I also have such an exception. I found that this is because TLS 1.0 was not supported by the server.

I noticed that the Android device, http connection fails on a server on which TLS 1.0 not supported. I searched everything regarding the error, but did not find anything related to this problem. And the problem was resolved when support for the TLS 1.0 protocol was added to the server. You can check server / host protocol support with https://www.ssllabs.com/ssltest .

+26
Dec 23 '13 at 14:34
source share

There may be two reasons:

Certificates may have expired on the client or server side.

Solution: Extend the validity of an existing certificate or modify new certificates.

The server port was reset for another port.

Solution: I encountered this problem of changing the port, usually due to server maintenance or updating patches, sometimes the service port receives the changes. Ask the person who provided wsdl for you to restore wsdl on your server and check the port to see if it matches the existing wsdl on the client side or not. Most likely it will be here.

+3
Dec 23 '13 at 11:01
source share

We had the same problem that started this morning, and it was resolved.

SSL on IIS 8

  • Everything worked fine yesterday and yesterday, and our SSL was updated on the IIS website.
  • When checking the site’s binding to SSL, we noticed that in IIS8 a new checkbox “Require server name” was set, it was not checked, so we turned it on.
  • This caused a problem.
  • He returned to IIS, disabled the check box .... the problem is resolved!
+2
Oct 13 '15 at 16:27
source share

I had the same problem for some Android devices. Found a solution using the IIS server settings .

Steps:

  • Open IIS
  • Select the site you are working on.
  • Change site binding
  • Uncheck Mandatory server name authentication
  • Click OK

Summary screenshot:

enter image description here

Hope this helps you.

0
Jul 11 '17 at 8:04 on
source share



All Articles