Java Code Examples for android.net.http.SslError#getPrimaryError()

The following examples show how to use android.net.http.SslError#getPrimaryError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebViewActivity.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) {
    int primaryError = error.getPrimaryError();
    String url = error.getUrl();
    SslCertificate cert = error.getCertificate();
    mLogger.warning("onReceivedSslError: error = " + primaryError
            + ", url = " + url + ", certificate = " + cert);

    if (primaryError == SslError.SSL_UNTRUSTED && url != null && cert != null) {
        SslCertificate.DName subjectName = cert.getIssuedTo();
        if (subjectName != null
                && "localhost".equals(subjectName.getCName())
                && url.startsWith("https://localhost") ) {
            handler.proceed();
            mLogger.warning("SSL Proceeded: url = " + url);
            return;
        }
    }
    handler.cancel();
    mLogger.severe("SSL Canceled: url = " + url);
}
 
Example 2
Source File: WebViewFragment.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
    Date today = new Date();
    today.setTime(System.currentTimeMillis());
    if(error.getPrimaryError() == SslError.SSL_DATE_INVALID ||
            error.getPrimaryError() == SslError.SSL_IDMISMATCH ||
            error.getPrimaryError() == SslError.SSL_INVALID ||
            error.getPrimaryError() == SslError.SSL_UNTRUSTED) {
        handler.cancel();
    }
    else {
        handler.proceed();
    }
}
 
Example 3
Source File: WebViewActivity.java    From checkey with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
    String host = uri.getHost();
    int errno = error.getPrimaryError();
    if (host.equals("androidobservatory.org")
            && (errno == SslError.SSL_EXPIRED || errno == SslError.SSL_UNTRUSTED)) {
        handler.proceed();
    } else {
        super.onReceivedSslError(view, handler, error);
    }
}
 
Example 4
Source File: InAppBrowser.java    From cordova-plugin-inappbrowser with Apache License 2.0 5 votes vote down vote up
@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();
}