Skip to content

Commit

Permalink
apacheGH-292 android: SSL errors handling in Android
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolashenry committed Sep 4, 2018
1 parent cf58b04 commit b591d2c
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 @@ -44,6 +45,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.HttpAuthHandler;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
Expand Down Expand Up @@ -1220,6 +1222,47 @@ 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());
switch (error.getPrimaryError()) {
case SslError.SSL_DATE_INVALID:
obj.put("message", "The date of the certificate is invalid");
break;
case SslError.SSL_EXPIRED:
obj.put("message", "The certificate has expired");
break;
case SslError.SSL_IDMISMATCH:
obj.put("message", "Hostname mismatch");
break;
default:
case SslError.SSL_INVALID:
obj.put("message", "A generic error occurred");
break;
case SslError.SSL_MAX_ERROR:
obj.put("message", "<SSL_MAX_ERROR>");
break;
case SslError.SSL_NOTYETVALID:
obj.put("message", "The certificate is not yet valid");
break;
case SslError.SSL_UNTRUSTED:
obj.put("message", "The certificate authority is not trusted");
break;
}

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 Expand Up @@ -1258,4 +1301,4 @@ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, Str
super.onReceivedHttpAuthRequest(view, handler, host, realm);
}
}
}
}

0 comments on commit b591d2c

Please sign in to comment.