即使信任存储中的根证书,java 也会引发 SSLHandshakeException

lov*_*soa 3 java ssl

下面的java代码:

new URL("https://www.limagrain.com/").openStream()
Run Code Online (Sandbox Code Playgroud)

引发以下错误:

javax.net.ssl.SSLHandshakeException thrown: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Run Code Online (Sandbox Code Playgroud)

但是,该站点使用的根证书(Thawte Primary Root CA - G3)存在于 java 的信任存储中,并且该站点在浏览器中显示没有问题。

Qualys SSL checker上检查该站点会给出有关标记为extra download的中间证书的警告。

如何让java自动下载中间证书?

lov*_*soa 5

解决方案

将系统属性设置com.sun.security.enableAIAcaIssuerstrue.

System.setProperty("com.sun.security.enableAIAcaIssuers", "true");
Run Code Online (Sandbox Code Playgroud)

请参阅 Oracle 的 Java PKI 指南:https : //docs.oracle.com/javase/7/docs/technotes/guides/security/certpath/CertPathProgGuide.html#AppB