【发布时间】:2012-06-01 12:30:14
【问题描述】:
我不是密钥库方面的专家,很难理解其中的细微差别,但这就是我能做到的:
在使用 here 找到的 asmack 构建创建 xmpp 连接时,仍然需要更改信任库,通常,例如网络上的多个 sources,使用这些命令完成
ConnectionConfiguration config = new ConnectionConfiguration(host, Integer.parseInt(port), service);
config.setTruststorePath("/system/etc/security/cacerts.bks");
config.setTruststorePassword("changeit");
config.setTruststoreType("bks");
XMPPConnection connection = new XMPPConnection(connConfig);
connection.connect();
这适用于较旧的 Android 版本,但在 ICS 下他们更改了一些内容,现在不再更改。现在的路径不同了。
显然是this can be fixed,但我不知道该怎么做。
显然,需要一种根据 SDK 版本返回路径的方法,该方法返回设置 sdk 路径所需的字符串,因为您不能只将密钥库本身返回到 xmpp 连接。
参考this,该方法如下所示:
private String getTrustStorePath()
{
String path = System.getProperty("javax.net.ssl.trustStore");
if (path == null)
{
if ( Build.VERSION.SDK_INT >= 14 )
{
//THIS IS THE PART I DONT KNOW
path="";
}
else
{
path = "/system/etc/security/cacerts.bks";
}
return path;
}
Here 一位评论者说,在 Android 下,“4.x;/etc/security/cacerts.bks 被替换为目录 /etc/security/cacerts/,其中包含作为单独 PEM 编码文件的证书。”但是,我不知道这有什么相关性(如果有的话)。
我还检查了使用 xmpp 和 asmack 的两个项目的代码(gtalksms 和 yaxim,但没有看到他们如何避免这个问题。
【问题讨论】:
-
我目前也在调查这个问题。我们最近有changed how we detect the truststore path on GTalkSMS,因为它也可以是seen here。但我很确定这还不够……
标签: android xmpp keystore asmack