我有这个代码:
URL url = new URL("https://berlinbuzzwords.de/sites/berlinbuzzwords.de/files/media/documents/julien_nioche-low_latency_scalable_web_crawling_on_apache_storm.pdf");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.connect();
它失败了
Exception in thread "main" 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
我知道我可以将证书添加到 JVM 并解决这个问题,但是 Firefox 接受这个 url,甚至说它是安全的。那么,为什么会这样呢?如果 Firefox 接受,是否可以添加证书?
最佳答案
如果您使用 SSLLabs 分析此站点它看起来大部分都很好。但其中一个信息可能很重要:
This site works only in browsers with SNI support.
如果您使用不支持 Server Name Indication (SNI) 的软件相反,它将返回 www.re-publica.de 的证书,并且也没有包含必要的中间证书。因此验证失败。
我的猜测是您使用的 Java 版本尚不支持 SNI(如 Java 6)。
另一种选择是未安装必要的根 CA。此证书的最终信任 anchor 是 StartCom 证书颁发机构,您可以下载它 here .
关于Java 拒绝 ssl 证书,但 Firefox 接受它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33946553/