简体   繁体   中英

Android SSL Handshake Exception

I have been developing an app that can parse information off three website pages and then display the parsed information to the user. I never got an any exceptions for the pass few weeks since this was working. Then today when I was testing the parsing function again I wasn't getting any result back and the logcat gave a SSLHandshakeException as well as bunch of system errors. The following errors are from the 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

Below is the partial code for my QueryActivity that is responsible for parsing the webpage. I was passing in the url of three website from another activity into QueryActivity then I used Jsoup to connect and get the html for parsing.

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

Can someone explain why is this happening and any solution to this problem and as far as I know I didn't change any code in this activity(QueryActivity)? Thank you.

If this problem is on your side: 1. Check date/time of you device. 2. Maybe you changed a firmware version or installed some updates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM