I am writing an app which lists all the certificates installed on the device. But I found that there are two places where certificates are stored:
System/etc/security/cacerts.bks: This file contains list of all pre-installed certificate. I am able to read this file using Keystore class defined in frameworks/ base/keystore/java/android/security.
data/misc/keystore: Another way to install certificates (e.g. through certinstaller app) installs third party certificate and makes its entry in this directory.
But I am not getting how to read certificate info like SerialNumber, IssuerDN etc. from this file.
To view certificates for the current userSelect Run from the Start menu, and then enter certmgr. msc. The Certificate Manager tool for the current user appears. To view your certificates, under Certificates - Current User in the left pane, expand the directory for the type of certificate you want to view.
Now we have to place our CA certificate inside the system certificate store located at /system/etc/security/cacerts/ in the Android filesystem. By default, the /system partition is mounted as read-only.
Removing all credentials will delete both the certificate you installed and those added by your device.
Related. Trusted secure certificates are used when connecting to secure resources from the Android operating system. These certificates are encrypted on the device and may be used for Virtual Private Networks, Wi-Fi and ad-hoc networks, Exchange servers, or other applications found in the device.
I use the below code snippet to list
public void PrintInstalledCertificates() { try { KeyStore ks = KeyStore.getInstance("AndroidCAStore"); if (ks != null) { ks.load(null, null); Enumeration<String> aliases = ks.aliases(); while (aliases.hasMoreElements()) { String alias = (String) aliases.nextElement(); java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate) ks.getCertificate(alias); //To print System Certs only if(cert.getIssuerDN().getName().contains("system")){ System.out.println(cert.getIssuerDN().getName()); } //To print User Certs only if(cert.getIssuerDN().getName().contains("user")){ System.out.println(cert.getIssuerDN().getName()); } //To print all certs System.out.println(cert.getIssuerDN().getName()); } } } catch (IOException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (java.security.cert.CertificateException e) { e.printStackTrace(); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With