4

Java 8 的一个 SNI 的 bug

 2 years ago
source link: https://www.boris1993.com/others/java-8-sni-bug.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Java 8 的一个 SNI 的 bug

发表于

2021-11-24 分类于 其他

Waline: 0 阅读次数: 3 Changyan: 0 Disqus: 0 Comments

联动上一篇博文,在解决了 OpenResty 上那个 SNI 的问题之后,我们发现有一个 Java 应用也有类似的问题。而最后发现,这是因为我们当前版本的 Java 中有一个 bug……

简单来说,就是在 Java 1.8u141 之前,HttpsURLConnection#setDefaultHostnameVerifier() 方法会破坏 SNI,而正好我们的代码里有这么一行:

HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);

翻了下框架的代码,发现如果我不设定这个值,框架也调用这个方法来指定它默认的 hostname verifier;而如果我传个 null,那么它会抛个异常给我。所以,代码层面没有很方便的解决方案。

无奈,最后决定,先临时换了个没开启 SNI 的域名,暂时解决掉问题,然后升级 Java 到 1.8u181,一劳永逸。


终于,我也有机会理直气壮地喊出 “这是 Java 的 bug” 了!(笑

如果我的博客帮到了你,那么可不可以请我喝一杯咖啡?

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK