Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error?

后端 未结 22 2484
名媛妹妹
名媛妹妹 2020-11-21 05:59

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

Here is the original issue.

22条回答
  •  名媛妹妹
    2020-11-21 06:12

    for safety we should not use self signed certificates in our implementation. However, when it comes to development often we have to use trial environments which got self-signed certs. I tried to fix this issue programmatically in my code and I fail. However, by adding the cert to the jre trust-store fixed my issue. Please find below steps,

    1. Download the site cert,

      • Using Chrome
      • Using Firefox
    2. Copy the certificate(ex:cert_file.cer) into the directory $JAVA_HOME\Jre\Lib\Security

    3. Open CMD in Administrator and change the directory to $JAVA_HOME\Jre\Lib\Security

    4. Import the certificate to a trust store using below command,

    keytool -import -alias ca -file cert_file.cer -keystore cacerts -storepass changeit

    If you got a error saying keytool is not recognizable please refer this.

    Type yes like below

    Trust this certificate: [Yes]

    1. Now try to run your code or access the URL programmatically using java.

    Update

    If your app server is jboss try adding below system property

    System.setProperty("org.jboss.security.ignoreHttpsHost","true");
    

    Hope this helps!

提交回复
热议问题