I have an app that gives option to install CA cert and it gets stored in the user tab of Trusted Credentials and it works as expected.
FYI (This is how I install the cert):
Intent installIntent = KeyChain.createInstallIntent();
javax.security.cert.X509Certificate x509 = javax.security.cert.X509Certificate.getInstance(caRootCertBytes);
installIntent.putExtra(KeyChain.EXTRA_CERTIFICATE, x509.getEncoded());
installIntent.putExtra(KeyChain.EXTRA_NAME,caRootCertName);
startActivity(installIntent);
If the app is uninstalled the cert remains in the Trusted credentials.
I would like the cert to be uninstalled when the application is uninstalled.
I thought of removing the cert using deleteEntry method of KeyStore
.
FYI (I haven't tested though.Hopefully it should work..I will update once I tested it)
javax.security.cert.X509Certificate x509 = javax.security.cert.X509Certificate.getInstance(caRootCertBytes);
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);
String name = x509.getIssuerDN().getName();
if (cert.getIssuerDN().getName().contains(name))
{
ks. deleteEntry(alias)
}
}
}
Even though if you consider above code works AFAIK I can't register broadcast receiver for uninstallation of my own app.
How can I go about removing the cert that is installed by my app on uninstallation of my app ?
Any help is appreciated !
Press Windows Key + R Key together, type certmgr. msc, and hit enter. You will get a new window with the list of Certificates installed on your computer. Locate the certificate you want to delete and then click on the Action button then, click on Delete.
What is CAcert? CAcert.org is a community-driven Certificate Authority that issues certificates to the public at large for free. CAcert's goal is to promote awareness and education on computer security through the use of encryption, specifically by providing cryptographic certificates.
you cant get the broadcast of package getting uninstalled for your own package. this may lead to inconsistency in the system. see this answer
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