I have been building web downloaders over the years (e.g., using Apache HTTPClient and recently JBrowser [1]). These have worked OK till recently when some sites result in certification errors. I do not understand the details, and I cannot find a simple tutorial for people who know relatively little about certificates (e.g., what one looks like and how it obtained or created). This is a request for a default explanation of the simplest case and how to fix it. Typical error:
[2020-02-17T09:38:24.249][Instance 1][Port 57129] Warning: Single GUI Threadiong is enabled, FPS should be slower
[2020-02-17T09:38:29.737][Instance 1][Port 57129] Feb 17, 2020 9:38:29 AM com.sun.webkit.network.URLLoader doRun
[2020-02-17T09:38:29.737][Instance 1][Port 57129] WARNING: Unexpected error
[2020-02-17T09:38:29.737][Instance 1][Port 57129] java.io.IOException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target: https://osf.io/search/?q=coronavirus
[2020-02-17T09:38:29.737][Instance 1][Port 57129] at com.machinepublishers.jbrowserdriver.StreamConnection.exec(StreamConnection.java:369)
[2020-02-17T09:38:29.737][Instance 1][Port 57129] at com.machinepublishers.jbrowserdriver.StreamConnection.getResponseCode(StreamConnection.java:449)
[2020-02-17T09:38:29.737][Instance 1][Port 57129] at com.sun.webkit.network.URLLoader.receiveResponse(URLLoader.java:414)
...
I can access the URL through browsers (Firefox, Chrome) and get HTML which represents what I want, but cannot access this programmatically.
I have read several accounts of how to fix this (e.g. [2]), but they generally refer to "your Keystore" or "trust manager" as if everyone knows what these are. I am concerned that if I don't know what I am doing, I could break security. I don't know how I add sites to these or whether I even should.
I am on MACOSX and appear to have a binary file
"/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/JRE/lib/security/cacerts"
Some of the answers suggest I should have a file called "truststore.jks" but don't say where this should be or how it was created.
So I am asking for a simple explanation of the system components and the simplest way to fix it. In some cases, I can avoid it (e.g., by using curl
from the command-line), so I don't know how much this is a Java (8) problem.
EDIT: Trust Store vs Key Store - creating with keytool seems to explain the difference between KeyStore and TrustStore, but I still don't have insight into what to do.
[1] http://machinepublishers.github.io/jBrowserDriver/com/machinepublishers/jbrowserdriver /JBrowserDriver.html [2] Using a custom truststore in java as well as the default one