gpt4 book ai didi

javax.net.ssl.SSLHandshakeException : java. security.cert.CertificateException:没有可用的 X509TrustManager 实现

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

我的应用程序中有代码尝试使用具有指定证书的 HTTPS 连接到外部主机。

我的代码是这样的:

    //Load Two Keystores
KeyStore keystore = KeyStore.getInstance("pkcs12", "SunJSSE");
InputStream keystoreInput = new FileInputStream(cerPath);
keystore.load(keystoreInput, passwd.toCharArray());
System.out.println("Keystore has " + keystore.size() + " keys");

// load the truststore, leave it null to rely on cacerts distributed with the JVM
KeyStore truststore = KeyStore.getInstance("pkcs12", "SunJSSE");
InputStream truststoreInput = new FileInputStream(cerPath);
truststore.load(truststoreInput, passwd.toCharArray());
System.out.println("Truststore has " + truststore.size() + " keys");

//ssl context
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, null, null);
SSLSocketFactory sf = new SSLSocketFactory(keystore, passwd);
Scheme https = new Scheme("https", 443, sf);

SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(https);
...
client = new DefaultHttpClient(new PoolingClientConnectionManager(schemeRegistry));
...
HttpResponse httpResponse = client.execute( targetHost, httpMethod);

变量 cerPath 包含用于建立连接的证书 (xxxx.pfx) 的路径。

在独立应用程序中,这完美地工作,但在我的 spring-boot 应用程序中,相同的代码抛出此异常:

javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No X509TrustManager implementation available

我已经在普通的 Spring 应用程序中测试了这段代码,它也能正常工作。

普通的 SSL 属性 () 也不起作用。

最佳答案

最后我们发现了问题。

我们的 pom.xml 中有一个指向框架 wiremock 的依赖项:

     <dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>1.43</version>
<exclusions>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>

此框架在产生此问题的 jar 中包含一个/keystore 文件。当我们从 pom 中删除此依赖项时,一切正常。

关于javax.net.ssl.SSLHandshakeException : java. security.cert.CertificateException:没有可用的 X509TrustManager 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22467084/

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