我使用以下代码检索此列表。它似乎工作,但它似乎并不特别安全/智能,因为我找不到任何文件,表明.bks文件将始终在硬编码位置可用。
这种方法是否合理,还是有更安全/更智能的方法来解决这个问题?
String filename = "/system/etc/security/cacerts.bks";
FileInputStream is = new FileInputStream(filename);
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
String password = "changeit";
keystore.load(is, password.toCharArray());
PKIXParameters params = new PKIXParameters(keystore);
Iterator it = params.getTrustAnchors().iterator();
//iterate and such
答案 0 :(得分:0)
在Google小组上找到答案:
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init((KeyStore) null);
X509TrustManager xtm = (X509TrustManager) tmf.getTrustManagers()[0];
for (X509Certificate cert : xtm.getAcceptedIssuers()) {
String certStr = "S:" + cert.getSubjectDN().getName() + "\nI:"
+ cert.getIssuerDN().getName();
Log.d(TAG, certStr);
}