xmpp - "CertPathValidatorException: Trust anchor for certification path not found."(a)Smack 4.0.0

标签 xmpp smack

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

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

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

最佳答案

是的,如果您编写类似下面的代码,以下代码的旧版本 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

关于xmpp - "CertPathValidatorException: Trust anchor for certification path not found."(a)Smack 4.0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24819441/

相关文章:

ios - openfire 中需要哪些插件才能进行聊天

android - 从 XMPP android 获取不同的发件人和接收地址,任何解决方案?

XMPP 名册状态、自定义名册和未知用户之间的消息传递

components - XEP-0114 是如何工作的?

java - Android - XMPPError : jid-malformed - modify

android - 我们如何从 xmpp 服务器访问存档消息到 android 应用程序

ios - 如何在 iOS 上使用 XMPPFramework 和 OpeFire 创建/更新/检索用户 vCard

android - 如何在 XMPP SMACK 库中获取服务器时间

java - Android XMPP Smack 在应用程序关闭时接收消息

java - XMPP服务器不响应Smack登录请求