“CertPathValidatorException:未找到证书路径的信任锚."与 (a) Smack 4.0.0 [英] "CertPathValidatorException: Trust anchor for certification path not found." with (a)Smack 4.0.0

查看:53
本文介绍了“CertPathValidatorException:未找到证书路径的信任锚."与 (a) Smack 4.0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have recently updated the asmack jar. Now I am getting an error like this:

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

07-18 12:49:29.523: W/XMPPConnection(6817): javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

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

When I am trying to connect. Earlier everything was working properly (with old version).

推荐答案

是的,如果您编写如下所示的代码,下面的旧版本 asmack(直到 aSmack-0.8.10)运行良好,没有任何错误,

Yes,with the older version of asmack(till aSmack-0.8.10) below code was working fine without any error if you write something like below,

><块引用>

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

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

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

But with the newer version of asmack(aSmack-4.0.4) this error is will remain persist if you use connConfig.setSecurityMode(SecurityMode.enabled);

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

As mention by @cOcO here The SSL is not properly configured.For this you can use MemorizingTrustManager .

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

Its an open source library ,download it and import as android project in eclipse and add to you android project as libraryProject.

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

After adding this library add below lines to your 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 服务中添加以下代码

Now add below code in your xmpp service

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);
        }

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

Hope above code will solve your problem.

16_10_2014有关信任管理器的更多信息,您可以访问此链接 https://github.com/Flowdalic/asmack/维基/信托商店

16_10_2014 for more information about trust manager you can visit this link https://github.com/Flowdalic/asmack/wiki/Truststore

这篇关于“CertPathValidatorException:未找到证书路径的信任锚."与 (a) Smack 4.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆