gpt4 book ai didi

Java HttpClient 4.4.1 无法创建用于检查 SSL 证书的 TrustStrategy

转载 作者:太空宇宙 更新时间:2023-11-03 13:39:14 25 4
gpt4 key购买 nike

我在较新版本的 HttpClient 上遇到了问题。 TrustStrategy 似乎不能再使用了;但是,我需要在我的 TrustStrategy 上设置方法 isTrusted 以初始化 SSLSocketFactory。有人有其他方法可以做到这一点吗?

我对此做了很多研究,大部分案例都与TrustManager有关。有很多情况与忽略服务器的证书有关。它适用于我的本地,但我想检查证书是否有效,所以......我需要有 TrustStrategy。

下面是我的忽略证书的代码,我想在里面添加TrustStrategy。

        SSLContext sslContext = SSLContext.getInstance("SSL");

// set up a TrustManager that trusts everything
sslContext.init(null, new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}

public void checkClientTrusted(X509Certificate[] certs, String authType) {
}

public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
}
}, new SecureRandom());

SSLSocketFactory sf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Scheme httpsScheme = new Scheme("https", 443, sf);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(httpsScheme);

BasicClientConnectionManager cm = new BasicClientConnectionManager(schemeRegistry);
DefaultHttpClient httpClient = new DefaultHttpClient(cm);

我尝试了另一种方法来 new SSLSocketFactory(trustStrategy, ALLOW_ALL_HOSTNAME_VERIFIER),但它不起作用。感谢您的关注。

最佳答案

似乎 TrustSelfSignedStrategy 期望链中至少有一个证书。它似乎是 QnD 的教父,但对于测试来说,覆盖此方法可能是合适的。

关于Java HttpClient 4.4.1 无法创建用于检查 SSL 证书的 TrustStrategy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30269365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com