Skip to content

Commit

Permalink
Add ssl error handling (react-native-webview#1450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Vlasov committed Jun 11, 2020
1 parent e25b2b5 commit 23ff090
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import android.graphics.Bitmap;
import android.graphics.Color;
import android.Manifest;
import android.net.http.SslError;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
Expand All @@ -49,6 +50,7 @@
import android.webkit.DownloadListener;
import android.webkit.GeolocationPermissions;
import android.webkit.JavascriptInterface;
import android.webkit.SslErrorHandler;
import android.webkit.PermissionRequest;
import android.webkit.URLUtil;
import android.webkit.ServiceWorkerController;
Expand Down Expand Up @@ -1136,6 +1138,50 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
}


@Override
public void onReceivedSslError(final WebView webView, final SslErrorHandler handler, final SslError error) {
handler.cancel();

int code = error.getPrimaryError();
String failingUrl = error.getUrl();
String description = "";
String descriptionPrefix = "SSL error: ";

// https://developer.android.com/reference/android/net/http/SslError.html
switch (code) {
case SslError.SSL_DATE_INVALID:
description = "The date of the certificate is invalid";
break;
case SslError.SSL_EXPIRED:
description = "The certificate has expired";
break;
case SslError.SSL_IDMISMATCH:
description = "Hostname mismatch";
break;
case SslError.SSL_INVALID:
description = "A generic error occurred";
break;
case SslError.SSL_NOTYETVALID:
description = "The certificate is not yet valid";
break;
case SslError.SSL_UNTRUSTED:
description = "The certificate authority is not trusted";
break;
default:
description = "Unknown SSL Error";
break;
}

description = descriptionPrefix + description;

this.onReceivedError(
webView,
code,
description,
failingUrl
);
}

@Override
public void onReceivedError(
WebView webView,
Expand Down

0 comments on commit 23ff090

Please sign in to comment.