“未找到认证路径的锚点”在信任库中

发布于 2024-12-21 00:03:41 字数 1096 浏览 2 评论 0原文

我尝试过此方法来建立安全的连接到我大学的服务器。在一个小型java应用程序中,它适用于我,但不适用于Android 2.3.3。相反,我得到以下异常:

javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException:
    Trust anchor for certification path not found.`
  1. 这个解决方案的问题在哪里?是信任库本身还是我导入了“错误”的证书?
  2. 如何更好地调试此类错误?

我的代码:

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.`
  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());
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单身狗的梦 2024-12-28 00:03:41

问题是,无论 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文