javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException 错误

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException error

我们正在使用 Google 的 recaptch 并导入相应的证书(使用 java 应用程序)后,我们仍然有错误:

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

我们正在使用 JDK_1.7.51 和 Tomcat8.

我们列出了证书,可以看到证书存在并且有效,即使这样我们仍然有之前提到的异常:

Alias name: google.com Creation date: 7-aug-2017 Entry type: trustedCertEntry

Owner: CN=www.google.com, O=Google Inc, L=Mountain View, ST=California, C=US Issuer: C=DE, CN=AXA-DE-Proxy-Issuing-CA17, OU=IF-NDSG, O=AXA Technology Services Germany GmbH Serial number: d21265bf38c9faf8d615fbbf840aaa1fc6959dc5bbff60a48f77e355fa2eac07bccb6c6d

Valid from: Wed Jul 12 14:25:22 CEST 2017 until: Wed Oct 04 13:57:00 CEST 2017

Certificate fingerprints: MD5: 52:73:92:40:38:DF:AB:2B:ED:5B:19:10:00:1D:57:7C SHA1: 76:F8:DC:99:CD:07:F8:81:4F:E5:48:C3:F4:4F:71:46:24:CE:F3:54 SHA256: 9B:72:1F:69:85:4C:AD:20:39:16:D4:7A:12:62:0D:8B:03:EC:8B:2F:E8:FD:40:FA:2E:D2:0E:F3:6A:1F:34:59 Signature algorithm name: SHA256withRSA Version: 3

有人可以帮我吗?

您的客户端位于防火墙后面并通过代理执行 HTTPS 请求,该代理为正在联系的站点动态生成 SSL 证书,以便窃听正在交换的数据。您可以看到您正在检查的 "Google-certificate" 的发行人:

Issuer: C=DE, CN=AXA-DE-Proxy-Issuing-CA17, OU=IF-NDSG, O=AXA Technology Services Germany

Java 有自己的根 CA 密钥库,标准证书检查正在寻找受信任的根 CA,而你的窃听者的根证书显然在那里丢失了。

要消除此错误并让 java 客户端错误地认为证书是由受信任的 CA 签署的,您需要 add the CAs root certificate to the root keystore of Java. Another solution is to establish the SSL-connection using your own TrustManager. You do that by using your own SSLContext where you set trust- and keymanagers yourself.

前者需要在每次 Java 安装时完成,后者在应用程序中运行。