最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android Webview上的ssl warning的處理方式詳解及實例

 更新時間:2017年02月25日 11:59:23   作者:yizhihaohut  
這篇文章主要介紹了Android Webview上的ssl warning的處理方式詳解及實例的相關(guān)資料,需要的朋友可以參考下

Android Webview上的ssl warning的處理方式詳解

前言:

因為最近遇到google pay上匯報的安全漏洞問題,需要處理ssl warning.

安全提醒

您的應用中 WebViewClient.onReceivedSslError 處理程序的實施方式很不安全。具體來說,這種實施方式會忽略所有 SSL 證書驗證錯誤,從而使您的應用容易受到中間人攻擊。攻擊者可能會更改受影響的 WebView 內(nèi)容、讀取傳輸?shù)臄?shù)據(jù)(例如登錄憑據(jù)),以及執(zhí)行應用中使用 JavaScript 的代碼。

為了正確處理 SSL 證書驗證,請將您的代碼更改為在服務器提供的證書符合您的預期時調(diào)用 SslErrorHandler.proceed(),否則應調(diào)用SslErrorHandler.cancel()。系統(tǒng)已向您的開發(fā)者帳號地址發(fā)送了一封電子郵件提醒,其中列出了受影響的應用和類。

所以查閱了相關(guān)Webview上的訪問ssl協(xié)議的網(wǎng)址的警告處理方式。

其實大概意思就是說客戶端在處理https鏈接返回的ssl錯誤的時候不要無腦的直接通過,需要友好的在客戶端主動彈出對話框讓用戶做出選擇。

然后添加代碼如下:

public void onReceivedSslError(WebView view,final SslErrorHandler handler,
  SslError error) {
      final AlertDialog.Builder builder = new AlertDialog.Builder(WebViewActivity.this);
      String message = "SSL Certificate error.";
      switch (error.getPrimaryError()) {
        case SslError.SSL_UNTRUSTED:
          message = "The certificate authority is not trusted.";
          break;
        case SslError.SSL_EXPIRED:
          message = "The certificate has expired.";
          break;
        case SslError.SSL_IDMISMATCH:
          message = "The certificate Hostname mismatch.";
          break;
        case SslError.SSL_NOTYETVALID:
          message = "The certificate is not yet valid.";
          break;
        case SslError.SSL_DATE_INVALID:
          message = "The date of the certificate is invalid";
          break;
        case SslError.SSL_INVALID:
        default:
          message = "A generic error occurred";
          break;
      }
      message += " Do you want to continue anyway?";

      builder.setTitle("SSL Certificate Error");
      builder.setMessage(message);

      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();
 }

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論

河北省| 台北县| 渑池县| 拜泉县| 肃北| 阿克陶县| 灵丘县| 宣城市| 开江县| 郯城县| 霍邱县| 桂林市| 桂林市| 阿图什市| 西藏| 满洲里市| 崇阳县| 桦南县| 宁强县| 临江市| 永修县| 拉萨市| 祁连县| 岑溪市| 贺州市| 屏山县| 昆山市| 方正县| 荣昌县| 麻阳| 萨迦县| 泰州市| 义马市| 信宜市| 塘沽区| 葵青区| 阆中市| 宝丰县| 清镇市| 新蔡县| 浦城县|