验证证书是否由可信CA签名。我尝试使用getAcceptedIssuers()方法获取Trusted X509Certificate列表。
X509Certificate[] cert2= getAcceptedIssuers();
在该列表中,通用名称(Symantec Class 3 EV SSL CA-G3)不可用。 如何在默认的信任管理器中获取此值?
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
if (!false) {
X509Certificate cert=chain[0];
Log.d("bucky validate 0",chain[0].getIssuerDN().getName());
boolean found = false;
try {
String dns= String.valueOf(cert.getIssuerDN());
Log.d("bucky validate",dns);
X509Certificate[] cert2= getAcceptedIssuers();
int length=cert2.length;
for (int i=0;i<length;i++){
String dnName= String.valueOf(cert2[i].getIssuerDN());
Log.d("bucky validate2",dnName);
}
cert.checkValidity(new Date());
} catch (Exception e) {
e.printStackTrace();
}}
@Override
public X509Certificate[] getAcceptedIssuers()
{
return defaultTrustManager.getAcceptedIssuers() ;
}
public ApplicationTrustManager() throws NoSuchAlgorithmException, KeyStoreException {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init((KeyStore) null);
defaultTrustManager = (X509TrustManager) tmf.getTrustManagers()[0];
}
答案 0 :(得分:0)
最后,我得到了答案。这是一个小错误。
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException
链数组的最后一个值,我得到了可信证书名称。