Skip to content

Commit 8aaae5b

Browse files
authored
apacheGH-292 android: SSL errors handling in Android (apache#293)
1 parent 2793e16 commit 8aaae5b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/android/InAppBrowser.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Licensed to the Apache Software Foundation (ASF) under one
3333
import android.graphics.PorterDuff;
3434
import android.graphics.PorterDuffColorFilter;
3535
import android.graphics.Color;
36+
import android.net.http.SslError;
3637
import android.net.Uri;
3738
import android.os.Build;
3839
import android.os.Bundle;
@@ -50,6 +51,7 @@ Licensed to the Apache Software Foundation (ASF) under one
5051
import android.webkit.CookieSyncManager;
5152
import android.webkit.HttpAuthHandler;
5253
import android.webkit.JavascriptInterface;
54+
import android.webkit.SslErrorHandler;
5355
import android.webkit.ValueCallback;
5456
import android.webkit.WebChromeClient;
5557
import android.webkit.WebResourceRequest;
@@ -1465,6 +1467,46 @@ public void onReceivedError(WebView view, int errorCode, String description, Str
14651467
}
14661468
}
14671469

1470+
@Override
1471+
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
1472+
super.onReceivedSslError(view, handler, error);
1473+
try {
1474+
JSONObject obj = new JSONObject();
1475+
obj.put("type", LOAD_ERROR_EVENT);
1476+
obj.put("url", error.getUrl());
1477+
obj.put("code", 0);
1478+
obj.put("sslerror", error.getPrimaryError());
1479+
String message;
1480+
switch (error.getPrimaryError()) {
1481+
case SslError.SSL_DATE_INVALID:
1482+
message = "The date of the certificate is invalid";
1483+
break;
1484+
case SslError.SSL_EXPIRED:
1485+
message = "The certificate has expired";
1486+
break;
1487+
case SslError.SSL_IDMISMATCH:
1488+
message = "Hostname mismatch";
1489+
break;
1490+
default:
1491+
case SslError.SSL_INVALID:
1492+
message = "A generic error occurred";
1493+
break;
1494+
case SslError.SSL_NOTYETVALID:
1495+
message = "The certificate is not yet valid";
1496+
break;
1497+
case SslError.SSL_UNTRUSTED:
1498+
message = "The certificate authority is not trusted";
1499+
break;
1500+
}
1501+
obj.put("message", message);
1502+
1503+
sendUpdate(obj, true, PluginResult.Status.ERROR);
1504+
} catch (JSONException ex) {
1505+
LOG.d(LOG_TAG, "Should never happen");
1506+
}
1507+
handler.cancel();
1508+
}
1509+
14681510
/**
14691511
* On received http auth request.
14701512
*/

0 commit comments

Comments
 (0)