【问题标题】:java.security.cert.CertPathValidatorException: Trust anchor for certification path not foundjava.security.cert.CertPathValidatorException:找不到证书路径的信任锚
【发布时间】:2016-03-31 22:41:36
【问题描述】:

我正在尝试打开证书有问题的网站,经过长时间的研究,我找到了通过覆盖 onReceivedSslError 方法然后继续错误 handler.proceed(); 传递证书错误的方法,但是当我打开网站时,我得到了这个异常

 webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                String[] urls = new String[]{url};
                new ParseURl().execute(urls);
            }
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (!url.equals("about:blank")) {
                    view.loadUrl(url);
                }
                return false;
            }
            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                handler.proceed();
            }
        });

异常日志

12-26 05:28:11.719 5681-5832/com.example.mina.speechrecognition D/dalvikvm: GC_FOR_ALLOC freed 350K, 13% free 4084K/4652K, paused 7ms, total 8ms
12-26 05:28:12.599 5681-5681/com.example.mina.speechrecognition D/TilesManager: Starting TG #0, 0xb85683a0
12-26 05:28:12.599 5681-5681/com.example.mina.speechrecognition D/TilesManager: new EGLContext from framework: b83b4440 
12-26 05:28:12.599 5681-5681/com.example.mina.speechrecognition D/GLWebViewState: Reinit shader
12-26 05:28:13.067 5681-5681/com.example.mina.speechrecognition D/GLWebViewState: Reinit transferQueue
12-26 05:28:13.095 5681-5681/com.example.mina.speechrecognition W/Web Console: The page at https://noor.moe.gov.sa/Noor/login.aspx ran insecure content from http://www.moe.gov.sa/_layouts/15/MOE/script/MOECommon.js.
                                                                                at null:1
12-26 05:28:18.935 5681-6039/com.example.mina.speechrecognition W/System.err: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
12-26 05:28:18.951 5681-6039/com.example.mina.speechrecognition W/System.err:     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:401)
12-26 05:28:18.951 5681-6039/com.example.mina.speechrecognition W/System.err:     at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
12-26 05:28:18.951 5681-6039/com.example.mina.speechrecognition W/System.err:     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
12-26 05:28:18.951 5681-6039/com.example.mina.speechrecognition W/System.err:     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
12-26 05:28:18.951 5681-6039/com.example.mina.speechrecognition W/System.err:     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
12-26 05:28:18.951 5681-6039/com.example.mina.speechrecognition W/System.err:     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
12-26 05:28:19.011 5681-6039/com.example.mina.speechrecognition W/System.err:     at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
12-26 05:28:19.011 5681-6039/com.example.mina.speechrecognition W/System.err:     at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
12-26 05:28:19.011 5681-6039/com.example.mina.speechrecognition W/System.err:     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:449)
12-26 05:28:19.115 5681-6039/com.example.mina.speechrecognition W/System.err:     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:434)
12-26 05:28:19.119 5681-6039/com.example.mina.speechrecognition W/System.err:     at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:181)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err:     at org.jsoup.helper.HttpConnection.get(HttpConnection.java:170)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err:     at com.example.mina.speechrecognition.WebActivity$ParseURl.doInBackground(WebActivity.java:156)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err:     at com.example.mina.speechrecognition.WebActivity$ParseURl.doInBackground(WebActivity.java:150)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err:     at java.lang.Thread.run(Thread.java:841)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
12-26 05:28:19.459 5681-6039/com.example.mina.speechrecognition W/System.err:     at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:282)
12-26 05:28:19.459 5681-6039/com.example.mina.speechrecognition W/System.err:     at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:202)
12-26 05:28:19.463 5681-6039/com.example.mina.speechrecognition W/System.err:     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:595)
12-26 05:28:19.463 5681-6039/com.example.mina.speechrecognition W/System.err:     at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
12-26 05:28:19.463 5681-6039/com.example.mina.speechrecognition W/System.err:     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:398)
12-26 05:28:19.467 5681-6039/com.example.mina.speechrecognition W/System.err:   ... 19 more
12-26 05:28:19.467 5681-6039/com.example.mina.speechrecognition W/System.err: Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
12-26 05:28:19.467 5681-6039/com.example.mina.speechrecognition W/System.err:   ... 24 more

我分析网站并提取ID

public class ParseURl extends AsyncTask<String, Void, Boolean> {
        @Override
        protected Boolean doInBackground(String... params) {

            try {
                listID.clear();
                Document doc = Jsoup.connect(params[0]).get();
                Elements inputs = doc.select("input[type=text], input[type=password], input[type=email]");

                for (Element ele : inputs) {
                    listID.add(ele.attr("id"));
                }
            } catch (IOException e) {
                e.printStackTrace(); // exception fired here
                Log.i("error stack", e.getMessage());
            }
            if (listID.size() > 0) {
                return true;
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);

            if (result) {
                //  Toast.makeText(WebActivity.this, "Analysis site Done", Toast.LENGTH_LONG).show();
                //startReadInput();
            } else {
                Toast.makeText(WebActivity.this, "your site dont have input to fill", Toast.LENGTH_LONG).show();
            }
        }
    }

【问题讨论】:

    标签: java android ssl webview


    【解决方案1】:

    我已尝试使用您的 logcat 中显示的网站 url,它可以工作

    final String url = "https://noor.moe.gov.sa/Noor/login.aspx";
    WebView mWebView = (WebView) v.findViewById(R.id.webView);
    mWebView.setInitialScale(1);
    mWebView.getSettings().setUseWideViewPort(true);
    
    mWebView.setWebViewClient(new WebViewClient(){
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    if (!url.equals("about:blank")) {
                        view.loadUrl(url);
                    }
                    return false;
                }
                @Override
                public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                    handler.proceed();
                }
            });
    
    mWebView.loadUrl(url);
    

    这是截图

    【讨论】:

    • handler.proceed () 不是正确的解决方案。您的应用将被 Google Play 拒绝。有必要通过警报对话框获得批准。
    猜你喜欢
    • 2017-01-08
    • 2016-12-26
    • 1970-01-01
    • 2018-01-06
    • 2023-02-15
    • 2019-08-02
    • 2014-09-27
    • 1970-01-01
    相关资源
    最近更新 更多