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