HttpsUrlConnection:2.3上找不到证书路径的信任锚点

5

你好,我需要与https://free.temafon.ru建立https连接,但在Android 2.3及以下版本中出现了CertPathValidatorException错误。我该怎么办?

  1. Grab all certs from https://free.temafon.ru with Firefox.
  2. Import certs in keystore in sequence from temefon certificate to root certificate.
  3. Init ssl context:

    final KeyStore 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());
    

    Here, I use custom TrustManager, because server sends certs in wrong order.

这段代码在Android 4.0上可以正常工作,但在2.3上失败了,提示错误信息为java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 我做错了什么?

我创建了一个测试项目,可以在这里找到。


你找到解决方案了吗?我也在处理同样的问题。 - jimbob
很遗憾,我最终接受了所有2.3的证书。 - Bracadabra
1个回答

0

当你说你用FireFox获取了所有证书时,是否也包括根CA?

很可能,Android 2.3没有安装根CA。根据此link

在这种情况下,SSLHandshakeException是因为您有一个系统不信任的CA。这可能是因为您有一个来自尚未被Android信任的新CA的证书,或者您的应用程序正在旧版本上运行而没有该CA


我同意Android 2.3没有根CA,但我获取了所有证书链并将其添加到自定义信任存储中。 - Bracadabra

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接