我正在尝试使用以下代码绕过证书:
private static HttpClient wrapClient(HttpClient base)抛出AGException { 尝试 { SSLContext ctx = SSLContext.getInstance(“TLS”);
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;
}
};
ctx.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = base.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));
return new DefaultHttpClient(ccm, base.getParams());
}
catch (NoSuchAlgorithmException nsaex)
{
throw new AGException(nsaex, "Not able to get the SSL Context");
}
catch (KeyManagementException kmex) {
throw new AGException(kmex, "Not able to get the SSL Context");
}
}
但仍然收到以下错误 javax.net.ssl.SSLPeerUnverifiedException:peer not authenticated
简要介绍一下我的意见:
我使用putty隧道到服务器并通过https调用SOAP来连接到该服务器 但即使尝试使用上述代码也会收到相同的错误。
任何帮助/建议都会非常吸引人。 提前谢谢。
-Nitish
答案 0 :(得分:1)
不要使用不安全的TrustManagers。
这里的问题是对等方根本没有提供证书。