Situation: 我有一个Airwatch分期付款,它为客户提供存储在用户专用CA Store中的私有"User Certificates" . 在与指定的https Web服务器 Build SSL连接时,应使用证书 .

例如 . 当我尝试通过HTTPS和Chrome访问此Web服务器时,Chrome会找到客户端证书并询问我是否要使用它(所以不要直接使用) . 通过单击“确定”,我可以 Build 连接并查看站点 .

Problem 在"recent times"中,这可以通过向应用程序自身提供物理证书并在运行时加载(通过创建Keystore,Trustmanager和Custom SSLContext)在自定义应用程序中解决here

我用Android Nougat我可以摆脱"Workaround",只配置这个应用程序的证书所在的位置 . 它被称为网络安全配置,如此处所述https://developer.android.com/training/articles/security-config.html

所以我补充说:

android:networkSecurityConfig="@xml/network_security_config"

在Android Manifest中,添加了一个看起来像这样的XML

<network-security-config>
    <base-config>
        <!-- Trust ONLY the mydomain.com Domain and its Subdomains -->
       <domain includeSubdomains="true">mydomain.com</domain>
       <trust-anchors>
           <!-- Trust preinstalled CAs -->
            <certificates src="system"/>
            <!-- Additionally trust user added CAs -->
            <certificates src="user"/>
        </trust-anchors>
    </base-config>
</network-security-config>

我虽然使用HttpsURLConnection会在必要时自动使用用户证书 .

Current Situation: 我仍然得到这个:

javax.net.ssl.SSLHandshakeException: Handshake failed

Question:

1)我是否还需要创建自定义SSLContext并使用自定义密钥库注入自定义信任管理器?如果必须这样做,我如何获得用户证书?可以通过 KeyStore.getInstance("AndroidCAStore"); 轻松初始化Defautl系统CA但是如何从用户特定存储中获取密钥以在SSLContext中使用它们?

3)我在Web上没有找到任何示例如何使用HttpsConnection与存储在Android上的用户密钥库中的Nougat或更高版本的客户端证书,任何提示?