PKIX path building failed when running Teamprise-ant task - java

I am having an xml which will connect to tfs through https connection to get latest files from it. I am trying to run this as ant task invoked from my java scheduler. When i try to invoke it I am getting the following error message :
An error occurred: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
But if i invoke the ant task from a bat file directly, it is working fine without any issues.
Kindly help me out on how to handle the execption when invoking from java

These steps, based on Oracle instructions, worked for me:
Get InstallCert.java (the link in Oracle's instructions is broken)
Compile and execute java InstallCert [host]:[port]
enter '1'
Copy and rename the newly created jssecacerts file as %JAVA_HOME%\jre\lib\security\cacerts (backup the original, just in case)
Rerun Ant, it should not complain about certificate anymore
There may be other solutions as well.

Related

Problem with certificate while trying to compile with Gradle

I've been desperately trying to use ROS2 and PX4, but I can't compile all of the necessary packages: Fast-RTPS-Gen
For people to know PX4:
I am using Gradle version 6.3 installed with sdk, as explained on the PX4 website.
I have download the version 1.0.4 from the Fast-RTPS-Gen repository
When I try to compile it with Gradle, I have a certificate (see end of question).
My question is: how can I bypass this? Since I'm not gonna develop anything on Java, I just really need this one thing to compile, I'm really interested in the quickest, dirtiest way I can bypass this certificate check.
I have tried adding a certificate from the Maven repo with keystool but I just can't get it to work.
> Task :buildIDLParser FAILED
FAILURE: Build failed with an exception.
* Where:
Build file '/home/evandro/Fast-RTPS-Gen/thirdparty/idl-parser/idl.gradle' line: 89
* What went wrong:
Could not determine the dependencies of task ':idl-parser:jar'.
> Could not resolve all files for configuration ':idl-parser:compile'.
> Could not resolve org.antlr:antlr4:4.5.
Required by:
project :idl-parser
> Could not resolve org.antlr:antlr4:4.5.
> Could not get resource 'https://repo.maven.apache.org/maven2/org/antlr/antlr4/4.5/antlr4-4.5.pom'.
> Could not GET 'https://repo.maven.apache.org/maven2/org/antlr/antlr4/4.5/antlr4-4.5.pom'.
> 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 org.antlr:antlr4:4.5.
Required by:
project :idl-parser
> Could not resolve org.antlr:antlr4:4.5.
> Could not get resource 'https://repo.maven.apache.org/maven2/org/antlr/antlr4/4.5/antlr4-4.5.pom'.
> Could not GET 'https://repo.maven.apache.org/maven2/org/antlr/antlr4/4.5/antlr4-4.5.pom'.
> 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 org.antlr:stringtemplate:3.2.
Required by:
project :idl-parser
> Could not resolve org.antlr:stringtemplate:3.2.
> Could not get resource 'https://repo.maven.apache.org/maven2/org/antlr/stringtemplate/3.2/stringtemplate-3.2.pom'.
> Could not GET 'https://repo.maven.apache.org/maven2/org/antlr/stringtemplate/3.2/stringtemplate-3.2.pom'.
> sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.4/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 653ms
4 actionable tasks: 2 executed, 2 up-to-date
As far as I am aware, it is not possible to disable JVM cert validation by configuration. As you are getting a cert validation failure for https://repo.maven.apache.org, which should not happen on most systems, I am going to guess that you are behind a corporate firewall.
If you are on Windows, try setting the environment variable JAVA_TOOL_OPTIONS to (exactly):
-Djavax.net.ssl.trustStoreType=Windows-ROOT -Djavax.net.ssl.trustStore=NUL
If you are on Mac, try setting it to:
-Djavax.net.ssl.trustStoreType=KeychainStore -Djavax.net.ssl.trustStore=/dev/null
If none of those work, you can copy the existing keystore of your JVM, and add your corporate certs to it using keytool, which is easy enough to look up with Google. In this case you would use these settings in the env var:
-Djavax.net.ssl.trustStore=/my/trust_store -Djavax.net.ssl.trustStorePassword=my_password
Managed to solve it by compiling with sudo:
sudo env "PATH=$PATH" gradle assemble
Took me the whole day since I know nothing about gradle, and it ended up just being a stupid simple solution. I proposed to add this as a note on the PX4 install guide.

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)

AEM 6.5 PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException

I have been struggling with getting AEM instances to work with the certs/keys generated by a trusted source. I am following the /libs/granite/security/content/sslConfig.html wizard and AEM tells me everything is configured properly. I then try going to access my instance over https in my browser (incognito window) on my new port and my certificate is recognized by my browser. Finally I go to my replication agent on Author and update the configuration to use the same exact https URL/Port I just tested in my browser that worked minutes before and a simple test of that newly updated agent spits out the following error message:
Replication test failed
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I have double checked the ssl-service and can see my cert/key is correctly installed there.
If anyone has an idea why the replication agent is acting this way and how to fix it I'm open to suggestions.
Thanks
Is it a local cert? Look at the Transport tab, then choose Relaxed. Let me know if that helps.

How to fix java.security.cert.CertPathValidatorException: timestamp check failed

My mac has a TFS build agent connecting to a TFS server. That works fine. But when fetching the source code it fails with the following error:
An error occurred: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: timestamp check failed
When I on the mac, remove the old certificate for the TFS server from the Java Truststore I get the following error:
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
If I add a new certificate for the server, into the Java truststore (the cacerts file) with good new valid time stamps, I get this error:
PKIX path validation failed: java.security.cert.CertPathValidatorException: timestamp check failed
Thus, I know that I am making changes to the correct cacerts file, since I'am getting different output based on the two scenarios above.
I've been scanning through the cacert file, trying to find if any expired cert for the TFS server is still there. Can't find any.
I've tried importing both the root cert and the site cert, but no difference there.
No problems connecting to the server site with Safari or using curl. The certificate on the server is renewed and has valid timestamps.
Any help would be greatly appreciated.
I managed to get by the issue by installing a brand new, latest version build agent.

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

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.

Categories

Resources