此处相同 - APK 中检测到不安全的主机名验证程序
您的应用程序正在使用不安全的 HostnameVerifier 实现。请
请参阅这篇 Google 帮助中心文章了解详细信息,包括
修复漏洞的最后期限。我没有使用 HostnameVerifier
并且不调用 setDefaultHostnameVerifier。此外 - 我使用 OKHTTP
http 请求的 lib。我希望定义 TrustManager 能够解决
这个问题。
因为我没有子类化HostnameVerifier
或致电setDefaultHostnameVerifier()
我认为它依赖于一些第三方库。由于我无法检测到这样的库,我想我会尝试使用以下代码添加一个类
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(final String hostname, final SSLSession session) {
if (/* check if SSL is really valid */)
return true;
else
return false;
}
});
到我的项目,看看它是否解决了问题。
所以我做到了,此外,我还为每个 webView 添加了重写方法
@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
// the main thing is to show dialog informing user
// that SSL cert is invalid and prompt him to continue without
// protection: handler.proceed();
// or cancel: handler.cancel();
String message;
switch(error.getPrimaryError()) {
case SslError.SSL_DATE_INVALID:
message = ResHelper.getString(R.string.ssl_cert_error_date_invalid);
break;
case SslError.SSL_EXPIRED:
message = ResHelper.getString(R.string.ssl_cert_error_expired);
break;
case SslError.SSL_IDMISMATCH:
message = ResHelper.getString(R.string.ssl_cert_error_idmismatch);
break;
case SslError.SSL_INVALID:
message = ResHelper.getString(R.string.ssl_cert_error_invalid);
break;
case SslError.SSL_NOTYETVALID:
message = ResHelper.getString(R.string.ssl_cert_error_not_yet_valid);
break;
case SslError.SSL_UNTRUSTED:
message = ResHelper.getString(R.string.ssl_cert_error_untrusted);
break;
default:
message = ResHelper.getString(R.string.ssl_cert_error_cert_invalid);
}
mSSLConnectionDialog = new MaterialDialog.Builder(getParentActivity())
.title(R.string.ssl_cert_error_title)
.content(message)
.positiveText(R.string.continue_button)
.negativeText(R.string.cancel_button)
.titleColorRes(R.color.black)
.positiveColorRes(R.color.main_red)
.contentColorRes(R.color.comment_grey)
.backgroundColorRes(R.color.sides_menu_gray)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
mSSLConnectionDialog.dismiss();
handler.proceed();
}
})
.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
handler.cancel();
}
})
.build();
mSSLConnectionDialog.show();
}
to the
mWebView.setWebViewClient(new WebViewClient() {
... // other corresponding overridden methods
}
最后谷歌说:
安全扫描完成
未检测到 APK 158 的已知漏洞。
不过我不确定是什么代码造成的,HostNameVerifier
or onReceivedSslError()
of mWebView.setWebViewClient
. Note: HostNameVerifier.setDefaultHostnameVerifier()
不应该返回true
总是像你的代码一样!它必须实现一些逻辑来检查 SSL 是否一切正常并返回 true 或 false。这是必要的。