javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

1.问题如何出现的?

使用httpclient访问https开头的url。

这个问题比较奇怪,并不是所有的https开头的都不能访问,比如https://www.baidu.com/ 就可以访问,不知道是不是这个网站的证书有问题。在有的服务器上,curl 这个网站会出现这个:

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

2. https://blog.****.net/kevin_mails/article/details/82143490 (感谢这位kevin_mails网友给我提供了思路)看到这篇文章之后,引发了我的测试。

我最开始用的是jdk1.8_181, 按照上篇文章所说应该什么也不用修改就是正常的,但是就是出了问题。然后我用jdk1.8_25、jdk1.8_144、jdk1.8_151、jdk1.8_162都是正常的(无需任何修改)。其中162和181的jdk1.8.0_162\jre\lib\security的java.security是最接近的,关于crypto.policy=unlimited这部分完全一样。

下面是两个java.security对比:有四个地方不一致

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

 

3. 问题解决:

实际上就是用162的java.security替换掉181的java.security就可以了,我是这样做的。

 

4.总结: 在网上可能搜到了一样的问题,但是解决办法却不一定适用于自己,希望这篇文章对大家有所帮助。