1

For some time now, I have been trying to extract data from the internet using technologies such as:

Problem

I never had a problem doing data extraction before. Everything always worked correctly. However, I'm suddenly starting to get the following error:

java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
    at java.base/javax.net.ssl.DefaultSSLSocketFactory.throwException(SSLSocketFactory.java:266)
    at java.base/javax.net.ssl.DefaultSSLSocketFactory.createSocket(SSLSocketFactory.java:273)
    at java.base/sun.net.www.protocol.https.HttpsClient.createSocket(HttpsClient.java:420)
    at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:162)
    at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:497)
    at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:600)
    at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265)
    at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:379)
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:189)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1232)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1120)
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:175)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:142)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:859)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:829)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:366)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:353)
    at com.plua.jsoupteste.JSoupTest.main(JSoupTest.java:13)
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
    at java.base/java.security.Provider$Service.newInstance(Provider.java:1900)
    at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
    at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
    at java.base/javax.net.ssl.SSLContext.getInstance(SSLContext.java:184)
    at java.base/javax.net.ssl.SSLContext.getDefault(SSLContext.java:110)
    at java.base/javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:83)
    at java.base/javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(HttpsURLConnection.java:334)
    at java.base/javax.net.ssl.HttpsURLConnection.<init>(HttpsURLConnection.java:291)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.<init>(HttpsURLConnectionImpl.java:81)
    at java.base/sun.net.www.protocol.https.Handler.openConnection(Handler.java:62)
    at java.base/sun.net.www.protocol.https.Handler.openConnection(Handler.java:57)
    at java.base/java.net.URL.openConnection(URL.java:1101)
    at org.jsoup.helper.HttpConnection$Response.createConnection(HttpConnection.java:1020)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:856)
    ... 4 more
Caused by: java.security.KeyManagementException: problem accessing trust store
    at java.base/sun.security.ssl.SSLContextImpl$DefaultManagersHolder.<clinit>(SSLContextImpl.java:942)
    at java.base/sun.security.ssl.SSLContextImpl$DefaultSSLContext.<init>(SSLContextImpl.java:1112)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at java.base/java.security.Provider.newInstanceUtil(Provider.java:155)
    at java.base/java.security.Provider$Service.newInstance(Provider.java:1893)
    ... 17 more

This error is persistent and is displayed regardless of using any of the technologies listed above (JSoup, HtmlUnit, java.net.http, etc.). Even a simple code like the one shown below is causing this problem (in the example, JSoup was used for demonstration purposes only):

public static void main(String[] args) {
    try {
        Document doc = Jsoup.connect("https://en.wikipedia.org/").get();
    
        System.out.println(doc.title());
        Elements newsHeadlines = doc.select("#mp-itn b a");
        
        for (Element headline : newsHeadlines) {
          System.out.printf("%s\n\t%s", 
            headline.attr("title"), headline.absUrl("href"));
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Example Source

I am fully aware that this is a problem related to certificates, SSL, etc., something that unfortunately I am not able to solve on my own.

The problem is that I never messed with anything, any files, configuration, or anything that could make any changes compromising the application to work properly (at least, not that I'm aware of).

Desired Goal

I've already been looking on the internet for solutions for this type of exception, but my case has a very specific detail:

I am developing an application that will be used on home computers, that is, this data extraction application will need to be used by common people, who are not programmers, such as friends, family, etc.

I'm not sure if solving this certificate issue here on my personal computer (creating commands, applying JVM arguments, extracting and manipulating certificates, etc.), I would have to do the same on every computer the application will be distributed to (which would be a nightmare, and completely unfeasible in this case).

In summary: I want to be able to develop an application for extracting data from the internet, distribute it, and not need to do any configuration on the computers that will receive the application, after all, they would only need to have Java installed.

The graphical interface I'm doing using JavaFX, something I've been able to do before. My problem is extracting data, precisely because I'm ALWAYS getting this error.

Development Environment

  • Eclipse IDE for Java Developers Version 2018-09 (4.9.0), Build id 20180917-1800
  • JSoup 1.14.3
  • JDK 16
  • JRE 1.8.0_311
Loa
  • 2,117
  • 3
  • 21
  • 45
  • I'm seeing quite a few posts on Stackoveflow when I search for `java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)` already, did none of those contain any data that allowed you to do further debugging? – Mike 'Pomax' Kamermans Dec 16 '21 at 21:28
  • Does this answer your question? [Java and SSL - java.security.NoSuchAlgorithmException](https://stackoverflow.com/questions/6365209/java-and-ssl-java-security-nosuchalgorithmexception) – fantaghirocco Dec 16 '21 at 22:12
  • 1
    @fantaghirocco: except that this one is clearly identified as truststore, not keystore. OP: do you have sysprops `javax.net.ssl.trustStore*` set? Has the file `$JRE/lib/security/cacerts` been modified, removed, or made inaccessible? Can you read that file using `keytool -list -cacerts` with password `changeit`? – dave_thompson_085 Dec 17 '21 at 00:27

1 Answers1

0

Your JVM is trying to establish an encrypted connection. However when negotiating which encyption algorithm to use the parties cannot agree on one known to both sides so that is when they fail.

This may mean the algorithms allowed for your JVM are not good. It may also mean the algorithms allowed for the other side are not good. There is just no common ground.

Try to install latest software versions on both sides. Check the SSL or encryption settings for allowed ciphers.

Queeg
  • 7,748
  • 1
  • 16
  • 42
  • This is related to TLS-aka-SSL, but **not the protocol negotiation** which has not yet started during the SSLContext constructor. SSL _truststore_ settings may be a factor; encryption or protocol more broadly are not. – dave_thompson_085 Dec 17 '21 at 00:27
  • 1
    You are right. The lowest exception in the stack trace actually mentiones "java.security.KeyManagementException: problem accessing trust store". I will delete my response soon. – Queeg Dec 17 '21 at 07:13