Search in sources :

Example 1 with TrustedCertificateStore

use of org.apache.harmony.xnet.provider.jsse.TrustedCertificateStore in project android_frameworks_base by ParanoidAndroid.

the class KeyChain method getCertificateChain.

/**
     * Returns the {@code X509Certificate} chain for the requested
     * alias, or null if no there is no result.
     *
     * @param alias The alias of the desired certificate chain, typically
     * returned via {@link KeyChainAliasCallback#alias}.
     * @throws KeyChainException if the alias was valid but there was some problem accessing it.
     */
public static X509Certificate[] getCertificateChain(Context context, String alias) throws KeyChainException, InterruptedException {
    if (alias == null) {
        throw new NullPointerException("alias == null");
    }
    KeyChainConnection keyChainConnection = bind(context);
    try {
        IKeyChainService keyChainService = keyChainConnection.getService();
        final byte[] certificateBytes = keyChainService.getCertificate(alias);
        if (certificateBytes == null) {
            return null;
        }
        TrustedCertificateStore store = new TrustedCertificateStore();
        List<X509Certificate> chain = store.getCertificateChain(toCertificate(certificateBytes));
        return chain.toArray(new X509Certificate[chain.size()]);
    } catch (RemoteException e) {
        throw new KeyChainException(e);
    } catch (RuntimeException e) {
        // only certain RuntimeExceptions can be propagated across the IKeyChainService call
        throw new KeyChainException(e);
    } finally {
        keyChainConnection.close();
    }
}
Also used : TrustedCertificateStore(org.apache.harmony.xnet.provider.jsse.TrustedCertificateStore) RemoteException(android.os.RemoteException) X509Certificate(java.security.cert.X509Certificate)

Example 2 with TrustedCertificateStore

use of org.apache.harmony.xnet.provider.jsse.TrustedCertificateStore in project XobotOS by xamarin.

the class KeyChain method getCertificateChain.

/**
     * Returns the {@code X509Certificate} chain for the requested
     * alias, or null if no there is no result.
     *
     * <p>This method requires the caller to hold the permission
     * {@link android.Manifest.permission#USE_CREDENTIALS}.
     *
     * @param alias The alias of the desired certificate chain, typically
     * returned via {@link KeyChainAliasCallback#alias}.
     * @throws KeyChainException if the alias was valid but there was some problem accessing it.
     */
public static X509Certificate[] getCertificateChain(Context context, String alias) throws KeyChainException, InterruptedException {
    if (alias == null) {
        throw new NullPointerException("alias == null");
    }
    KeyChainConnection keyChainConnection = bind(context);
    try {
        IKeyChainService keyChainService = keyChainConnection.getService();
        byte[] certificateBytes = keyChainService.getCertificate(alias);
        List<X509Certificate> chain = new ArrayList<X509Certificate>();
        chain.add(toCertificate(certificateBytes));
        TrustedCertificateStore store = new TrustedCertificateStore();
        for (int i = 0; true; i++) {
            X509Certificate cert = chain.get(i);
            if (Objects.equal(cert.getSubjectX500Principal(), cert.getIssuerX500Principal())) {
                break;
            }
            X509Certificate issuer = store.findIssuer(cert);
            if (issuer == null) {
                break;
            }
            chain.add(issuer);
        }
        return chain.toArray(new X509Certificate[chain.size()]);
    } catch (RemoteException e) {
        throw new KeyChainException(e);
    } catch (RuntimeException e) {
        // only certain RuntimeExceptions can be propagated across the IKeyChainService call
        throw new KeyChainException(e);
    } finally {
        keyChainConnection.close();
    }
}
Also used : TrustedCertificateStore(org.apache.harmony.xnet.provider.jsse.TrustedCertificateStore) ArrayList(java.util.ArrayList) RemoteException(android.os.RemoteException) X509Certificate(java.security.cert.X509Certificate)

Aggregations

RemoteException (android.os.RemoteException)2 X509Certificate (java.security.cert.X509Certificate)2 TrustedCertificateStore (org.apache.harmony.xnet.provider.jsse.TrustedCertificateStore)2 ArrayList (java.util.ArrayList)1