Search in sources :

Example 6 with X509CertImpl

use of org.apache.harmony.security.provider.cert.X509CertImpl in project XobotOS by xamarin.

the class AbstractSessionContext method toSession.

/**
     * Creates a session from the given bytes.
     *
     * @return a session or null if the session can't be converted
     */
SSLSession toSession(byte[] data, String host, int port) {
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    DataInputStream dais = new DataInputStream(bais);
    try {
        int type = dais.readInt();
        if (type != OPEN_SSL) {
            log(new AssertionError("Unexpected type ID: " + type));
            return null;
        }
        int length = dais.readInt();
        byte[] sessionData = new byte[length];
        dais.readFully(sessionData);
        int count = dais.readInt();
        X509CertImpl[] certs = new X509CertImpl[count];
        for (int i = 0; i < count; i++) {
            length = dais.readInt();
            byte[] certData = new byte[length];
            dais.readFully(certData);
            certs[i] = new X509CertImpl(certData);
        }
        return new OpenSSLSessionImpl(sessionData, host, port, certs, this);
    } catch (IOException e) {
        log(e);
        return null;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) X509CertImpl(org.apache.harmony.security.provider.cert.X509CertImpl) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 7 with X509CertImpl

use of org.apache.harmony.security.provider.cert.X509CertImpl in project XobotOS by xamarin.

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 {
        X509Certificate cert = new X509CertImpl(certDER);
        SslCertificate sslCert = new SslCertificate(cert);
        sslError = SslError.SslErrorFromChromiumErrorCode(certError, sslCert, url);
    } catch (IOException 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);
            nativeSslCertErrorProceed(handle);
        }

        @Override
        public void cancel() {
            nativeSslCertErrorCancel(handle, certError);
        }
    };
    mCallbackProxy.onReceivedSslError(handler, sslError);
}
Also used : SslCertificate(android.net.http.SslCertificate) SslError(android.net.http.SslError) X509CertImpl(org.apache.harmony.security.provider.cert.X509CertImpl) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate)

Example 8 with X509CertImpl

use of org.apache.harmony.security.provider.cert.X509CertImpl in project XobotOS by xamarin.

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 {
        X509Certificate cert = new X509CertImpl(cert_der);
        mCallbackProxy.onReceivedCertificate(new SslCertificate(cert));
    } catch (IOException e) {
        // Can't get the certificate, not much to do.
        Log.e(LOGTAG, "Can't get the certificate from WebKit, canceling");
        return;
    }
}
Also used : SslCertificate(android.net.http.SslCertificate) X509CertImpl(org.apache.harmony.security.provider.cert.X509CertImpl) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate)

Aggregations

IOException (java.io.IOException)8 X509CertImpl (org.apache.harmony.security.provider.cert.X509CertImpl)8 X509Certificate (java.security.cert.X509Certificate)7 Signature (java.security.Signature)4 Certificate (java.security.cert.Certificate)4 BerInputStream (org.apache.harmony.security.asn1.BerInputStream)4 ContentInfo (org.apache.harmony.security.pkcs7.ContentInfo)4 SignedData (org.apache.harmony.security.pkcs7.SignedData)4 SignerInfo (org.apache.harmony.security.pkcs7.SignerInfo)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 SslCertificate (android.net.http.SslCertificate)2 RandomAccessFile (java.io.RandomAccessFile)2 BigInteger (java.math.BigInteger)2 GeneralSecurityException (java.security.GeneralSecurityException)2 MessageDigest (java.security.MessageDigest)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 PublicKey (java.security.PublicKey)2 SignatureException (java.security.SignatureException)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2