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 证书


- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 获取数字的最后一位 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 转换 ldap 日期 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01