How to Fix SunCertPathBuilderException: Unable to Find Valid Certification Path to Requested Target Error in Java
-
What Is the
sun.security.provider.certpath.SunCertPathBuilderException
in Java -
Causes of
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
-
Solution of
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Today’s post will discuss potential reasons for unable to find valid certification path to requested target
and its solution in Java.
But, before we continue, you must clearly understand SSL encryption and Certificates since a clear understanding of SSL Certificates is required.
SSL encryption and Certificates: an HTTPS connection cannot function properly without an SSL certificate. Through the use of a set of public and private keys, it substantiates the claimed identity of the service or website.
The private key encrypts or signs everything that is delivered by the domain, and the client apps validate the identification by utilizing the public keys.
What Is the sun.security.provider.certpath.SunCertPathBuilderException
in Java
The sun.security.provider.certpath.SunCertPathBuilderException
is a class for handling exceptions in Java that checks the server’s SSL certificates that the Java program is attempting to connect to. This class was named after the provider that created the certificates.
The following is the error message shown to the developer when they encounter this issue.
Caused by : sun.security.provider.certpath.SunCertPathBuilderException
: unable to find valid certification path to requested target
It can be thrown during any action involving visiting an encrypted service using SSL.
SSL-protected APIs and websites are checked for trustworthiness by the Java framework before they can be accessed. This is accomplished by examining its internal trusted list to see whether the root certificate authority signed is in there.
Java throws this error if it can’t discover any reference to the service. Using a self-signed certificate to access a service signed by someone else’s digital signature will always fail.
Causes of sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
The only way Java will be able to connect to another program via SSL is if it can trust HTTPS, etc. There is a truststore usually $JAVA HOME/lib/security/cacerts
in the Java world where you store your trust certificates.
This exception is triggered by a self-signed certificate or a certificate chain that does not exist in the Java trust store. Java refuses to connect to the application because it does not trust the certificate.
Solution of sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
-
To begin, determine whether the issue stems from the certificate or the network. To verify this, open the URL in Google Chrome or your preferred browser and see whether it works.
In this case, an invalid certificate setting on the application client must be the source of the exception. There may be a firewall or network settings issue if the browser cannot access it.
-
Get the server’s SSL Certificate after determining if there’s an issue with the certificate settings. This might be the root certificate in the simplest of circumstances, but in most cases, a certificate chain and intermediate certificate authority are required.
You can check SSL Certificate validity by following the below steps.
-
Open your browser and click on the lock in the left upper corner.
-
Then click on
Connection is secure
. -
At last, you will get the site’s status if it’s valid.
- If you want certificate details exported, follow the below steps.
-
Select the lock symbol next to the URL bar, then click the
Connection is secure
>Certificate is valid
. -
Click on the
Details
section and export a certificate by clicking on theCopy to File
button. -
Export
DER
encoded binaries. -
Choose the directory where you want to save and name the file.
-
When you click
Finish
, you’ll see a messageThe export was successful
.
-
Start a trust store entry with a new certificate. The key tool utility can be used to do this.
Execute the following command to create a new trust store.
keytool - import - file C :\cascerts\firstCA.cert - alias firstCA - Keystore myTrustStore
-
Restart your program to complete the process.
I have been working as a Flutter app developer for a year now. Firebase and SQLite have been crucial in the development of my android apps. I have experience with C#, Windows Form Based C#, C, Java, PHP on WampServer, and HTML/CSS on MYSQL, and I have authored articles on their theory and issue solving. I'm a senior in an undergraduate program for a bachelor's degree in Information Technology.
LinkedInRelated Article - Java SSL
Related Article - Java Error
- How to Fix the Error: Failed to Create the Java Virtual Machine
- How to Fix the Missing Server JVM Error in Java
- How to Fix the 'No Java Virtual Machine Was Found' Error in Eclipse
- How to Fix Javax.Net.SSL.SSLHandShakeException: Remote Host Closed Connection During Handshake
- How to Fix the Error: Failed to Create the Java Virtual Machine
- How to Fix Java.Lang.VerifyError: Bad Type on Operand Stack