美文网首页Android经验分享
Android WebView中支持Https签名检测

Android WebView中支持Https签名检测

作者: 没头脑和挺高兴 | 来源:发表于2019-02-14 16:35 被阅读0次

Https签名认证是什么意思

  • http是没有加密的,很容易被中间人攻击
  • https使用了对称和非对称加密
    • 数据传输使用对称加密
    • 密钥交换使用非对称加密
  • https也有可能中间人攻击,中间人伪造了公钥和私钥
  • ca是用来验证公钥的。这样伪造的公钥就会被浏览器在认证时进行提醒

WebView的支持

  • WebView本身是支持https签名认证的
  • 当发现证书有问题时,需要提醒用户,这个是通过webview的回调来实现自定义
        * Displays SSL error(s) dialog to the user.
         */
        @Override
        public void onReceivedSslError(final WebView view,
                                       final SslErrorHandler handler, final SslError error) {

            if (WebSettings.getInstance().mShowSecurityWarnings) {

                new AlertDialog.Builder(getContext())
                        .setTitle(R.string.web_http_ssl_title)
                        .setMessage(R.string.web_http_ssl_message)
//                      .setIcon(android.R.drawable.ic_dialog_alert)
                        .setPositiveButton(R.string.common_ok,
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                                        int whichButton) {
                                        handler.proceed();
                                        dialog.dismiss();
                                    }
                                })

                        .setNegativeButton(R.string.common_cancel,
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                                        int whichButton) {
                                        handler.cancel();
                                        // resetTitleAndRevertLockIcon();
                                        dialog.dismiss();
                                    }
                                })
                        .create().show();
            } else {
                handler.proceed();
            }
        }

测试网站

相关文章

网友评论

    本文标题:Android WebView中支持Https签名检测

    本文链接:https://www.haomeiwen.com/subject/uaneeqtx.html