diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java index 5980290..ab869cf 100644 --- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java @@ -10,6 +10,7 @@ import android.content.pm.PackageManager; 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; @@ -26,6 +27,7 @@ import android.webkit.CookieManager; 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.ValueCallback; @@ -797,6 +799,50 @@ public class RNCWebViewManager extends SimpleViewManager { return this.shouldOverrideUrlLoading(view, 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,