如果我只知道该字段的名称,如何从X509Certificate获取价值?
例如" CN"有OID" 2.5.4.3",如果我知道只获取字符串名称如何将其转换为OID并从字段中获取值?
如果我只有字符串名称OID,我怎么能得到数字OID?
答案 0 :(得分:0)
public class CustomX509TrustManager implements X509TrustManager{
private X509Certificate[] serverX509CertificateArray;
@Override
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
//TODO xcs array include: OID,...
this.serverX509CertificateArray = xcs;
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return this.serverX509CertificateArray;
}
}
代码部分:
SSLContext sslContext = SSLContext.getInstance("SSLv3");
sslContext.init(null, new TrustManager[] {new CustomX509TrustManager()}, new java.security.SecureRandom());
SSLSocketFactory ssf = sslContext.getSocketFactory();
HttpsURLConnection conn = (HttpsURLConnection) new URL("https://www.facebook.com/").openConnection();
conn.setSSLSocketFactory(ssf);
conn.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String string, SSLSession ssls) {
return true;
}
});
conn.setConnectTimeout(1000);
conn.setReadTimeout(1000 * 2);
conn.connect();
//READ HTML
conn.disconnect();