java - Android,我的应用程序不接受我的自签名 ssl 证书

标签 java android ssl https

我的本​​地 tomcat 应用程序有一个自签名的 ssl 证书,我正在尝试使用 https 从我的 android 连接到 tomcat 网络应用程序,但我收到此错误:

java.security.cert.CertPathValidatorException:找不到证书路径的信任 anchor 。

这是一个常见问题,但到目前为止我找到的所有解决方案都存在问题。他们中的很多人只是创建了一种方法来接受所有 ssl 证书,这违背了使用 ssl 的要点。解决方案的另一个问题是它们都使用已弃用的 apache httpclient,而我想使用 urlconnection。

我在 res/raw 中有一个 keystore.bks,如何让我的 android 应用接受这个证书?

这是我用来连接到我的 tomcat 应用程序的代码:

URL url = new URL("https://192.168.0.6:8443/Rest/android/login");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
StringBuilder sb = new StringBuilder();
reader = new BufferedReader(new InputStreamReader(con.getInputStream()));

最佳答案

关于java - Android,我的应用程序不接受我的自签名 ssl 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36415378/

相关文章:

java - DL4J UnsatisfiedLinkError : no jniopenblas in java. 库.path

java - 无法删除 Firebase 中的子节点

android - 创建点击 WebView 链接的 Intent

JavaFX - 如何识别 ScrollBar 在 TableView 中的位置

java - 如何在 spring 中触发 Async TransactionalEventListener

java - 使用外部 JAR 构建 Eclipse 项目

java - 创建页面的左右垂直线 - Android Java iTextPdf

ssl - 在 GCP Composer Airflow 中使用 AWS SES SMTP 服务器时出现 "SSL: WRONG_VERSION_NUMBER"

ssl - 无法建立双向 SSL 连接

tomcat - 如何测试 Tomcat 是否启用了 SSL 支持?