Java Code Examples for android.security.KeyChain#getCertificateChain()

The following examples show how to use android.security.KeyChain#getCertificateChain() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidSslSocketFactoryFactory.java    From PresencePublisher with MIT License 6 votes vote down vote up
private KeyManager[] getClientKeyManagers(String clientCertAlias) {
    try {
        PrivateKey privateKey = KeyChain.getPrivateKey(context, clientCertAlias);
        X509Certificate[] certificateChain = KeyChain.getCertificateChain(context, clientCertAlias);
        KeyStore customKeyStore = KeyStore.getInstance("PKCS12");
        char[] pwdArray = Double.toString(Math.random()).toCharArray();
        customKeyStore.load(null, pwdArray);
        customKeyStore.setKeyEntry(clientCertAlias, privateKey, null, certificateChain);
        KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        keyManagerFactory.init(customKeyStore, pwdArray);
        return keyManagerFactory.getKeyManagers();
    } catch (Exception e) {
        HyperLog.w(TAG, "Unable to initialize client key store", e);
        return null;
    }
}
 
Example 2
Source File: XmppConnection.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public X509Certificate[] getCertificateChain(String alias) {
    Log.d(Config.LOGTAG, "getting certificate chain");
    try {
        return KeyChain.getCertificateChain(mXmppConnectionService, alias);
    } catch (Exception e) {
        Log.d(Config.LOGTAG, e.getMessage());
        return new X509Certificate[0];
    }
}
 
Example 3
Source File: XmppConnection.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
@Override
public X509Certificate[] getCertificateChain(String alias) {
    Log.d(Config.LOGTAG, "getting certificate chain");
    try {
        return KeyChain.getCertificateChain(mXmppConnectionService, alias);
    } catch (Exception e) {
        Log.d(Config.LOGTAG, e.getMessage());
        return new X509Certificate[0];
    }
}
 
Example 4
Source File: VpnProfile.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
private X509Certificate[] getKeyStoreCertificates(Context context) throws KeyChainException, InterruptedException {
    PrivateKey privateKey = KeyChain.getPrivateKey(context, mAlias);
    mPrivateKey = privateKey;


    X509Certificate[] caChain = KeyChain.getCertificateChain(context, mAlias);
    return caChain;
}