Using the Android TrustStore for aSmack in Android 4+ (ICS)

佐手、 提交于 2019-12-03 08:48:49

Try this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    connectionConfiguration.setTruststoreType("AndroidCAStore");
    connectionConfiguration.setTruststorePassword(null);
    connectionConfiguration.setTruststorePath(null);
} else {
    connectionConfiguration.setTruststoreType("BKS");
    String path = System.getProperty("javax.net.ssl.trustStore");
    if (path == null)
        path = System.getProperty("java.home") + File.separator + "etc"
            + File.separator + "security" + File.separator
            + "cacerts.bks";
    connectionConfiguration.setTruststorePath(path);
}

See https://github.com/Flowdalic/asmack/wiki/Truststore and some background explanation at http://nelenkov.blogspot.com/2011/12/ics-trust-store-implementation.html.

The trust store in ICS is not in a single .bks file any more, but in separate PEM-encoded files in the /system/etc/security/cacerts directory. User-added certs can be placed in /data/misc/keychain/cacerts-added. More details can be found here.

Your cert file must be named as: subject-hash.N where N is an sequential integer starting from 0 (usually just 0, but if 0 is already used, then 1, etc).

To get the subject-hash of your cert, you can use openssl like this: openssl x509 -noout -subject_hash_old -in my-cert-file.pem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!