【问题标题】:Google Play Warning: WebViewClient.onReceivedSslError handlerGoogle Play 警告:WebViewClient.onReceivedSslError 处理程序
【发布时间】:2016-05-15 02:42:40
【问题描述】:

我最近收到了一封来自 Google 的电子邮件,主题如下:“Google Play 警告:SSL 错误处理程序漏洞”。在这封电子邮件中,Google 解释说我的应用有一个 ["不安全的 WebViewClient 实现。onReceivedSslError 处理程序。具体来说,该实现会忽略所有 SSL 证书验证错误,从而使您的应用容易受到人为攻击。 -middle 攻击。攻击者可以更改受影响的 WebView 的内容,读取传输的数据(例如登录凭据),并使用 JavaScript 在应用程序内执行代码。"] .....................

我在我的代码中使用:

    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {}

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            // My code
        }
    });

// 我的代码

webview_ClientPost(webView, "https://secure.payu.in/_payment", mapParams.entrySet());

为什么 Google Play 会发送此关于 SSL 的警告?这是我的代码问题还是 PayUMoney 问题?

【问题讨论】:

标签: ssl android-security


【解决方案1】:

我希望这还为时不晚..警告是关于你应该通知用户正在访问一个无效证书的页面,你不应该直接继续。

您可以像这样实现一个警报对话框:

@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(R.string.notification_error_ssl_cert_invalid);
    builder.setPositiveButton("continue", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            handler.proceed();
        }
    });
    builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            handler.cancel();
        }
    });
    final AlertDialog dialog = builder.create();
    dialog.show();
}

这摘自此链接中的 sakiM 答案:Webview avoid security alert from google play upon implementation of onReceivedSslError

【讨论】:

  • 非常感谢
  • 实际上,用户不知道他们是否应该接受不安全的连接。最好的解决方案是完全删除 onReceivedSslError 方法并回退到拒绝不安全连接的默认行为。
【解决方案2】:

问题出在您的代码中。当您像这样调用handler.proceed(); 时,它实际上会消除您连接中的所有安全性。

您应该删除您的 onReceivedSslError 方法。默认实现将拒绝不安全的连接。

【讨论】:

  • 此解决方案对您有用吗?我在我的 Google 控制台中收到了相同的警报。
猜你喜欢
  • 1970-01-01
  • 2016-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-05
  • 1970-01-01
  • 2015-12-22
相关资源
最近更新 更多