Is there a possibility to check if a specific certificate is installed on an Android Device? For example a special company certificate?
Asked
Active
Viewed 1,215 times
1
-
ok after some more research it seems to be not possible. it should be possible with Android 4.0 ICS, but not with a lower version :( – Henry Jan 10 '12 at 15:47
1 Answers
1
I got it to work on a device with Android 5.1.1
.
Depending how you want to check if it is the certificate that you are looking for, you can choose any field and compare it. I went for the quick way of just checking the issuer distinguished name (DN).
private boolean isCertificateInstalled(String issuerDn) {
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init((KeyStore) null);
X509TrustManager xtm = (X509TrustManager) tmf.getTrustManagers()[0];
for (X509Certificate cert : xtm.getAcceptedIssuers()) {
if (cert.getIssuerDN().getName().contains(issuerDn)) {
return true;
}
}
} catch (NoSuchAlgorithmException | KeyStoreException e) {
// Handle exceptions
}
return false;
}
I took this solution from this answer that claims this should work also on pre IceCream Sandwich.