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

后端 未结 22 2317
名媛妹妹
名媛妹妹 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:25

    For MacOS X below is the exact command worked for me where I had to try with double hypen in 'importcert' option which worked :

    sudo keytool -–importcert -file /PathTo/YourCertFileDownloadedFromBrowserLockIcon.crt -keystore /Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/security/cacerts -alias "Cert" -storepass changeit
    
    0 讨论(0)
  • 2020-11-21 06:29

    I want to chime in since I have a QEMU environment where I have to download files in java. It turns out the /etc/ssl/certs/java/cacerts in QEMU does have problem because it does not match the /etc/ssl/certs/java/cacerts in the host environment. The host environment is behind a company proxy so the java cacerts is a customized version.

    If you are using a QEMU environment, make sure the host system can access files first. For example you can try this script on your host machine first to see. If the script runs just fine in host machine but not in QEMU, then you are having the same problem as me.

    To solve this issue, I had to make a backup of the original file in QEMU, copy over the file in host environment to the QEMU chroot jail, and then java could download files normally in QEMU.

    A better solution would be mount the /etc into the QEMU environment; however I am not sure if other files will get impacted in this process. So I decided to use this ugly but easy work-around.

    0 讨论(0)
  • 2020-11-21 06:29

    Just a small hack. Update the URL in the file "hudson.model.UpdateCenter.xml" from https to http

    <?xml version='1.1' encoding='UTF-8'?>
    <sites>
      <site>
        <id>default</id>
        <url>http://updates.jenkins.io/update-center.json</url>
      </site>
    </sites>
    
    0 讨论(0)
  • 2020-11-21 06:29

    add this to your code :

    TrustManager[] trustAllCerts = new TrustManager[]{
               new X509TrustManager() {
                   @Override
                   public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                       return new X509Certificate[0];
                   }
    
                   @Override
                   public void checkClientTrusted(
                           java.security.cert.X509Certificate[] certs, String authType) {
                   }
    
                   @Override
                   public void checkServerTrusted(
                           java.security.cert.X509Certificate[] certs, String authType) {
                   }
               }
           };
    
           try {
               SSLContext sc = SSLContext.getInstance("SSL");
               sc.init(null, trustAllCerts, new java.security.SecureRandom());
               HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
           } catch (GeneralSecurityException e) {
           }
    
    0 讨论(0)
提交回复
热议问题