上架google應(yīng)用收到了Google的一封電子郵件,其中包含以下主題:“Google Play警告:SSL錯(cuò)誤處理程序漏洞”.在這封電子郵件中,Google解釋說,我的應(yīng)用程序有一個(gè)[“不安全的WebViewClient.onReceivedSslError處理程序”實(shí)現(xiàn),具體而言,該實(shí)現(xiàn)將忽略所有SSL證書驗(yàn)證錯(cuò)誤,使您的應(yīng)用程序易受中間人攻擊,攻擊者可能更改受影響的WebView的內(nèi)容,讀取傳輸?shù)臄?shù)據(jù)(如登錄憑據(jù)),并使用 [JavaScript](javascript:void())在應(yīng)用程序內(nèi)執(zhí)行代碼
我的代碼
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
// TODO Auto-generated method stub
// super.onReceivedSslError(view, handler, error);
handler.proceed();// 接受https所有網(wǎng)站的證書
}
});
警告是關(guān)于你應(yīng)該通知用戶去一個(gè)無效證書的頁面,你不應(yīng)該直接進(jìn)行.
您可以隱藏警報(bào)對話框,如下所示:
修改onReceivedSslError方法
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
// TODO Auto-generated method stub
// super.onReceivedSslError(view, handler, error);
AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
builder.setMessage("SSL認(rèn)證失敗辈挂,是否繼續(xù)訪問提岔?");
builder.setPositiveButton("確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();// 接受https所有網(wǎng)站的證書
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
然后就OK了