title: SSLHandshakeException: Certificate Exception using HttpURLConnetion with Android 4.2.2
body: <p>I am struggling with a strange issue, while using <strong>HttpURLConnection</strong> for webservice api call in Android. I am getting below exception <strong>ONLY with Android version 4.2.2</strong>. It is working fine in Android 4.0.3, 4.3 and 4.4 and above.
  I am using below code for service api call.</p>
  
  <pre><code>HttpURLConnection mConn = (HttpURLConnection)mUrl.openConnection();
  mConn.addRequestProperty("Connection", "close");
  mConn.setConnectTimeout(CONNECTION_TIMEOUT);
  mConn.setReadTimeout(SOCKET_TIMEOUT);
  mConn.setUseCaches(true);
  mConn.setRequestMethod("POST");
  String param = Utils.appendQueryParams(null,this.stringparams);
  mConn.setDoInput(true);
  mConn.setDoOutput(true);
  mConn.setFixedLengthStreamingMode(param.getBytes().length);
  mConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  mConn.setRequestProperty("Accept", "application/json");
  mConn.connect();
  PrintWriter out = new PrintWriter(mConn.getOutputStream());
  out.print(param);
  out.close();
  </code></pre>
  
  <p>Here is the Exception (ONLY in Android SDK version 4.2.2)</p>
  
  <pre><code>08-18 11:43:22.663  26427-26485/com.abc.xyz W/System.err﹕ javax.net.ssl.SSLHandshakeException: com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: IssuerName(CN=Go Daddy Root Certificate Authority - G2, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US) does not match SubjectName(CN=Go Daddy Root Certificate Authority - G2, OU=https://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US) of signing certificate.
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:381)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at com.halomem.android.utils.ServiceCall.executeRequest(ServiceCall.java:86)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at com.halomem.android.impl.Session$1.run(Session.java:161)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ Caused by: java.security.cert.CertificateException: com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: IssuerName(CN=Go Daddy Root Certificate Authority - G2, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US) does not match SubjectName(CN=Go Daddy Root Certificate Authority - G2, OU=https://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US) of signing certificate.
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:296)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:197)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:597)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:378)
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ ... 9 more
  08-18 11:43:22.833  26427-26485/com.abc.xyz W/System.err﹕ Caused by: com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: IssuerName(CN=Go Daddy Root Certificate Authority - G2, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US) does not match SubjectName(CN=Go Daddy Root Certificate Authority - G2, OU=https://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US) of signing certificate.
  08-18 11:43:22.843  26427-26485/com.abc.xyz W/System.err﹕ at com.android.org.bouncycastle.jce.provider.RFC3280CertPathUtilities.processCertA(RFC3280CertPathUtilities.java:1525)
  08-18 11:43:22.843  26427-26485/com.abc.xyz W/System.err﹕ at com.android.org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi.engineValidate(PKIXCertPathValidatorSpi.java:305)
  08-18 11:43:22.843  26427-26485/com.abc.xyz W/System.err﹕ at com.sec.android.security.pkix.SecCertPathValidatorSpi.engineValidate(SecCertPathValidatorSpi.java:99)
  08-18 11:43:22.843  26427-26485/com.abc.xyz W/System.err﹕ at java.security.cert.CertPathValidator.validate(CertPathValidator.java:190)
  08-18 11:43:22.843  26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:283)
  08-18 11:43:22.843  26427-26485/com.abc.xyz W/System.err﹕ ... 13 more
  </code></pre>
  
  <p>Please suggest in this regard.</p>
  
  <p>Thanks
  Himanshu.</p>