Search in sources :

Example 6 with TrustedCertificateIndex

use of com.android.org.conscrypt.TrustedCertificateIndex in project platform_frameworks_base by android.

the class ResourceCertificateSource method ensureInitialized.

private void ensureInitialized() {
    synchronized (mLock) {
        if (mCertificates != null) {
            return;
        }
        Set<X509Certificate> certificates = new ArraySet<X509Certificate>();
        Collection<? extends Certificate> certs;
        InputStream in = null;
        try {
            CertificateFactory factory = CertificateFactory.getInstance("X.509");
            in = mContext.getResources().openRawResource(mResourceId);
            certs = factory.generateCertificates(in);
        } catch (CertificateException e) {
            throw new RuntimeException("Failed to load trust anchors from id " + mResourceId, e);
        } finally {
            IoUtils.closeQuietly(in);
        }
        TrustedCertificateIndex indexLocal = new TrustedCertificateIndex();
        for (Certificate cert : certs) {
            certificates.add((X509Certificate) cert);
            indexLocal.index((X509Certificate) cert);
        }
        mCertificates = certificates;
        mIndex = indexLocal;
        mContext = null;
    }
}
Also used : ArraySet(android.util.ArraySet) InputStream(java.io.InputStream) TrustedCertificateIndex(com.android.org.conscrypt.TrustedCertificateIndex) 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)

Example 7 with TrustedCertificateIndex

use of com.android.org.conscrypt.TrustedCertificateIndex in project android_frameworks_base by AOSPA.

the class ResourceCertificateSource method ensureInitialized.

private void ensureInitialized() {
    synchronized (mLock) {
        if (mCertificates != null) {
            return;
        }
        Set<X509Certificate> certificates = new ArraySet<X509Certificate>();
        Collection<? extends Certificate> certs;
        InputStream in = null;
        try {
            CertificateFactory factory = CertificateFactory.getInstance("X.509");
            in = mContext.getResources().openRawResource(mResourceId);
            certs = factory.generateCertificates(in);
        } catch (CertificateException e) {
            throw new RuntimeException("Failed to load trust anchors from id " + mResourceId, e);
        } finally {
            IoUtils.closeQuietly(in);
        }
        TrustedCertificateIndex indexLocal = new TrustedCertificateIndex();
        for (Certificate cert : certs) {
            certificates.add((X509Certificate) cert);
            indexLocal.index((X509Certificate) cert);
        }
        mCertificates = certificates;
        mIndex = indexLocal;
        mContext = null;
    }
}
Also used : ArraySet(android.util.ArraySet) InputStream(java.io.InputStream) TrustedCertificateIndex(com.android.org.conscrypt.TrustedCertificateIndex) 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)

Example 8 with TrustedCertificateIndex

use of com.android.org.conscrypt.TrustedCertificateIndex in project android_frameworks_base by ResurrectionRemix.

the class ResourceCertificateSource method ensureInitialized.

private void ensureInitialized() {
    synchronized (mLock) {
        if (mCertificates != null) {
            return;
        }
        Set<X509Certificate> certificates = new ArraySet<X509Certificate>();
        Collection<? extends Certificate> certs;
        InputStream in = null;
        try {
            CertificateFactory factory = CertificateFactory.getInstance("X.509");
            in = mContext.getResources().openRawResource(mResourceId);
            certs = factory.generateCertificates(in);
        } catch (CertificateException e) {
            throw new RuntimeException("Failed to load trust anchors from id " + mResourceId, e);
        } finally {
            IoUtils.closeQuietly(in);
        }
        TrustedCertificateIndex indexLocal = new TrustedCertificateIndex();
        for (Certificate cert : certs) {
            certificates.add((X509Certificate) cert);
            indexLocal.index((X509Certificate) cert);
        }
        mCertificates = certificates;
        mIndex = indexLocal;
        mContext = null;
    }
}
Also used : ArraySet(android.util.ArraySet) InputStream(java.io.InputStream) TrustedCertificateIndex(com.android.org.conscrypt.TrustedCertificateIndex) 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)

Example 9 with TrustedCertificateIndex

use of com.android.org.conscrypt.TrustedCertificateIndex in project android_frameworks_base by ResurrectionRemix.

the class KeyStoreCertificateSource method ensureInitialized.

private void ensureInitialized() {
    synchronized (mLock) {
        if (mCertificates != null) {
            return;
        }
        try {
            TrustedCertificateIndex localIndex = new TrustedCertificateIndex();
            Set<X509Certificate> certificates = new ArraySet<>(mKeyStore.size());
            for (Enumeration<String> en = mKeyStore.aliases(); en.hasMoreElements(); ) {
                String alias = en.nextElement();
                X509Certificate cert = (X509Certificate) mKeyStore.getCertificate(alias);
                if (cert != null) {
                    certificates.add(cert);
                    localIndex.index(cert);
                }
            }
            mIndex = localIndex;
            mCertificates = certificates;
        } catch (KeyStoreException e) {
            throw new RuntimeException("Failed to load certificates from KeyStore", e);
        }
    }
}
Also used : ArraySet(android.util.ArraySet) TrustedCertificateIndex(com.android.org.conscrypt.TrustedCertificateIndex) KeyStoreException(java.security.KeyStoreException) X509Certificate(java.security.cert.X509Certificate)

Example 10 with TrustedCertificateIndex

use of com.android.org.conscrypt.TrustedCertificateIndex in project android_frameworks_base by crdroidandroid.

the class KeyStoreCertificateSource method ensureInitialized.

private void ensureInitialized() {
    synchronized (mLock) {
        if (mCertificates != null) {
            return;
        }
        try {
            TrustedCertificateIndex localIndex = new TrustedCertificateIndex();
            Set<X509Certificate> certificates = new ArraySet<>(mKeyStore.size());
            for (Enumeration<String> en = mKeyStore.aliases(); en.hasMoreElements(); ) {
                String alias = en.nextElement();
                X509Certificate cert = (X509Certificate) mKeyStore.getCertificate(alias);
                if (cert != null) {
                    certificates.add(cert);
                    localIndex.index(cert);
                }
            }
            mIndex = localIndex;
            mCertificates = certificates;
        } catch (KeyStoreException e) {
            throw new RuntimeException("Failed to load certificates from KeyStore", e);
        }
    }
}
Also used : ArraySet(android.util.ArraySet) TrustedCertificateIndex(com.android.org.conscrypt.TrustedCertificateIndex) KeyStoreException(java.security.KeyStoreException) X509Certificate(java.security.cert.X509Certificate)

Aggregations

ArraySet (android.util.ArraySet)10 TrustedCertificateIndex (com.android.org.conscrypt.TrustedCertificateIndex)10 X509Certificate (java.security.cert.X509Certificate)10 InputStream (java.io.InputStream)5 KeyStoreException (java.security.KeyStoreException)5 Certificate (java.security.cert.Certificate)5 CertificateException (java.security.cert.CertificateException)5 CertificateFactory (java.security.cert.CertificateFactory)5