【发布时间】:2013-09-27 07:59:51
【问题描述】:
那里。我需要与 https://free.temafon.ru 建立 https 连接,但我在 Android 2.3 及更低版本上遇到了 CertPathValidatorException。我做了什么。
- 使用 Firefox 从https://free.temafon.ru 获取所有证书。
- 从 temefon 证书到根证书的顺序导入 keystore 中的证书。
-
初始化 ssl 上下文:
最终的 KeyStore 密钥库 = KeyStore.getInstance("BKS");
keystore.load(getResources().openRawResource(R.raw.temafon), "W0d3Uoa5PkED".toCharArray()); final TrustManager trustManager = new TemafonTrustManager(keystore); final SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[] { trustManager }, null); HttpsURLConnection.setDefaultSSLSocketFactory(sslContext .getSocketFactory());这里,我使用custom TrustManager,因为服务器以错误的顺序发送证书。
此代码在 Android 4.0 上运行良好,但在 2.3 上失败,java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 我做错了什么?
我创建了一个测试项目,可以找到here。
【问题讨论】:
-
您找到解决方案了吗?我正在处理同样的问题。
-
很遗憾,我最终接受了 2.3 的所有证书。
标签: android ssl https ssl-certificate httpsurlconnection