How to remove App installed trusted CA cert on uninstalling the App(如何在卸载应用程序时删除应用程序安装的受信任 CA 证书)
问题描述
我有一个应用程序提供安装 CA 证书的选项,它存储在 Trusted Credentials 的用户选项卡中,并且按预期工作.
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.
仅供参考 (这是我安装证书的方式):
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.
我想过使用 删除证书KeyStore
的 deleteEntry 方法.
I thought of removing the cert using deleteEntry method of KeyStore
.
仅供参考 (虽然我还没有测试过.希望它应该可以工作.我会在测试后更新)
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.
我如何才能在卸载我的应用时删除我的应用安装的证书?
感谢任何帮助!
推荐答案
你无法为你自己的包获得卸载包的广播.这可能会导致系统不一致.看到这个答案
you cant get the broadcast of package getting uninstalled for your own package. this may lead to inconsistency in the system. see this answer
这篇关于如何在卸载应用程序时删除应用程序安装的受信任 CA 证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在卸载应用程序时删除应用程序安装的受信任 CA 证书
基础教程推荐
- 在螺旋中写一个字符串 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01