Example usage for android.net.http SslError getCertificate

List of usage examples for android.net.http SslError getCertificate

Introduction

In this page you can find the example usage for android.net.http SslError getCertificate.

Prototype

public SslCertificate getCertificate() 

Source Link

Document

Gets the SSL certificate associated with this object.

Usage

From source file:com.cerema.cloud2.ui.dialog.SslUntrustedCertDialog.java

public static SslUntrustedCertDialog newInstanceForEmptySslError(SslError error, SslErrorHandler handler) {
    if (error == null) {
        throw new IllegalArgumentException("Trying to create instance with parameter error == null");
    }//from ww w  .  j  av a2s. co m
    if (handler == null) {
        throw new IllegalArgumentException("Trying to create instance with parameter handler == null");
    }
    SslUntrustedCertDialog dialog = new SslUntrustedCertDialog();
    dialog.mHandler = handler;
    dialog.mErrorViewAdapter = new SslErrorViewAdapter(error);
    dialog.mCertificateViewAdapter = new SslCertificateViewAdapter(error.getCertificate());
    return dialog;
}

From source file:android.core.TestEventHandler.java

/**
 * SSL certificate error callback. Handles SSL error(s) on the way
 * up to the user.//from w ww . j av  a  2 s . c o m
 */
public boolean handleSslErrorRequest(SslError error) {
    int primaryError = error.getPrimaryError();

    if (false) {
        Log.v(LOGTAG, "TestEventHandler: handleSslErrorRequest(): " + " primary error:" + primaryError
                + " certificate: " + error.getCertificate());
    }

    eventsReceived[TEST_SSL_CERTIFICATE_ERROR] = true;
    if (notExpecting[TEST_SSL_CERTIFICATE_ERROR]) {
        expectDetails.append("SSL Certificate error event received " + "but not expected");
        expectDetails.append("\r\n");
    }

    if (expectSslErrors != -1) {
        if (expectSslErrors == primaryError) {
            expectSslErrors = -1;
        } else {
            expectDetails
                    .append("SslCertificateError id expected:" + expectSslErrors + " got: " + primaryError);
            expectDetails.append("\r\n");
        }
    }

    // SslCertificate match here?

    if (expectSslErrors == -1) // && expectSslCertificate == certificate?
        expects[TEST_SSL_CERTIFICATE_ERROR] = false;

    // return false so that we won't block the thread
    return false;
}

From source file:com.mb.android.MainActivity.java

public void handleSslError(SslError error, final Response<Boolean> response) {

    final Context context = this;
    SslCertificate cert = error.getCertificate();

    String issuedTo = cert.getIssuedTo().getDName();
    String issuedBy = cert.getIssuedBy().getDName();
    String issuedOn = cert.getValidNotBeforeDate().toString();

    final String srch = error.getUrl() + "--" + issuedTo + "--" + issuedBy + "--" + issuedOn;
    final String results = getSharedPreferences(this).getString("acurls1", "");

    if (StringHelper.IndexOfIgnoreCase(results, srch) != -1) {
        response.onResponse(true);/*from  w w w .jav  a2 s .com*/
        return;
    }

    final AlertDialog.Builder builder = new AlertDialog.Builder(this);

    String message = getResources().getString(R.string.notification_error_ssl_cert_invalid)
            .replace("{0}", issuedTo.replace("localhost", "Emby Server"))
            .replace("{1}", issuedBy.replace("localhost", "Emby Server")).replace("{2}", issuedOn);

    builder.setMessage(message);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            SharedPreferences settings = getSharedPreferences(context);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString("acurls1", results + "|" + srch);
            // Commit the edits!
            boolean saved = editor.commit();

            response.onResponse(true);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            response.onResponse(false);
        }
    });
    final AlertDialog dialog = builder.create();
    dialog.show();
}

From source file:android.webkit.LoadListener.java

/**
 * SSL certificate error callback. Handles SSL error(s) on the way up
 * to the user./*  w  ww.  j a  va2 s.c  o m*/
 * IMPORTANT: as this is called from network thread, can't call native
 * directly
 */
public void handleSslErrorRequest(SslError error) {
    if (Config.LOGV) {
        Log.v(LOGTAG, "LoadListener.handleSslErrorRequest(): url:" + url() + " primary error: "
                + error.getPrimaryError() + " certificate: " + error.getCertificate());
    }

    if (!mCancelled) {
        mSslError = error;
        Network.getInstance(mContext).handleSslErrorRequest(this);
    }
}