Java 建立SSL主机连接时无法使用已签名的证书验证Cacerts

Java 建立SSL主机连接时无法使用已签名的证书验证Cacerts,java,ssl,sslhandshakeexception,Java,Ssl,Sslhandshakeexception,我已经创建了一个带有自定义密钥库和自定义CA的自定义cacerts。 我刚刚收到下面的异常消息 javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification

我已经创建了一个带有自定义密钥库和自定义CA的自定义cacerts。 我刚刚收到下面的异常消息

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) ~[?:1.7.0_45]
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1884) ~[?:1.7.0_45]
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276) ~[?:1.7.0_45]
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270) ~[?:1.7.0_45]
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341) ~[?:1.7.0_45]
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153) ~[?:1.7.0_45]
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868) ~[?:1.7.0_45]
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:804) ~[?:1.7.0_45]
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016) ~[?:1.7.0_45]
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312) ~[?:1.7.0_45]
    at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:702) ~[?:1.7.0_45]
    at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122) ~[?:1.7.0_45]
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) ~[?:1.7.0_45]
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) ~[?:1.7.0_45]

例外情况只是说明自定义密钥库中服务器端的证书链中的一个证书未正确颁发/签名,或者不是放置在客户端的自定义cacerts文件的一部分。由于链中存在不受信任的证书,SSL握手由于缺少正确/良好的证书路径而失败。 要了解此问题的根本原因,请尝试以PEM编码格式提取所有中间产物、根证书和私钥证书,然后运行以下命令

请注意,以下内容完全依赖于服务器上安装的OpenSSL。(运行openssl版本-a以显示它是否是服务器的一部分)

根据提示提供密码,避免在命令中传递密码

现在使用下面的命令提取证书。 openssl pkcs12-输入customKeystore_pkcs.p12-节点-输出pvtkey_hostORdns_cert.pem 使用相同的keytool实用程序签出新生成的PKCS12密钥库

keytool-list-v-keystore customKeystore_pkcs.p12-storetype pkcs12

您还可以使用查看此文件


opensslx509-通知PEM-在pvtkey\u hostORdns\u cert.PEM-noout-text中

您可以共享java属性配置文件吗?错误消息不是这样说的。它不必验证
cacerts
,它必须验证证书。它并不意味着任何这样的事情。
openssl verify -verbose -CAfile <(cat ServerCA1.pem ServerCA2.pem RootCA.pem)
pvtkey_hostORdns_cert.pem
keytool -importkeystore -srckeystore customeKeystore.jks -destkeystore customKeystore_pkcs.p12 -srcstoretype JKS - deststoretype PKCS12