我在这个页面上看到如何做 https
http://sonatype.github.com/async-http-client/ssl.html
但是,如果我只想忽略并接受任何证书,因为在这种环境中,我现在不关心中间人,因为它处于孤立的环境中,我只是在做一些事情来对 QA 数据进行自动化测试。
也许我的问题是如何在 java 的 SSL 堆栈中伪造 SSL,以便它在另一端接受任何证书(这不是双向的,因为它是 https)。
上面链接中客户端的通用代码是
char[] keyStorePassword = "changeit".toCharArray();
KeyStore ks = KeyStore.getInstance("JKS");
//ks.load(keyStoreStream, keyStorePassword);
char[] certificatePassword = "changeit".toCharArray();
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, certificatePassword);
KeyManager[] keyManagers = kmf.getKeyManagers();
javax.net.ssl.TrustManager tm = new MyTrustMgr();
javax.net.ssl.TrustManager[] trustManagers = new javax.net.ssl.TrustManager[]{tm };
SecureRandom secureRandom = new SecureRandom();
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(keyManagers, trustManagers, secureRandom);
return ctx;
好的,解决这个问题,我发现由于某种原因它仍然无法正常工作
X509TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs,
String string) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] xcs,
String string) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[] { tm }, null);
return ctx;
谢谢,院长