【问题标题】:Java rejects ssl certificate, but Firefox accepts itJava 拒绝 ssl 证书,但 Firefox 接受它
【发布时间】:2015-11-26 20:31:07
【问题描述】:

我有这个代码:

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 接受,是否可以添加证书?

【问题讨论】:

  • 大多数时候它缺少证书链中的证书。或者 Java 中不包含的 CA。如果您打算在现场运行此程序,则仅将 CA 证书添加到本地 cacerts 可能是一种选择。但首先检查该证书及其链(可以在 Firefox 中进行)
  • 该证书也显示了我的移动 chrome 中的问题。

标签: java firefox ssl https


【解决方案1】:

如果您使用SSLLabs 分析此站点,它看起来基本没问题。但其中一项信息可能很重要:

此站点仅适用于支持 SNI 的浏览器。

如果您使用的软件不支持Server Name Indication (SNI),它将改为返回 www.re-publica.de 的证书,并且也无法包含必要的中间证书。因此验证失败。

我的猜测是您使用的 Java 版本尚不支持 SNI(如 Java 6)。

另一个选项是未安装必要的根 CA。此证书的最终信任锚是 StartCom 证书颁发机构,您可以下载 here

【讨论】:

    猜你喜欢
    • 2014-10-03
    • 2016-09-16
    • 2012-06-29
    • 1970-01-01
    • 2016-10-18
    • 2018-12-13
    • 2014-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多