且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法通过Java代码连接到服务器。获取javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure

更新时间:2021-07-24 05:51:32

我是新来的放心,但是像我这样的java SSL问题code> handshake_failure 通常是相同的:

I am new to rest-assured, but the java SSL problems like handshake_failure are usually the same:


  • 不兼容的密码套件:客户端必须使用由服务器启用的密码套件

  • SSL / TLS的不兼容版本:客户端必须确保它使用兼容版本。例如,服务器可能强制在java7中默认未启用的TLS1.2

  • 服务器证书的不完整信任路径:服务器证书可能不受客户端信任。通常,修复方法是将服务器证书链导入客户端信任库。

  • 错误的服务器配置,例如发给不同域或证书链的证书不完整。如果修复程序在服务器部分上

  • Incompatible cipher suites: The client has to use a cipher suite enabled by the server
  • Incompatible versions of SSL/TLS: The client have to ensure that it uses a compatible version. For example the server might force TLS1.2 that is not enabled by default in java7
  • Incomplete trust path for the server certificate: the server certificate is probably not trusted by the client. Usually the fix is to import the server certificate chain in into the client trust store.
  • Bad server config, like certificate issued to a different domain or certificate chain incomplete. In the case the fix is on server part

要检测原因,可以设置以下环境变量来详细说明协议详细信息

To detect the cause the following environment variable can be set to verbose the protocol details

-Djavax.net.debug=ssl

针对您在SSL方面的具体问题,请查看放心的ssl文档 https://github.com/rest-assured/rest-assured/wiki/Usage#ssl

For your specific issue with SSL, take a look at rest assured ssl documentation https://github.com/rest-assured/rest-assured/wiki/Usage#ssl

首先你可以尝试禁用通常的https验证

First you can try to disable usual https verification

given().relaxedHTTPSValidation().when().get("https://some_server.com"). .. 

如果可行,请使用服务器的证书创建一个JKS信任库

If it works, create a JKS truststore with the certificates of the server

1)从服务器下载它们(点击浏览器绿色锁并下载每个)
2)用keytool创建JKS并导入可信证书。请遵循放心指南中的指南或使用 portecle
3)在JKS中配置信任库

1)Download them from the server (click on browser green lock and download each one) 2) Create the JKS with keytool and import the trusted certificates. Follow the guide in rest-assured guide or use portecle 3) Configure truststore in JKS

given().keystore("/pathToJksInClassPath", <password>). .. 

如果您需要客户端身份验证(我认为没有),请查看此帖子如何使用证书进行HTTPS GET调用Rest-Assured java

If you need client authentication ( I think no), check this post How to make HTTPS GET call with certificate in Rest-Assured java

如果这对您没有任何帮助,请不要忘记用

If nothing of this works for you, do not forget todebug the SSL connection with

 -Djavax.net.debug=ssl

确保客户端支持您的服务器算法。例如,如果使用Java7,则默认情况下不启用TLS1.2

Ensure that the algorithm of your server is supported by your client. For example if you use Java7, TLS1.2 is not enabled by default