【问题标题】:"CertPathValidatorException: Trust anchor for certification path not found." with (a)Smack 4.0.0“CertPathValidatorException:找不到证书路径的信任锚。”使用(a)Smack 4.0.0
【发布时间】:2014-07-18 07:26:51
【问题描述】:

我最近更新了 asmack jar。现在我收到这样的错误:

07-18 12:49:29.523:W/XMPPConnection(6817):javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚。

当我尝试连接时。早些时候一切正常(旧版本)。

【问题讨论】:

  • 代理问题我猜!尝试连接到其他网络,然后尝试。

标签: xmpp smack


【解决方案1】:

是的,如果您编写类似下面的代码,以下代码的旧版本 asmack(直到 aSmack-0.8.10)工作正常,没有任何错误,

ConnectionConfiguration connConfig = new ConnectionConfiguration("host_name", 5222 ); connConfig.setSecurityMode(SecurityMode.enabled);

但是对于较新版本的 asmack(aSmack-4.0.4),如果您使用 connConfig.setSecurityMode(SecurityMode.enabled); 则此错误将持续存在;

正如@cOcO 提到的,SSL 配置不正确。为此,您可以使用MemorizingTrustManager

它是一个开源库,下载它并在 Eclipse 中作为 android 项目导入,然后作为 libraryProject 添加到你的 android 项目中。

添加此库后,将以下行添加到您的 AndroidManifest.xml

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

<activity android:name="de.duenndns.ssl.MemorizingActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

</application>

现在在您的 xmpp 服务中添加以下代码

try {
            SSLContext sc = SSLContext.getInstance("TLS");
            sc.init(null, MemorizingTrustManager.getInstanceList(this.getApplicationContext()), new SecureRandom());
            connConfig.setCustomSSLContext(sc);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException(e);
        } catch (KeyManagementException e) {
            throw new IllegalStateException(e);
        }

希望以上代码能解决您的问题。

编辑:16_10_2014 有关信任管理器的更多信息,您可以访问此链接https://github.com/Flowdalic/asmack/wiki/Truststore

【讨论】:

  • 我尝试了您的方法,但出现错误:在回复超时内未收到回复。超时为 10000 毫秒(约 10 秒)。在等待建立 TLS 时。如果您知道如何解决此问题,请提供帮助
【解决方案2】:

SSL 配置不正确。那些信任锚错误通常意味着无法找到信任库。检查您的配置并确保您实际上指向信任存储并且它已就位。

【讨论】:

    猜你喜欢
    • 2017-10-03
    • 2015-05-30
    • 2021-03-18
    • 2014-12-15
    • 2015-04-17
    • 1970-01-01
    • 2016-11-16
    • 2018-02-20
    相关资源
    最近更新 更多