同樣在這裏 - 不安全的主機名驗證檢測在APK
您的應用使用不安全的實現的HostnameVerifier的。有關詳細信息,請參閱此Google幫助中心文章,其中包括 修復漏洞的截止日期,請參閱 。我沒有使用HostnameVerifier 而不是調用setDefaultHostnameVerifier。此外 - 我使用OKHTTP lib用於http請求。我希望定義TrustManager將解決 這個問題。
由於我不是繼承HostnameVerifier
或致電setDefaultHostnameVerifier()
我認爲它依賴於一些第三方庫。既然不能檢測這樣的lib我想我會嘗試添加一類具有下面的代碼
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();
}
到
mWebView.setWebViewClient(new WebViewClient() {
... // other corresponding overridden methods
}
最後谷歌稱:
安全掃描完整
無已知的漏洞會在APK 158中檢測到。
但是我不確定代碼是什麼,HostNameVerifier
或onReceivedSslError()
的mWebView.setWebViewClient
。注意:HostNameVerifier.setDefaultHostnameVerifier()
不應該返回true
總是喜歡它在你的代碼!它必須實現一些邏輯來檢查它是否全部使用SSL並返回true或false。這是至關重要的。
我也有同樣的問題。請列出您正在使用的所有庫。我可以與我比較,找出哪一個是造成問題。 –
難道是Glide lib?這裏同樣存在問題,但根本沒有在項目中使用HostnameVerifier。無法理解,如果我沒有任何此類實現,我如何更改「我的自定義HostnameVerifier以使其返回false」? – Stan
@Stan我沒有使用Glide lib。我已經添加了HostnameVerifier的代碼。 –