SSLHandshakeException: Android 4.2.2使用httpurlconnection的证书异常



我正在努力解决一个奇怪的问题,而在Android中使用HttpURLConnection进行webservice api调用。我得到以下例外只有Android版本4.2.2。它在Android 4.0.3, 4.3和4.4及以上版本中工作正常。我使用下面的代码为服务api调用。

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();

这里是例外(仅在Android SDK版本4.2.2)

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

请就此提出建议。

谢谢Himanshu .

重要提示

检查您的设备时间是否正确?

您的设备似乎不信任证书的权威。结帐此帖子:无法验证证书签名?

最新更新