Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing all installed certificates on android

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:

  1. 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.

  2. 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.

like image 837
manish Avatar asked Dec 16 '10 06:12

manish


People also ask

How do I view all certificates?

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.

Where are CA certificates stored in Android?

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.

What happens if you remove all certificates on Android?

Removing all credentials will delete both the certificate you installed and those added by your device.

What are all the security certificates on my phone?

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.


1 Answers

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();     }                } 
like image 92
Durai Amuthan.H Avatar answered Oct 03 '22 17:10

Durai Amuthan.H