在 Java 密钥库中导入 pkcs12 (.p12) 客户端证书文件时,CertificateChain 为空

问题描述

我将带有证书链的 client-ssl-certificate KeyPair 导出为 PKCS12 文件密钥库资源管理器。我可以再次使用 KSE 加载这个 PKCS12 文件,并且密钥对和证书链都在那里。当我将它加载到 Java KeyStore 中时,我可以访问该密钥,但证书链为空。

这是我的代码:

        final KeyStore instance = KeyStore.getInstance( "pkcs12" );
        instance.load( new ByteArrayInputStream( bytes ),password );

        instance.getKey(alias,password) => returns Key
        instance.getCertificateChain(alias) => returns null

        final KeyStore.ProtectionParameter param = new KeyStore.PasswordProtection( password );
        final KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry) instance.getEntry( alias,param );

        => fails:

java.lang.NullPointerException: invalid null input
    at java.security.KeyStore$PrivateKeyEntry.<init>(KeyStore.java:524) ~[na:1.8.0_202]
    at sun.security.pkcs12.PKCS12KeyStore.engineGetEntry(PKCS12KeyStore.java:1311) ~[na:1.8.0_202]
    at java.security.KeyStore.getEntry(KeyStore.java:1521) ~[na:1.8.0_202]

通过调试我可以看到,PrivateKeyEntry 的构造函数是在链参数为空的情况下调用的:

image: debugging PrivateKeyEntry constructor call

我对此完全没有解释,也没有在互联网上找到任何信息。

我可以排除使用的别名和使用的密码作为原因。

我会感谢有关此主题的任何提示。

提前致谢,

亚历山大

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)