android - 列出存储在用户凭据中的证书

标签 android ssl pkcs#12 android-7.0-nougat android-7.1-nougat

在 Android 7 Nougat 中,用户安装的证书转到“用户凭据”而不是“受信任的凭据”(由系统凭据和用户凭据组成)。

我曾经通过以下方式访问“受信任的凭据”:

KeyStore keystore = KeyStore.getInstance("AndroidCAStore");

通过上面的代码,我可以访问系统和用户信任的凭据。

但现在,在 Android 7 中,用户安装的证书会转到 Settings --> Security --> User credentials 下一个名为“用户凭据”的单独位置。

我的问题是如何在 Android 7 中以编程方式列出 User credentials 内的凭据?

最佳答案

为了在整个 Android 生态系统中提供更一致和更安全的体验,从 Android Nougat 开始,兼容设备仅信任在 AOSP 中维护的标准化系统 CA .

以前,与系统 bundle 的 预安装 CA 集可能因设备而异。如果某些设备不包含应用程序连接所需的 CA,这可能会导致兼容性问题,如果包含不符合我们安全要求的 CA,则可能会导致潜在的安全问题一些设备。

First, be sure that your CA needs to be included in the system. The preinstalled CAs are only for CAs that meet our security requirements because they affect the secure connections of most apps on the device. If you need to add a CA for connecting to hosts that use that CA, you should instead customize your apps and services that connect to those hosts. For more information on Customizing trusted CAs.

在上面link您可以找到信任具有不同需求的自定义 CA 的所有必要信息,例如

  1. 信任自定义 CA 进行调试
  2. 信任域的自定义 CA
  3. 信任某些域的用户添加 CA
  4. 信任用户添加的所有域(部分域除外)的 CA
  5. 信任用户添加的 CA 以确保所有安全连接

所以,基本上你需要添加一个 Security Configuration FileConfigure a custom CA (适用于 Android 7.0(API 级别 24)及更高版本)。

在您的 ma​​nifest.xml

<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config"
                    ... >
        ...
    </application>
</manifest>

res/xml/network_security_config.xml:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config>
        <domain includeSubdomains="true">example.com</domain>
        <trust-anchors>
            <certificates src="@raw/my_ca"/>
        </trust-anchors>
    </domain-config>
</network-security-config>

仅供引用:- 如果您操作一个您认为应该包含在 Android 中的 CA,请先填写 Mozilla CA Inclusion Process然后归档 feature request针对 Android 将 CA 添加到标准化的系统 CA 集中。

如果有任何进一步的帮助,请告诉我。

希望这会对您有所帮助。继续编码!!!

关于android - 列出存储在用户凭据中的证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40363553/

相关文章:

ssl - 有没有办法强制 WSO2 API Manager 接受不受信任的证书?

google-chrome - 忘记 Chrome 将哪个客户端证书用于 URL

java - 无法将 .p12 证书导入 cacerts

c# - 将自定义根 CA 与 HttpClient 结合使用

python - 我如何/可以使用 python 和加密模块生成 PKCS#12 文件?

java - 如何将Base64编码的pkcs12内容转换为java.security.PrivateKey?

java - 如何将项目导入Android Studio

Android 在测试期间信任自签名证书

android - 如何更新 Android Studio Beta channel

java - StartActivity 突然停止启动另一个 Activity