PKIX 路径构建失败:找不到证书

问题描述 投票:0回答:2

我已将新证书添加到我的密钥库中,当我运行我的应用程序时,它尝试使用 CertificateMessage 类中的方法 checkServerCerts 从 TrustStore 读取证书,它始终反映相同的证书,并且计数始终为 7,即使我向我的应用程序添加了新证书阴谋。我的问题是信任库从哪个位置读取并获取证书。

java x509certificate
2个回答
0
投票

它们默认存储在

<JAVA_HOME>/lib/security/cacerts
中。
使用
<JAVA_HOME>/bin
文件夹中的 keytool 来管理它。


0
投票

我使用了下面的代码,它对我有用。您也需要对 KeyStore 执行相同的操作

FileInputStream myKeys = new FileInputStream("C:\\certs\\TrustStore.jks");

// Do the same with your trust store this time
// Adapt how you load the keystore to your needs
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
// Using null here initialises the TMF with the default trust store.
tmf.init((KeyStore) null);

KeyStore myTrustStore = KeyStore.getInstance(KeyStore.getDefaultType());
myTrustStore.load(myKeys, "password".toCharArray());

myKeys.close();

tmf = TrustManagerFactory
        .getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(myTrustStore);

return tmf.getTrustManagers()[0];
© www.soinside.com 2019 - 2024. All rights reserved.