我试过了 this method与我大学的服务器建立安全连接。在一个小型 java 应用程序中它适用于我,但不适用于 Android 2.3.3。相反,我得到以下异常:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException:
Trust anchor for certification path not found.`
- 这个解决方案的问题在哪里?是信任库本身还是我导入了“错误的”证书?
- 如何更好地调试此类错误?
我的代码:
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());
}
最佳答案
问题是 JSoup 使用的任何 http 库都没有获取(或根本不使用)那些系统属性。要调试它,请找出 JSoup 在幕后使用的是什么并手动连接。如果它在桌面上运行,则您的信任库可能没问题。
关于java - 信任库中的 "Anchor for certification path not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8480436/