我的本地 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()));
最佳答案
你应该注册一个KeyStore
使用 TrustManagerFactory
.参见 http://developer.android.com/reference/javax/net/ssl/HttpsURLConnection.html
关于java - Android,我的应用程序不接受我的自签名 ssl 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36415378/