Search in sources :

Example 16 with KeyChainConnection

use of android.security.KeyChain.KeyChainConnection in project platform_frameworks_base by android.

the class DevicePolicyManagerService method installCaCert.

@Override
public boolean installCaCert(ComponentName admin, byte[] certBuffer) throws RemoteException {
    enforceCanManageCaCerts(admin);
    byte[] pemCert;
    try {
        X509Certificate cert = parseCert(certBuffer);
        pemCert = Credentials.convertToPem(cert);
    } catch (CertificateException ce) {
        Log.e(LOG_TAG, "Problem converting cert", ce);
        return false;
    } catch (IOException ioe) {
        Log.e(LOG_TAG, "Problem reading cert", ioe);
        return false;
    }
    final UserHandle userHandle = new UserHandle(UserHandle.getCallingUserId());
    final long id = mInjector.binderClearCallingIdentity();
    try {
        final KeyChainConnection keyChainConnection = KeyChain.bindAsUser(mContext, userHandle);
        try {
            keyChainConnection.getService().installCaCertificate(pemCert);
            return true;
        } catch (RemoteException e) {
            Log.e(LOG_TAG, "installCaCertsToKeyChain(): ", e);
        } finally {
            keyChainConnection.close();
        }
    } catch (InterruptedException e1) {
        Log.w(LOG_TAG, "installCaCertsToKeyChain(): ", e1);
        Thread.currentThread().interrupt();
    } finally {
        mInjector.binderRestoreCallingIdentity(id);
    }
    return false;
}
Also used : UserHandle(android.os.UserHandle) KeyChainConnection(android.security.KeyChain.KeyChainConnection) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) RemoteException(android.os.RemoteException) X509Certificate(java.security.cert.X509Certificate)

Example 17 with KeyChainConnection

use of android.security.KeyChain.KeyChainConnection in project android_packages_apps_Settings by omnirom.

the class TrustedCredentialsSettings method getX509CertsFromCertHolder.

@Override
public List<X509Certificate> getX509CertsFromCertHolder(CertHolder certHolder) {
    List<X509Certificate> certificates = null;
    try {
        KeyChainConnection keyChainConnection = mKeyChainConnectionByProfileId.get(certHolder.mProfileId);
        IKeyChainService service = keyChainConnection.getService();
        List<String> chain = service.getCaCertificateChainAliases(certHolder.mAlias, true);
        final int n = chain.size();
        certificates = new ArrayList<X509Certificate>(n);
        for (int i = 0; i < n; ++i) {
            byte[] encodedCertificate = service.getEncodedCaCertificate(chain.get(i), true);
            X509Certificate certificate = KeyChain.toCertificate(encodedCertificate);
            certificates.add(certificate);
        }
    } catch (RemoteException ex) {
        Log.e(TAG, "RemoteException while retrieving certificate chain for root " + certHolder.mAlias, ex);
    }
    return certificates;
}
Also used : IKeyChainService(android.security.IKeyChainService) KeyChainConnection(android.security.KeyChain.KeyChainConnection) RemoteException(android.os.RemoteException) X509Certificate(java.security.cert.X509Certificate)

Example 18 with KeyChainConnection

use of android.security.KeyChain.KeyChainConnection in project android_packages_apps_Settings by crdroidandroid.

the class TrustedCredentialsSettings method getX509CertsFromCertHolder.

@Override
public List<X509Certificate> getX509CertsFromCertHolder(CertHolder certHolder) {
    List<X509Certificate> certificates = null;
    try {
        KeyChainConnection keyChainConnection = mKeyChainConnectionByProfileId.get(certHolder.mProfileId);
        IKeyChainService service = keyChainConnection.getService();
        List<String> chain = service.getCaCertificateChainAliases(certHolder.mAlias, true);
        final int n = chain.size();
        certificates = new ArrayList<X509Certificate>(n);
        for (int i = 0; i < n; ++i) {
            byte[] encodedCertificate = service.getEncodedCaCertificate(chain.get(i), true);
            X509Certificate certificate = KeyChain.toCertificate(encodedCertificate);
            certificates.add(certificate);
        }
    } catch (RemoteException ex) {
        Log.e(TAG, "RemoteException while retrieving certificate chain for root " + certHolder.mAlias, ex);
    }
    return certificates;
}
Also used : IKeyChainService(android.security.IKeyChainService) KeyChainConnection(android.security.KeyChain.KeyChainConnection) RemoteException(android.os.RemoteException) X509Certificate(java.security.cert.X509Certificate)

Example 19 with KeyChainConnection

use of android.security.KeyChain.KeyChainConnection in project platform_packages_apps_Settings by BlissRoms.

the class TrustedCredentialsSettings method getX509CertsFromCertHolder.

@Override
public List<X509Certificate> getX509CertsFromCertHolder(CertHolder certHolder) {
    List<X509Certificate> certificates = null;
    try {
        KeyChainConnection keyChainConnection = mKeyChainConnectionByProfileId.get(certHolder.mProfileId);
        IKeyChainService service = keyChainConnection.getService();
        List<String> chain = service.getCaCertificateChainAliases(certHolder.mAlias, true);
        final int n = chain.size();
        certificates = new ArrayList<X509Certificate>(n);
        for (int i = 0; i < n; ++i) {
            byte[] encodedCertificate = service.getEncodedCaCertificate(chain.get(i), true);
            X509Certificate certificate = KeyChain.toCertificate(encodedCertificate);
            certificates.add(certificate);
        }
    } catch (RemoteException ex) {
        Log.e(TAG, "RemoteException while retrieving certificate chain for root " + certHolder.mAlias, ex);
    }
    return certificates;
}
Also used : IKeyChainService(android.security.IKeyChainService) KeyChainConnection(android.security.KeyChain.KeyChainConnection) RemoteException(android.os.RemoteException) X509Certificate(java.security.cert.X509Certificate)

Aggregations

RemoteException (android.os.RemoteException)19 KeyChainConnection (android.security.KeyChain.KeyChainConnection)19 IKeyChainService (android.security.IKeyChainService)13 X509Certificate (java.security.cert.X509Certificate)10 UserHandle (android.os.UserHandle)9 IOException (java.io.IOException)3 CertificateException (java.security.cert.CertificateException)3 ParcelableString (com.android.internal.util.ParcelableString)1