Pyth0n
Pyth0n

Reputation: 367

"Anchor for certification path not found" in the truststore

I've tryed this method to establish a secure connection to the server of my university. In a small java application it works for me, but not under Android 2.3.3. Instead, I get the following exception:

javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException:
    Trust anchor for certification path not found.`
  1. Where is the problem with this solution? Is it the truststore itself or I have imported the "wrong" certificate?
  2. How can I debug such errors better?

My code:

try {
    File dir = Environment.getExternalStorageDirectory();
    File file = new File(dir, "test.jks");

    if (file.exists()) {
        System.out.println(file.getAbsolutePath());
        System.setProperty("javax.net.ssl.trustStore", file.getAbsolutePath());
        System.setProperty("javax.net.ssl.trustStorePassword", "myPassword");
        System.out.println(System.getProperty("javax.net.ssl.trustStore"));

        Document document = Jsoup.connect("https://www.dhbw-loerrach.de/").get();
        lblMessage.setText(document.html());
    }
} catch (Exception ex) {
    System.out.println(ex.getMessage());
}

Upvotes: 2

Views: 1776

Answers (1)

Nikolay Elenkov
Nikolay Elenkov

Reputation: 52936

The problem is that whatever http library JSoup is using is not picking up (or using at all) those system properties. To debug it find out what JSoup is using under the covers and connect manually. If it works on the desktop, your trust store is probably fine.

Upvotes: 1

Related Questions