为什么在使用 spring 和 CXF 时出现 bad_certificate 错误

发布于 2024-09-28 12:16:43 字数 2087 浏览 0 评论 0原文

我正在使用 CXF 生成的代码通过 SSL 并通过公司代理连接到远程 Web 服务。当通过 Java API 建立连接并且所有 SSL 设置都设置为系统属性时,代码可以正常工作,如下所示。

System.setProperties("https.proxyHost", "myproxy.com");
System.setProperties("https.proxyPort", "8001");
System.setProperties("javax.net.ssl.keyStoreType", "pkcs12");
System.setProperties("javax.net.ssl.keyStore", "C:/keystore.p12");
System.setProperties("javax.net.ssl.keyStorePassword", "keypassword");
System.setProperties("javax.net.ssl.trustStore", "C:/cacerts");
System.setProperties("javax.net.ssl.trustStorePassword", "capassword");

MyWebService_Service ss = new MyWebService_Service(wsdlUrl, SERVICE_NAME);
MyWebService service = ss.getMyWebServicePort();

使用此代码,我现在可以调用服务方法,一切都按预期进行。当我尝试使用 Spring 设置相同的配置时,我的问题出现了,这是我们的首选方法,因为我们已经广泛使用 Spring。

我的 Spring 配置:

<!-- relevant snippet from spring context -->

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />

<jaxws:client id="webservice" serviceName="myns:MyWebService" endpointName="myns:MyWebServicePort"
     address="https://bigserver.com:5012/blah/TheWebService"
     serviceClass="com.mycomp.MyWebService" />

<http:conduit name="{myns}MyWebServicePort.http-conduit">
   <http:tlsClientParamenters disableCNCheck="true" secureSocketProtocol="TLS">
      <sec:trustManagers>
         <sec:keyStore type="JKS" password="capassword" file="c:/cacerts" />
      </sec:trustmanagers>
      <sec:keyManagers>
         <sec:keyStore type="pkcs12" password="keypassword" file="c:/keystore.p12" />
      </sec:keyManagers>
   </http:tlsClientParamenters>
   <http:client ProxyServer="myproxy.com" ProxyServerPort="8001" />
</http:conduit>

在这两种情况下,Web 服务客户端都部署在 Web 应用程序中。在第二种情况下,访问 Web 服务会导致编辑

javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate

:我正在使用 CXF 版本 2.2。

I am using CXF generated code to connect to a remote web service over SSL and through a corporate proxy. The code works fine when the connection is established through the Java API and all SSL settings are set as system properties as follows.

System.setProperties("https.proxyHost", "myproxy.com");
System.setProperties("https.proxyPort", "8001");
System.setProperties("javax.net.ssl.keyStoreType", "pkcs12");
System.setProperties("javax.net.ssl.keyStore", "C:/keystore.p12");
System.setProperties("javax.net.ssl.keyStorePassword", "keypassword");
System.setProperties("javax.net.ssl.trustStore", "C:/cacerts");
System.setProperties("javax.net.ssl.trustStorePassword", "capassword");

MyWebService_Service ss = new MyWebService_Service(wsdlUrl, SERVICE_NAME);
MyWebService service = ss.getMyWebServicePort();

Using this code I can now call the service methods and everything works as expected. My problems occur when I try to set up the same configuration with Spring, which is our preferred approach since we are already using Spring extensively.

My Spring config:

<!-- relevant snippet from spring context -->

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />

<jaxws:client id="webservice" serviceName="myns:MyWebService" endpointName="myns:MyWebServicePort"
     address="https://bigserver.com:5012/blah/TheWebService"
     serviceClass="com.mycomp.MyWebService" />

<http:conduit name="{myns}MyWebServicePort.http-conduit">
   <http:tlsClientParamenters disableCNCheck="true" secureSocketProtocol="TLS">
      <sec:trustManagers>
         <sec:keyStore type="JKS" password="capassword" file="c:/cacerts" />
      </sec:trustmanagers>
      <sec:keyManagers>
         <sec:keyStore type="pkcs12" password="keypassword" file="c:/keystore.p12" />
      </sec:keyManagers>
   </http:tlsClientParamenters>
   <http:client ProxyServer="myproxy.com" ProxyServerPort="8001" />
</http:conduit>

In both cases, the web service client is deployed within a web application. In the second case, access to the web service results in a

javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate

Edit: I am using CXF version 2.2.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冬天旳寂寞 2024-10-05 12:16:43

您是否尝试过将下一个属性添加到客户端参数中?

**useHttpsURLConnectionDefaultHostnameVerifier="false"**

看起来像这样:

Have you tried adding the next property to your client parameters?

**useHttpsURLConnectionDefaultHostnameVerifier="false"**

Looks like this:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文