较低版本中的Android java.security.cert.CertificateException

时间:2015-05-26 15:26:04

标签: java android ssl

在使用SSL证书时,我在Android版本上的错误仍低于4.0。请帮助。

05-26 18:13:21.230: W/System.err(452): javax.net.ssl.SSLHandshakeException
05-26 18:13:21.230: W/System.err(452):  at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:477)
05-26 18:13:21.230: W/System.err(452):  at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.<init>(OpenSSLSocketImpl.java:750)
05-26 18:13:21.230: W/System.err(452):  at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:692)
05-26 18:13:21.240: W/System.err(452):  at org.apache.http.impl.io.SocketInputBuffer.<init>(SocketInputBuffer.java:93)
05-26 18:13:21.240: W/System.err(452):  at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:83)
05-26 18:13:21.240: W/System.err(452):  at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:170)
05-26 18:13:21.240: W/System.err(452):  at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:106)
05-26 18:13:21.240: W/System.err(452):  at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:129)
05-26 18:13:21.240: W/System.err(452):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:171)
05-26 18:13:21.240: W/System.err(452):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-26 18:13:21.240: W/System.err(452):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-26 18:13:21.250: W/System.err(452):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
05-26 18:13:21.250: W/System.err(452):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-26 18:13:21.250: W/System.err(452):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-26 18:13:21.250: W/System.err(452):  at HttpsConnection.getResponseFromHttpPostRequest(HttpsConnection.java:186)
05-26 18:13:21.260: W/System.err(452):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
05-26 18:13:21.260: W/System.err(452):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
05-26 18:13:21.260: W/System.err(452):  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
05-26 18:13:21.260: W/System.err(452):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
05-26 18:13:21.260: W/System.err(452):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
05-26 18:13:21.260: W/System.err(452):  at java.lang.Thread.run(Thread.java:1019)
05-26 18:13:21.270: W/System.err(452): Caused by: java.security.cert.CertificateException

此代码抛出异常:

public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 
    for (X509TrustManager tm : x509TrustManagers) { 
        try { 
            tm.checkServerTrusted(chain, authType); 
            return; 
        } catch (CertificateException e) { /* ignore */ } 
    } 
    throw new CertificateException(); 
}

0 个答案:

没有答案