Skip to content

Commit

Permalink
GH-292 android: SSL errors handling in Android (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolashenry committed May 8, 2020
1 parent 2793e16 commit 8aaae5b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Color;
import android.net.http.SslError;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
Expand All @@ -50,6 +51,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.webkit.CookieSyncManager;
import android.webkit.HttpAuthHandler;
import android.webkit.JavascriptInterface;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
Expand Down Expand Up @@ -1465,6 +1467,46 @@ public void onReceivedError(WebView view, int errorCode, String description, Str
}
}

@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
try {
JSONObject obj = new JSONObject();
obj.put("type", LOAD_ERROR_EVENT);
obj.put("url", error.getUrl());
obj.put("code", 0);
obj.put("sslerror", error.getPrimaryError());
String message;
switch (error.getPrimaryError()) {
case SslError.SSL_DATE_INVALID:
message = "The date of the certificate is invalid";
break;
case SslError.SSL_EXPIRED:
message = "The certificate has expired";
break;
case SslError.SSL_IDMISMATCH:
message = "Hostname mismatch";
break;
default:
case SslError.SSL_INVALID:
message = "A generic error occurred";
break;
case SslError.SSL_NOTYETVALID:
message = "The certificate is not yet valid";
break;
case SslError.SSL_UNTRUSTED:
message = "The certificate authority is not trusted";
break;
}
obj.put("message", message);

sendUpdate(obj, true, PluginResult.Status.ERROR);
} catch (JSONException ex) {
LOG.d(LOG_TAG, "Should never happen");
}
handler.cancel();
}

/**
* On received http auth request.
*/
Expand Down

0 comments on commit 8aaae5b

Please sign in to comment.