Search in sources :

Example 1 with SslCertificate

use of android.net.http.SslCertificate in project android_frameworks_base by ParanoidAndroid.

the class BrowserFrame method setCertificate.

/**
     * Called by JNI when we recieve a certificate for the page's main resource.
     * Used by the Chromium HTTP stack only.
     */
private void setCertificate(byte[] cert_der) {
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        X509Certificate cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(cert_der));
        mCallbackProxy.onReceivedCertificate(new SslCertificate(cert));
    } catch (Exception e) {
        // Can't get the certificate, not much to do.
        Log.e(LOGTAG, "Can't get the certificate from WebKit, canceling");
        return;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SslCertificate(android.net.http.SslCertificate) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) ParseException(android.net.ParseException) IOException(java.io.IOException) NotFoundException(android.content.res.Resources.NotFoundException)

Example 2 with SslCertificate

use of android.net.http.SslCertificate in project android_frameworks_base by ParanoidAndroid.

the class BrowserFrame method reportSslCertError.

/**
     * Called by JNI when the Chromium HTTP stack gets an invalid certificate chain.
     *
     * We delegate the request to CallbackProxy, and route its response to
     * {@link #nativeSslCertErrorProceed(int)} or
     * {@link #nativeSslCertErrorCancel(int, int)}.
     */
private void reportSslCertError(final int handle, final int certError, byte[] certDER, String url) {
    final SslError sslError;
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        X509Certificate cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(certDER));
        SslCertificate sslCert = new SslCertificate(cert);
        sslError = SslError.SslErrorFromChromiumErrorCode(certError, sslCert, url);
    } catch (Exception e) {
        // Can't get the certificate, not much to do.
        Log.e(LOGTAG, "Can't get the certificate from WebKit, canceling");
        nativeSslCertErrorCancel(handle, certError);
        return;
    }
    if (SslCertLookupTable.getInstance().isAllowed(sslError)) {
        nativeSslCertErrorProceed(handle);
        mCallbackProxy.onProceededAfterSslError(sslError);
        return;
    }
    SslErrorHandler handler = new SslErrorHandler() {

        @Override
        public void proceed() {
            SslCertLookupTable.getInstance().setIsAllowed(sslError);
            post(new Runnable() {

                public void run() {
                    nativeSslCertErrorProceed(handle);
                }
            });
        }

        @Override
        public void cancel() {
            post(new Runnable() {

                public void run() {
                    nativeSslCertErrorCancel(handle, certError);
                }
            });
        }
    };
    mCallbackProxy.onReceivedSslError(handler, sslError);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SslCertificate(android.net.http.SslCertificate) SslError(android.net.http.SslError) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) ParseException(android.net.ParseException) IOException(java.io.IOException) NotFoundException(android.content.res.Resources.NotFoundException)

Example 3 with SslCertificate

use of android.net.http.SslCertificate in project platform_frameworks_base by android.

the class SslCertificateTest method testSslCertificateWithEmptyIssuer.

@LargeTest
public void testSslCertificateWithEmptyIssuer() throws Exception {
    X509Certificate x509Certificate = generateCertificate(Issue1597Certificate);
    assertEquals("", x509Certificate.getSubjectDN().getName());
    SslCertificate sslCertificate = new SslCertificate(x509Certificate);
    assertEquals("", sslCertificate.getIssuedBy().getDName());
}
Also used : SslCertificate(android.net.http.SslCertificate) X509Certificate(java.security.cert.X509Certificate) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 4 with SslCertificate

use of android.net.http.SslCertificate in project WordPress-Android by wordpress-mobile.

the class SelfSignedSSLUtils method sslCertificateToX509.

public static X509Certificate sslCertificateToX509(@Nullable SslCertificate cert) {
    if (cert == null) {
        return null;
    }
    Bundle bundle = SslCertificate.saveState(cert);
    X509Certificate x509Certificate = null;
    byte[] bytes = bundle.getByteArray("x509-certificate");
    if (bytes == null) {
        AppLog.e(T.API, "Cannot load the SSLCertificate bytes from the bundle");
    } else {
        try {
            CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
            Certificate certX509 = certFactory.generateCertificate(new ByteArrayInputStream(bytes));
            x509Certificate = (X509Certificate) certX509;
        } catch (CertificateException e) {
            AppLog.e(T.API, "Cannot generate the X509Certificate with the bytes provided", e);
        }
    }
    return x509Certificate;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Bundle(android.os.Bundle) CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) SslCertificate(android.net.http.SslCertificate)

Example 5 with SslCertificate

use of android.net.http.SslCertificate in project android_frameworks_base by DirtyUnicorns.

the class SslCertificateTest method testSslCertificateWithEmptyIssuer.

@LargeTest
public void testSslCertificateWithEmptyIssuer() throws Exception {
    X509Certificate x509Certificate = generateCertificate(Issue1597Certificate);
    assertEquals("", x509Certificate.getSubjectDN().getName());
    SslCertificate sslCertificate = new SslCertificate(x509Certificate);
    assertEquals("", sslCertificate.getIssuedBy().getDName());
}
Also used : SslCertificate(android.net.http.SslCertificate) X509Certificate(java.security.cert.X509Certificate) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

SslCertificate (android.net.http.SslCertificate)20 X509Certificate (java.security.cert.X509Certificate)18 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 IOException (java.io.IOException)4 SslError (android.net.http.SslError)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 CertificateFactory (java.security.cert.CertificateFactory)3 NotFoundException (android.content.res.Resources.NotFoundException)2 ParseException (android.net.ParseException)2 X509CertImpl (org.apache.harmony.security.provider.cert.X509CertImpl)2 Context (android.content.Context)1 Bundle (android.os.Bundle)1 ValueCallback (android.webkit.ValueCallback)1 LinearLayout (android.widget.LinearLayout)1 Certificate (java.security.cert.Certificate)1 CertificateException (java.security.cert.CertificateException)1 CalledByNative (org.chromium.base.CalledByNative)1