Android Central Keystore

前端 未结 2 1179
野趣味
野趣味 2021-02-14 17:34

I\'m hoping that there\'s a way to programmatically access a central trusted keystore on an Android device. I know one exists, at least for verifying SSL connections etc. which

2条回答
  •  轮回少年
    2021-02-14 18:08

    ICS (Android 4.0 / API 14) introduced the TrustedCertificateStore (not directly available in the SDK) that enables you to do exactly that. You can access it using the JCA Keystore api like this:

    /**
     * Android Central Keystore repo usually located on /data/misc/keychain 
     * including the system trusted anchors located on /system/etc/security
     */
    KeyStore keyStore = KetStore.getInstance("AndroidCAStore");
    keyStore.load(null, null); //Load default system keystore
    Enumeration keyAliases = keyStore.aliases();
    
    while(keyAliases.hasMoreElements()){
        String alias = keyAliases.nextElement();
        X509Certificate cert = (X509Certificate) keyStore.getCertificate(alias);
    
        //
    }
    

提交回复
热议问题