JAVA javax.net.ssl.SSLHandshakeException error when running standalone jar - java

I am using Netbeans 7.2 IDE with jdk 1.6. My application downloads a file from google drive. When I am running the application in IDE, the file is getting downloaded, but when I do "Clean & build" and run the standalone jar of the application it is giving me the following error:
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

This exception show app unable to find valid certification path to requested target,
You need to add the certificate for request target(google drive) to the truststore file of the used JVM located at
%JAVA_HOME%\lib\security\cacerts
Once you have the certificate in your hard drive you can import it to the Java trust store. To import the certificate to the trusted Java key store, you can use the java ‘keytool‘ tool.
Use keytool command as follows to import the certificate to JRE.

Related

PKIX building failed:sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I am running an application in Eclipse locally. It tries to connect to an external URL to fetch some data. This application works fine from browser, but when I try the same from Eclipse as localhost, I get the below error:
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:456)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:323)
at sun.security.validator.Validator.validate(Validator.java:271)
Many solutions, have mentioned to add the URL certificate from the browser using keytool. This application shows "This site does not have a certificate.". The application URL does not have a certificate.
In this case, how can I fix this issue without a certificate to install?
Regards,
R
looks like you are running any java based application on a web server(e.g. Tomcat) with HTTPS enabled.
If you donot have signed any self certificate, then following link can help:
How to configure Tomcat to support SSL or https
Further this link has discussed the matter in detail:
Stackoverflow Link

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException

Situation :
(1) I am on Android Studio 4.1 and trying to build a sample Android Application
(2) I am behind the Proxy and Proxy settings working fine as I am able to download and install SDKs
I am getting the below error : I tried all possible steps adding the certificates using keytool.exe
eg : keytool.exe -import -trustcacerts -alias androidstudiocerts -file dlgooglecom.cer -keystore "C:\Program Files\Android\Android Studio\jre\jre\lib\security\cacerts"
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:4.1.0.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:4.1.0.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.pom'.
> sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I wanted to know :
(1) In the Android Studio Settings we have an option for http then why it is taking "https" to probe the site?Why not http?
(2) SDK Manager works fine for downloading the sdks and related build tools.
(3) tried with 5-6 differernt gradle:4.X.X. versions , no effect
(3) There are several JAVA (one from android studio, another from Oracle JAVA : Program Files\Java\jdk-15.0.1) and I have added the certificates to both C:\Program Files\Android\Android Studio\jre\jre\lib\security\ as well as C:\Program Files\Java\jdk-15.0.1\lib\security but still the sam error
(4) Already restarted the PC and invalidated cache and Android Studio Restart - No effect
(5) Which Software part is throwing this error? JAVA or Android Studio or something else?
(6)Is there any other location where I can get the full detailed logs of this error?
And most important :
(7) How to fix this now?
This seems to be network issue, can you try adding certificate into android studio by navigating to android studio>settings>tools>Server Certificates> add .crt file and tick "Accept non-trusted certificates automatically" if you want it automatically accepting certificates.
After this try running app again.

Spring Boot Embedded Tomcat - Unable to find valid certification path

I have an interesting problem I have yet to find a solution for. I have a Spring Boot application that is attempting to connect to a 3rd party API. When I run this application locally using the embedded Tomcat server, attempts to connect to this 3rd party API fail with the following exception:
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://<third party API endpoint>": sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target;
nested exception is 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
I've imported the certificate for my 3rd party API into my local JDK's keystore and if I run this application on another application server like Weblogic then it executes as expected. I just can't seem to get the Spring Boot embedded Tomcat server to behave properly.
Any advice would be appreciated.
Turns out my issue was a missing 3rd level intermediate certificate that I need to get through my corporate firewall. In order to figure this out I enabled SSL debugging so I could find the missing certificate. I accomplished this by adding the following VM argument to my application:
-Djavax.net.debug=SSL
Once I saw there was a 3rd level certificate, I imported that certificate into my JDK and poof...problem solved.
Maybe check that your java_home and Java.exe in your path point to the same installation. Usually we have multiple jres and a lot of the time certs get installed into a different jre then being run. Maybe inspect the process and make sure it's using the same jre as has the certs (maybe even try jconsole to verify)

Google Analytics API java lib - certificate error

I am using this java library to extract GA data. But it is generating the following certificate error:
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
I verified that it is trying to establish connection with url https://lhr26s05-in-f13.1e100.net which outputs a certificate error when accessed through the browser. I'm surprised this is happening as this is a google owned domain.
I have tried to manually download the certificate and add it to the cacerts file but that didn't work.
I have also tried to trust the certificate like this which has worked on other projects, but not for this one. I wonder if this is not working because I am using the google api java libraries? I'm out of ideas and would appreciate any suggestions

Installing ValiCert Class 3 PKI (X.509) certificate in jre's keystore on Red Hat Linux

I have a web application deployed on Linux machine. Now, while generating pdf in web application I am getting following error:
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
It seems that ValiCert Class 3 PKI (X.509) certificate is missing in jre's keystore. Does anyone have an idea of how to download it on Linux? Please provide the steps or link where I can get the required information?
Thnaks in advance!

Categories

Resources