Reputation: 367
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.`
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
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