我不是密钥库方面的专家,并且很难理解其中的细微差别,但这就是我所取得的进展:
在使用 asmack 构建创建 xmpp 连接时发现here https://github.com/Flowdalic/asmack人们仍然需要更改信任库,通常可以说是多个sources http://nhachicha.wordpress.com/2012/03/14/xmpp-client-with-android/在网络上,使用这些命令完成
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 下,他们更改了一些内容,但现在不再适用。现在的路径不同了。
显然这可以修复 http://redmine.xabber.com/issues/212#note-3但我不知道该怎么做。
显然,我们需要的是一种根据 SDK 版本返回路径的方法,该方法返回设置 sdk 路径所需的字符串,因为您不能只将密钥库本身返回到 xmpp 连接。
在参照this https://github.com/tomwhipple/AndroidPinning/blob/03d9b7d27ae3b12a946f7ac76143b7213af67579/java/org/thoughtcrime/ssl/pinning/PinningTrustManager.java该方法如下所示:
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 https://stackoverflow.com/questions/7002365/android-central-keystore评论者表示,在 Android 下“4.x;/etc/security/cacerts.bks 被替换为包含作为单独 PEM 编码文件的证书的目录 /etc/security/cacerts/”。然而,我不知道这有什么相关性(如果有的话)。
我还使用 xmpp 和 asmack 检查了两个项目的代码(gtalksms http://code.google.com/p/gtalksms/source/browse/src/com/googlecode/gtalksms/XmppManager.java?name=v1.9.2 and yaxim https://github.com/ge0rg/yaxim但没有看到他们如何避免这个问题。