“未找到认证路径的锚点”在信任库中
我尝试过此方法来建立安全的连接到我大学的服务器。在一个小型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());
}
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.`
- Where is the problem with this solution? Is it the truststore itself or I have imported the "wrong" certificate?
- 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());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是,无论 JSoup 使用什么 http 库,都不会获取(或根本使用)这些系统属性。要调试它,请找出 JSoup 在幕后使用的内容并手动连接。如果它可以在桌面上运行,那么您的信任存储可能没问题。
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.