Search in sources :

Example 6 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 7 with SslCertificate

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

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 8 with SslCertificate

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

the class SslCertificateTest method testSslCertificateWithMultipleCN.

@LargeTest
public void testSslCertificateWithMultipleCN() throws Exception {
    X509Certificate x509Certificate = generateCertificate(Issue41662Certificate);
    String dn = x509Certificate.getSubjectDN().getName();
    assertTrue(dn, dn.contains("Posta CA 1"));
    assertTrue(dn, dn.contains("Configuration"));
    SslCertificate sslCertificate = new SslCertificate(x509Certificate);
    assertEquals(dn, "Posta CA 1", sslCertificate.getIssuedTo().getCName());
}
Also used : SslCertificate(android.net.http.SslCertificate) X509Certificate(java.security.cert.X509Certificate) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 9 with SslCertificate

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

the class SslCertificateTest method testSslCertificateWithMultipleCN.

@LargeTest
public void testSslCertificateWithMultipleCN() throws Exception {
    X509Certificate x509Certificate = generateCertificate(Issue41662Certificate);
    String dn = x509Certificate.getSubjectDN().getName();
    assertTrue(dn, dn.contains("Posta CA 1"));
    assertTrue(dn, dn.contains("Configuration"));
    SslCertificate sslCertificate = new SslCertificate(x509Certificate);
    assertEquals(dn, "Posta CA 1", sslCertificate.getIssuedTo().getCName());
}
Also used : SslCertificate(android.net.http.SslCertificate) X509Certificate(java.security.cert.X509Certificate) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 10 with SslCertificate

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

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