简体   繁体   English

Android:CertPathValidatorException:找不到证书路径的信任锚

[英]Android: CertPathValidatorException: Trust anchor for certification path not found

I believe I have done everything I should here according to related articles and yet I still get this error. 我相信我已经按照相关文章做了我应该做的所有事情,但是仍然出现此错误。 I have created my own CA and signed the server certificates with this CA. 我已经创建了自己的CA,并为此CA签署了服务器证书。 On the Android side I have created a custom TrustManager using a custom truststore which has this CA root certificate in it. 在Android方面,我使用一个自定义信任库创建了一个自定义TrustManager,其中包含此CA根证书。 Using System.setProperty("javax.net.debug", "ssl") on the server side (it doesn't work on the Android side unfortunately even in 4.4) I get a little bit more information. 在服务器端使用System.setProperty(“ javax.net.debug”,“ ssl”)(不幸的是,即使在4.4中,它在Android端也无法使用),我得到了一些更多信息。 I get past the server hello and the exchange of the secret keys. 我经过服务器问好和密钥交换。 Then Android gives me the above error (Trust anchor for certification path not found) and on the server side I get javax.net.ssl.SSLException: Inbound closed before receiving peer's close_notify: possible truncation attack? 然后,Android给了我上面的错误(找不到证书路径的信任锚),在服务器端,我得到了javax.net.ssl.SSLException:入站在收到对等方的close_notify之前已关闭:可能发生截断攻击?

I have mirrored the application (client) on my PC and it works. 我已经在PC上镜像了应用程序(客户端),并且可以正常工作。

Is it that Android does not support 2048 keys with SHA512withRSA ? Android是否不支持SHA512withRSA使用2048个密钥 I have no problem with self-signed certificates (1024 and SHA1withRSA); 自签名证书(1024和SHA1withRSA)没有问题; have not tried self-signed certificates with 2048 and SHA512. 尚未尝试使用2048和SHA512的自签名证书。

Somehow I believe this is a shortcoming of Android that is not documented or hard to find (kind of like System.setProperty("javax.net.debug", "ssl") not working). 我以某种方式认为这是未记录或很难找到的Android的缺点(类似于System.setProperty(“ javax.net.debug”,“ ssl”)不能正常工作)。

I actually implement my own KeyManager and TrustManager and keystores and truststores because eventually I will need mutual TLS ... all working on a PC. 实际上,我实现了自己的KeyManager和TrustManager以及密钥库和信任库,因为最终我将需要相互TLS ...都在PC上运行。 Hoped it would be an easy migration to Android. 希望可以轻松迁移到Android。

Here is the Android setup of the Keystores/Truststores (gets the files and loads them) 这是密钥库/信任库的Android设置(获取文件并加载它们)

 LoadFile(getString(R.string.truststore_filename), R.raw.androidtruststore);
 LoadFile(getString(R.string.keystore_filename), R.raw.androidkeystore);
 String basePath = getFilesDir().getAbsolutePath() + "/";
 SecureRawHttpWanSender.setSecureProperties(basePath + getString(R.string.truststore_filename), 
                                                   getString(R.string.truststore_password),
                                                   basePath + getString(R.string.keystore_filename),
                                                   getString(R.string.keystore_password),
                                                   true);

Here is the setting of the TrustManagers etc. done in setSecureProperties() which is also used on the PC. 这是在setSecureProperties()中完成的TrustManager等设置,该设置也可在PC上使用。 Only the loading of the files is different (PC uses jks and Android uses bks) 只有文件的加载不同(PC使用jks,Android使用bks)

    FileInputStream fIS = null;
    try
    {
        // On Android this is "BKS". Otherwise Sun Java is "JKS"
        trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        Manager.log.log(Level.Info, Task.WanSecure, "Type of truststore: " + trustStore.getType());
        fIS = new FileInputStream(trustStoreFileName);
        trustStore.load(fIS, trustStorePassword.toCharArray());
        fIS.close();
        tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(trustStore);
        if(keyStoreFileName != null)
        {
            keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            Manager.log.log(Level.Info, Task.WanSecure, "Type of keystore: " + keyStore.getType());
            fIS = new FileInputStream(keyStoreFileName);
            keyStore.load(fIS, keyStorePassword.toCharArray());
            fIS.close();
            kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            kmf.init(keyStore, keyStorePassword.toCharArray());
        }
        return true;
    }

Thanks for any help (and the discovery of anything I did that was really stupid!) 感谢您的帮助(发现我所做的任何事情都真是愚蠢!)

I found a solution to the above problem but I don't like it. 我找到了解决上述问题的方法,但我不喜欢它。 I may have actually seen it mentioned somewhere else in one of the questions related to this topic. 我可能实际上已经看到它在与此主题相关的问题之一中的其他地方提到过。 What I did was add to the android truststore the server's certificate that is signed by the CA. 我所做的是将由CA签名的服务器证书添加到android truststore中。 So now in my truststore I have TWO certificates for the server, the server's certificate signed by the CA and the CA root certificate. 因此,现在在我的信任库中,我有服务器的两个证书,由CA签名的服务器证书和CA根证书。

What I don't like is the inconsistency. 我不喜欢的是不一致。 On my Windows 7 PC I do not need the server's certificate signed by the CA, it is sufficient to have the CA root. 在Windows 7 PC上,我不需要由CA签名的服务器证书,拥有CA根目录就足够了。 I can understand the need for intermediary certificates IF the server certificate was signed by a CA that perhaps is validated by the root CA in the truststore but that intermediary CA's certificate is not in the truststore. 如果服务器证书是由CA签名的,则可以理解中间证书的需求,该证书可能已由信任库中的根CA验证,但是中间CA的证书不在信任库中。 The chain is then broken. 然后链条断裂。

Why I need the server certificate signed by the CA root plus the root CA on Android but only need the root CA on my PC is point of significant confusion. 为什么我需要由CA根签名的服务器证书加上Android上的根CA,却只需要PC上的根CA,这是一个很大的困惑点。 I take it as a typically incomplete implementation of Android. 我将其视为Android的典型不完整实现。 As I am finding out is the case for XML schema validation! 我发现XML模式验证就是这种情况!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.security.cert.CertPathValidatorException:找不到证书路径的信任锚 - java.security.cert.CertPathValidatorException: Trust anchor for certification path not found Android-Retrofit2-java.security.cert.CertPathValidatorException:找不到证书路径的信任锚 - Android - Retrofit2 - java.security.cert.CertPathValidatorException: Trust anchor for certification path not found Hostgator 启用的免费 SSL - Android 错误:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚 - Free SSL Enabled by Hostgator - Android Error : java.security.cert.CertPathValidatorException: Trust anchor for certification path not found Android-原因:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚 - Android - Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found CertPathValidatorException:未找到证书路径的信任锚。 在 android 中更新 gradle 和 gradle 插件后 - CertPathValidatorException: Trust anchor for certification path not found. in android after update gradle and gradle plugin Android java.security.cert.CertPathValidatorException:未找到证书路径的信任锚 - Android java.security.cert.CertPathValidatorException: Trust anchor for certification path not found java.security.cert.CertPathValidatorException:未找到证书路径的信任锚。 安卓 2.3 - java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. Android 2.3 Android 7:找不到认证路径的信任锚 - Android 7: Trust anchor for certification path not found javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚 - javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found 调试javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚 - Debugging javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM