1

I am facing these exception in Android 4.4.4 but in Android 6 and in web it is working fine.

What is the issue?

@Override
protected String doInBackground(Object... params) {
    HttpResponse httpResponse = null;
    String response = null;
    Object httpRequest = null;
    if (null != params && params.length > 0) {
        httpRequest = params[0];
    }
    try {
        HttpParams httpParameters = new BasicHttpParams();
        int timeoutConnection = Constants.TIMEOUT_CONNECTION;
        HttpConnectionParams.setConnectionTimeout(httpParameters,
                timeoutConnection);
        int timeoutSocket = Constants.TIMEOUT_CONNECTION;
        HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

        HttpClient httpClient = new DefaultHttpClient(httpParameters);

        if (httpRequest instanceof HttpPost) {
            httpResponse = httpClient.execute((HttpPost) httpRequest);
        } else if (httpRequest instanceof HttpGet) {
            httpResponse = httpClient.execute((HttpGet) httpRequest);
        } else if (httpRequest instanceof HttpDelete) {
            httpResponse = httpClient.execute((HttpDelete) httpRequest);
        } else if (httpRequest instanceof HttpPut) {
            httpResponse = httpClient.execute((HttpPut) httpRequest);
        }
        StringBuffer stringBuffer = new StringBuffer("");
        if (httpResponse != null)// Retrieve response
        {
            if (httpResponse.getEntity() == null) {
                LogManager.D(TAG, "Entity is null");
            }
            String output;
            InputStream is = httpResponse.getEntity().getContent();
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(is));

            while ((output = br.readLine()) != null) {
                stringBuffer.append(output);
            }
            stringBuffer.trimToSize();
            is.close();
            br.close();
            br = null;
            is = null;

            httpResponse.getEntity().consumeContent();
            response = stringBuffer.toString();
            statusCode = httpResponse.getStatusLine().getStatusCode();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return response;
}

and the exception which i am getting in Android 4.4.4

01-13 11:14:45.001: W/System.err(10927): javax.net.ssl.SSLException: hostname in certificate didn't match:
 <abc.dbc.net> != <*.azurewebsites.net> OR <*.azurewebsites.net> OR <*.scm.azurewebsites.net> OR <*.azure-mobile.net> OR <*.scm.azure-mobile.net>
01-13 11:14:45.006: W/System.err(10927):    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:185)
01-13 11:14:45.006: W/System.err(10927):    at org.apache.http.conn.ssl.BrowserCompatHostnameVerifier.verify(BrowserCompatHostnameVerifier.java:54)
01-13 11:14:45.006: W/System.err(10927):    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:114)
01-13 11:14:45.006: W/System.err(10927):    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:95)
01-13 11:14:45.006: W/System.err(10927):    at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)
01-13 11:14:45.006: W/System.err(10927):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
01-13 11:14:45.006: W/System.err(10927):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-13 11:14:45.011: W/System.err(10927):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-13 11:14:45.011: W/System.err(10927):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
01-13 11:14:45.011: W/System.err(10927):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-13 11:14:45.011: W/System.err(10927):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-13 11:14:45.011: W/System.err(10927):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-13 11:14:45.011: W/System.err(10927):    at com.ericsson.dat.Presenter.threading.NetworkTask.doInBackground(NetworkTask.java:79)
01-13 11:14:45.011: W/System.err(10927):    at com.ericsson.dat.Presenter.threading.NetworkTask.doInBackground(NetworkTask.java:1)
01-13 11:14:45.011: W/System.err(10927):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-13 11:14:45.016: W/System.err(10927):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
01-13 11:14:45.016: W/System.err(10927):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
01-13 11:14:45.016: W/System.err(10927):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
01-13 11:14:45.016: W/System.err(10927):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
01-13 11:14:45.016: W/System.err(10927):    at java.lang.Thread.run(Thread.java:856)
halfer
  • 19,824
  • 17
  • 99
  • 186
Atul Dhanuka
  • 1,453
  • 5
  • 20
  • 56
  • How about using `SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER` as Prashant says in his [answer](http://stackoverflow.com/a/8839926/5588347)? – StackUseR Jan 13 '17 at 06:59
  • @AshishSrivastava: this would make the application accept all certificates issued by a valid CA no matter which web site the certificate is for. This would make a man in the middle attack trivial. – Steffen Ullrich Jan 13 '17 at 08:31
  • Its probably missing support for SNI which results in the server returning a certificate for a different site. This might also result in different content returned if you just ignore this problem. See http://stackoverflow.com/questions/5879894/android-ssl-sni-support for more information. – Steffen Ullrich Jan 13 '17 at 08:32
  • 1
    @SteffenUllrich then y it is working in Android 6 not in Android 4.4.4 – Atul Dhanuka Jan 13 '17 at 08:55
  • @AtulDhanuka: because Android 6 has a newer version of the TLS stack and of various libraries? – Steffen Ullrich Jan 13 '17 at 09:00
  • @SteffenUllrich ok so plz help me out how i will change the code in doInBackground – Atul Dhanuka Jan 13 '17 at 09:03
  • @AtulDhanuka: I've pointed out one post with more information. And you will find many more if searching for Android+SNI. No need to repeat it here. – Steffen Ullrich Jan 13 '17 at 09:23
  • @MayurRaval: thanks for wanting to edit and improve questions here. Please note that brand names like Android and versions like 4.4.4 are not code, and as such do not need inline formatting. Use backticks for methods, small lines of code, and console I/O. – halfer Jan 13 '17 at 17:30

0 Answers0