0

I'm using JSOUP to connect to a web page and get some content via web scraping method. Everything seems to work fine for months but recently this error started to appear.

ERROR: javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I've added the certificate of the web page (downloaded the certificate from chrome explorer, base64 cer) and added to my java cacert using this command

keytool -import -alias certificatebase64-2 -keystore "C:\Program Files\Java\jdk-11.0.10\lib\security\cacerts" -file certificate-base64.cer

I've also installed the certificate in my windows machine, since in this machine is where the java app is running, using certificate windows assistant right click on the certificate -> install certificate -> local machine -> and manually select "Trusted Root Certification Authorities"

After this two steps the app begin to works fine again, but after some hours the error pops up again.

The work around I've found is the execute the same comands explained above to add the certificate to my cacerts again (have to change the name of the import)

Here is how I connect to the web page using JSOUP

Connection.Response response = Jsoup.connect("https://www.test.store/us/").method(Connection.Method.GET)
                    .execute();

I can't seem to find to root cause of this error and why It fails to work some hours after I import the certificates again.

Kevin Valdez
  • 359
  • 4
  • 17
  • Modifying the Java Runtime was never a good idea especially on Windows as the keystore is replaced when you install an Java update. Better provide a cutom root ca certificate in a separate keystore: https://stackoverflow.com/questions/2893819/accept-servers-self-signed-ssl-certificate-in-java-client Use the SSLSocketfactory in Jsoup via `Jsoup.connect("url").sslSocketFactory(mySocketFactory)...` – Robert Oct 22 '21 at 16:45
  • This seems to be the correct approach, I manage to use 'sslSocketFactory(mySocketFactory())' to call a generic method to disable certificate validation, but cant seem to find how to use it to add my certificates using JSOUP – Kevin Valdez Oct 22 '21 at 17:18

0 Answers0