Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

java - 解决javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败错误?(Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error?)

Edit :- Tried to format the question and accepted answer in more presentable way at mine Blog

(编辑:-试图在我的博客上以更恰当的方式设置问题和接受的答案的格式)

Here is the original issue.

(这是原始问题。)

I am getting this error:

(我收到此错误:)

detailed message sun.security.validator.ValidatorException: PKIX path building failed:

(详细消息sun.security.validator.ValidatorException:PKIX路径构建失败:)
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

(sun.security.provider.certpath.SunCertPathBuilderException:无法找到到请求目标的有效证书路径)

cause 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

(导致javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:找不到指向所请求目标的有效证书路径)

I am using Tomcat 6 as webserver.

(我正在使用Tomcat 6作为Web服务器。)

I have two HTTPS web applications installed on different Tomcats on different ports but on the same machine.

(我有两个HTTPS Web应用程序安装在不同端口上但在同一台机器上的不同Tomcat上。)

Say App1(port 8443) and App2(port 443) .

(说出App1(port 8443)App2(port 443) 。)

App1 connects to App2 .

(App1连接到App2 。)

When App1 connects to App2 I get the above error.

(当App1连接到App2 ,出现上述错误。)

I know this is a very common error so came across many solutions on different forums and sites.

(我知道这是一个非常常见的错误,因此在不同的论坛和站点上遇到了许多解决方案。)

I have the below entry in server.xml of both Tomcats:

(我在两个Tomcat的server.xml中都有以下条目:)

keystoreFile="c:/.keystore" 
keystorePass="changeit"

Every site says the same reason that certificate given by app2 is not in the trusted store of app1 jvm.

(每个站点都表示由app2颁发的证书不在app1 jvm的受信任存储区中的相同原因。)

This seems to be true also when I tried to hit the same URL in IE browser, it works (with warming, There is a problem with this web site's security certificate. Here I say continue to this website).

(当我尝试在IE浏览器中命中相同的URL时,这似乎也是正确的(正常运行,此网站的安全证书有问题。在这里我说继续浏览此网站)。)

But when same URL is hit by Java client (in my case) I get the above error.

(但是,当Java客户端(在我的情况下)击中相同的URL时,会出现上述错误。)

So to put it in the truststore I tried these three options:

(因此,将其放入信任库中,我尝试了以下三个选项:)

Option1

(选项1)

System.setProperty("javax.net.ssl.trustStore", "C:/.keystore");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");

Option2 Setting below in environment variable

(Option2在环境变量中进行以下设置)

CATALINA_OPTS -- param name
-Djavax.net.ssl.trustStore=C:.keystore -Djavax.net.ssl.trustStorePassword=changeit ---param value

Option3 Setting below in environment variable

(Option3在环境变量中进行以下设置)

JAVA_OPTS -- param name
-Djavax.net.ssl.trustStore=C:.keystore -Djavax.net.ssl.trustStorePassword=changeit ---param value

But nothing worked .

(但是没有任何效果 。)

What at last worked is executing the Java approach suggested in How to handle invalid SSL certificates with Apache HttpClient?

(最后执行的工作是执行如何使用Apache HttpClient处理无效的SSL证书中建议的Java方法)

by Pascal Thivent ie executing the program InstallCert.

(由Pascal Thivent编写,即执行程序InstallCert。)

But this approach is fine for devbox setup but I can not use it at production environment.

(但是这种方法对于devbox设置来说很好,但是我不能在生产环境中使用它。)

I am wondering why three approaches mentioned above did not work when I have mentioned the same values in server.xml of app2 server and same values in truststore by setting

(我想知道为什么我通过设置app2 server.xml的相同值和truststore中的相同值时上述三种方法不起作用)

System.setProperty("javax.net.ssl.trustStore", "C:/.keystore") and System.setProperty("javax.net.ssl.trustStorePassword", "changeit");

in app1 program.

(在app1程序中。)

For more information this is how I am making the connection:

(有关更多信息,这是我进行连接的方式:)

URL url = new URL(urlStr);

URLConnection conn = url.openConnection();

if (conn instanceof HttpsURLConnection) {

  HttpsURLConnection conn1 = (HttpsURLConnection) url.openConnection();

  conn1.setHostnameVerifier(new HostnameVerifier() {
    public boolean verify(String hostname, SSLSession session) {
      return true;
    }
  });

  reply.load(conn1.getInputStream());
  ask by M Sach translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to add the certificate for App2 to the truststore file of the used JVM located at %JAVA_HOME%\lib\security\cacerts .

(您需要将App2的证书添加到位于%JAVA_HOME%\lib\security\cacerts的使用的JVM的信任库文件中。)

First you can check if your certificate is already in the truststore by running the following command: keytool -list -keystore "%JAVA_HOME%/jre/lib/security/cacerts" (you don't need to provide a password)

(首先,您可以通过运行以下命令来检查证书是否已在信任库中: keytool -list -keystore "%JAVA_HOME%/jre/lib/security/cacerts" (您无需提供密码))

If your certificate is missing, you can get it by downloading it with your browser and add it to the truststore with the following command:

(如果您的证书丢失,可以通过使用浏览器下载证书并将其添加到信任库中,使用以下命令:)

keytool -import -noprompt -trustcacerts -alias <AliasName> -file <certificate> -keystore <KeystoreFile> -storepass <Password>

After import you can run the first command again to check if your certificate was added.

(导入后,您可以再次运行第一个命令以检查是否已添加证书。)

Sun/Oracle information can be found here .

(可在此处找到Sun / Oracle信息。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...