Android SSL握手异常

时间:2013-03-05 18:56:38

标签: java android ssl certificate jsoup

我一直在开发一个应用程序,它可以解析三个网站页面上的信息,然后将解析后的信息显示给用户。自从这项工作开始以来,几个星期以来,我从来没有任何例外。然后今天当我再次测试解析函数时,我没有得到任何结果,并且logcat给出了SSLHandshakeException以及一堆系统错误。以下错误来自logcat:

03-05 17:59:39.834: W/System.err(5525): javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
03-05 17:59:39.834: W/System.err(5525):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:374)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
03-05 17:59:39.834: W/System.err(5525):     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:425)
03-05 17:59:39.834: W/System.err(5525):     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:446)
03-05 17:59:39.839: W/System.err(5525):     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
03-05 17:59:39.839: W/System.err(5525):     at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
03-05 17:59:39.839: W/System.err(5525):     at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153)
03-05 17:59:39.839: W/System.err(5525):     at com.example.queryApp.QueryActivity.onCreate(QueryActivity.java:50)
03-05 17:59:39.839: W/System.err(5525):     at android.app.Activity.performCreate(Activity.java:5206)
03-05 17:59:39.839: W/System.err(5525):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
03-05 17:59:39.839: W/System.err(5525):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-05 17:59:39.839: W/System.err(5525):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-05 17:59:39.844: W/System.err(5525):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-05 17:59:39.844: W/System.err(5525):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-05 17:59:39.844: W/System.err(5525):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 17:59:39.844: W/System.err(5525):     at android.os.Looper.loop(Looper.java:137)
03-05 17:59:39.844: W/System.err(5525):     at android.app.ActivityThread.main(ActivityThread.java:4898)
03-05 17:59:39.844: W/System.err(5525):     at java.lang.reflect.Method.invokeNative(Native Method)
03-05 17:59:39.844: W/System.err(5525):     at java.lang.reflect.Method.invoke(Method.java:511)
03-05 17:59:39.844: W/System.err(5525):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-05 17:59:39.849: W/System.err(5525):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-05 17:59:39.849: W/System.err(5525):     at dalvik.system.NativeStart.main(Native Method)
03-05 17:59:39.849: W/System.err(5525): Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
03-05 17:59:39.849: W/System.err(5525):     at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:192)
03-05 17:59:39.854: W/System.err(5525):     at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:163)
03-05 17:59:39.854: W/System.err(5525):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:573)
03-05 17:59:39.854: W/System.err(5525):     at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
03-05 17:59:39.854: W/System.err(5525):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:371)
03-05 17:59:39.854: W/System.err(5525):     ... 27 more
03-05 17:59:39.854: W/System.err(5525): Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
03-05 17:59:39.859: W/System.err(5525):     ... 32 more

以下是我的QueryActivity的部分代码,负责解析网页。我将三个网站的网址从另一个活动传递到QueryActivity然后我使用Jsoup连接并获取用于解析的html。

public class QueryActivity extends Activity
{
   String fWebsite = getIntent().getStringExtra("fURL");
   String sWebsite = getIntent().getStringExtra("sURL");
   String tWebsite = getIntent().getStringExtra("tURL");
   try{
       Document doc1 = Jsoup.connect(fWebsite).timeout(0).get();    
       Document doc2 = Jsoup.connect(sWebsite).timeout(0).get();
       Document doc3 = Jsoup.connect(tWebsite).timeout(0).get();
      }
  catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
    }
}

有人可以解释为什么会发生这种情况以及此问题的任何解决方案,据我所知,我没有更改此活动中的任何代码(QueryActivity)? 谢谢。

1 个答案:

答案 0 :(得分:2)

如果这个问题在你身边:  1.检查设备的日期/时间。  2.也许您更改了固件版本或安装了一些更新。