PKIX 路径构建失败:

Posted

技术标签:

【中文标题】PKIX 路径构建失败:【英文标题】:PKIX path building failed: 【发布时间】:2019-05-03 06:45:51 【问题描述】:

我收到 javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certificate path to requested target exception,如何解决这个问题?这是我的密钥库

KeyStore ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
                String pin = " ";
                ks.load(null, pin.toCharArray());





    Protocol myProtocol = new Protocol("https", new MySSLSockectFactory(), 443);
                                        httpclient.getHostConfiguration()
                                                .setHost("test.euniwizarde.com", 443, myProtocol);

                                        HostConfiguration hostConfiguration = httpclient.getHostConfiguration();
                                        String hostURL = hostConfiguration.getHostURL();
                                        System.out.println("hostURL============" + hostURL);

                                        BufferedReader br = null;
                                        setVisible(false);

                                        PostMethod postMethod = new PostMethod(hostURL);
                                        System.out.println("postmethod " + postMethod);
                                        postMethod.addParameter("userid", "" + userId);
                                        postMethod.addParameter("serialNumber", "" + serialNumber);
                                        postMethod.addParameter("name", "" + name);
                                        postMethod.addParameter("publicKey", "" + publicKey);
                                        postMethod.addParameter("dateOfIssue", "" + dateOfIssue);
                                        postMethod.addParameter("expiry", "" + expiryDate);
                                        postMethod.addParameter("issuer", "" + issuer);
                                        postMethod.addParameter("var", " " + var);
                                        postMethod.addParameter("siteName", "" + siteName);
                                        boolean requestSent = postMethod.isRequestSent();

                                        System.out.println("Is request Sent before execute method===="+ requestSent);
                                        try 
                                            int returnCode = httpclient.executeMethod(postMethod);

【问题讨论】:

【参考方案1】:

您需要将 SSL 证书添加到您的 java 密钥库。我假设您使用的是 Windows 机器。您需要在命令提示符下运行以下命令。

"%JAVA_HOME%\bin\keytool" -import -trustcacerts -keystore "%JAVA_HOME%\jre\lib\security\cacerts" -storepass changeit -alias CERTIFICATE -import -file CERTIFICATE.crt

【讨论】:

以上是关于PKIX 路径构建失败:的主要内容,如果未能解决你的问题,请参考以下文章

PKIX 路径构建失败:我将证书添加到 carcert 仍然失败

PKIX 路径构建失败:无法找到请求目标的有效证书路径

PKIX 路径构建失败:wso2 oauth

SSLHandshakeException:PKIX 路径构建失败 SunCertPathBuilderException:无法找到请求目标的有效证书路径

“PKIX 路径构建失败”和“无法找到请求目标的有效证书路径”

SSLHandshakeException:PKIX 路径构建失败