是否可以从Url
获取证书信息?在iOS中,它有NSURLAuthenticationChallenge
,如果url
包含https
,则会提供相关信息。
我们以同样的方式通过代码获取特定url
的证书信息吗?
答案 0 :(得分:2)
X509TrustManager trustManager = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
for (TrustManager tm : managers) {
if (tm instanceof X509TrustManager) {
((X509TrustManager) tm).checkClientTrusted(
chain, authType);
}
}
}
@Override
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
for (X509Certificate cert : chain) {
// cert gives the server Certificate Information.
if (cert.getIssuerX500Principal().equals(
trustedRoot.getIssuerX500Principal())) {
return;
}
}
for (TrustManager tm : managers) {
if (tm instanceof X509TrustManager) {
((X509TrustManager) tm).checkServerTrusted(
chain, authType);
}
}
}
@Override
public X509Certificate[] getAcceptedIssuers() {
ArrayList<X509Certificate> issuers = new ArrayList<>();
for (TrustManager tm : managers) {
if (tm instanceof X509TrustManager) {
issuers.addAll(Arrays
.asList(((X509TrustManager) tm)
.getAcceptedIssuers()));
}
}
return issuers.toArray(new X509Certificate[issuers
.size()]);
}
};
在上面的代码中检查此// cert gives the server Certificate Information.
。
答案 1 :(得分:0)
是的,有可能:
步骤1:在broswer中输入网址,点击2标签,如下所示:
第2步:打开详情选项卡
第3步:从那里导出公钥。
第4步:获取.cert文件。
步骤5:从.cert文件生成密钥库并将其放在android
中