My company uses its own PKI. The web browser which I use to access to code repository shows a certificate chain as follows:
Company Root CA
Company Issuing CA Intranet Server
Certificate to the code repository that I want to access
However, when I try to access to the repository using Gradle, I get a
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
error.
Gradle uses JVM. I have exported the "Company Root CA" certificate and added it to the certificate store of the JVM with the following command:
"%JAVA_HOME%\bin\keytool.exe" -import -alias company_root_cacert -file "C:\path\to\company\root\cacert.cer" -keystore "%JAVA_HOME%\jre\lib\security\cacerts" -storepass changeit
However, this did not solve the issue. I additionally exported the "Company Issuing CA Intranet Server" certificate and added it to the certificate store of the JVM with the following command:
"%JAVA_HOME%\bin\keytool.exe" -import -alias company_intermediate_cacert -file "C:\path\to\company\intermediate\cacert.cer" -keystore "%JAVA_HOME%\jre\lib\security\cacerts" -storepass changeit
This has solved the issue.
My question is, why was the second step necessary? Since the "Company Issuing CA Intranet Server" is signed by "Company Root CA", and since I have "Company Root CA" in the list of certificates trusted by JVM, why did I need to additionally add the "Company Issuing CA Intranet Server" certificate to the certificate store of JVM?