Minh Pham 4 years ago
parent
commit
9c1692190a
No account linked to committer's email address

+ 46
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

@@ -10,6 +10,7 @@ import android.content.pm.PackageManager;
10 10
 import android.graphics.Bitmap;
11 11
 import android.graphics.Color;
12 12
 import android.Manifest;
13
+import android.net.http.SslError;
13 14
 import android.net.Uri;
14 15
 import android.os.Build;
15 16
 import android.os.Environment;
@@ -27,6 +28,7 @@ import android.webkit.DownloadListener;
27 28
 import android.webkit.GeolocationPermissions;
28 29
 import android.webkit.JavascriptInterface;
29 30
 import android.webkit.PermissionRequest;
31
+import android.webkit.SslErrorHandler;
30 32
 import android.webkit.URLUtil;
31 33
 import android.webkit.ValueCallback;
32 34
 import android.webkit.WebChromeClient;
@@ -758,6 +760,50 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
758 760
       return this.shouldOverrideUrlLoading(view, url);
759 761
     }
760 762
 
763
+    @Override
764
+    public void onReceivedSslError(final WebView webView, final SslErrorHandler handler, final SslError error) {
765
+        handler.proceed();
766
+
767
+        int code = error.getPrimaryError();
768
+        String failingUrl = error.getUrl();
769
+        String description = "";
770
+
771
+        // https://developer.android.com/reference/android/net/http/SslError.html
772
+        switch (code) {
773
+          case SslError.SSL_DATE_INVALID:
774
+            description = "The date of the certificate is invalid";
775
+            break;
776
+          case SslError.SSL_EXPIRED:
777
+            description = "The certificate has expired";
778
+            break;
779
+          case SslError.SSL_IDMISMATCH:
780
+            description = "Hostname mismatch";
781
+            break;
782
+          case SslError.SSL_INVALID:
783
+            description = "A generic error occurred";
784
+            break;
785
+          case SslError.SSL_MAX_ERROR:
786
+            description = "The number of different SSL errors.";
787
+            break;
788
+          case SslError.SSL_NOTYETVALID:
789
+            description = "The certificate is not yet valid";
790
+            break;
791
+          case SslError.SSL_UNTRUSTED:
792
+            description = "The certificate authority is not trusted";
793
+            break;
794
+          default: 
795
+            description = "Unknown SSL Error";
796
+            break;
797
+        }
798
+
799
+        this.onReceivedError(
800
+          webView,
801
+          code,
802
+          description,
803
+          failingUrl
804
+        );
805
+    }
806
+
761 807
     @Override
762 808
     public void onReceivedError(
763 809
       WebView webView,