我最近更新了asmack jar.现在我收到这样的错误:
07-18 12:49:29.523:W/XMPPConnection(6817):javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:未找到证书路径的信任锚.
当我想要连接时.早些时候一切正常(旧版本).
是的,使用旧版本的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项目导入,并添加到你的android项目作为libraryProject.
添加此库后,将以下行添加到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>
Run Code Online (Sandbox Code Playgroud)
现在在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);
}
Run Code Online (Sandbox Code Playgroud)
希望以上代码能解决您的问题.
编辑:16_10_2014有关信任经理的更多信息,您可以访问此链接https://github.com/Flowdalic/asmack/wiki/Truststore
| 归档时间: |
|
| 查看次数: |
4179 次 |
| 最近记录: |