2

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());
}
Community
  • 1
  • 1
Pyth0n
  • 355
  • 5
  • 13

1 Answers1

1

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.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84