ssl - 如何设置 Apache CXF 客户端以使用 WebSphere 信任库? (接收到 "No trusted certificate found"异常。)

标签 ssl websphere cxf websphere-6.1

首先,我将从总结开始。我正在使用 Apache CXF 客户端通过 SSL 与使用自签名证书的 Apache CXF 服务提供商进行通信。我将证书导入客户端服务器上的 WebSphere 信任库,但我仍然收到“javax.net.ssl.SSLHandshakeException:SSLHandshakeException 调用 https://somesvcprovider.com/appname/svc/myservice:com.ibm.jsse2.util.h:未找到可信证书”异常。

现在,这里是详细信息:

我有一个使用 Spring 配置的 Apache CXF Web 服务客户端,该客户端部署到 WebSphere 6.1 应用程序服务器。 CXF 客户端与不同 WebSphere 服务器上的 Apache CXF 服务提供者通信。通信使用 SSL。

服务提供商使用的是自签名证书。我已经通过管理控制台将提供商的证书导入到客户端服务器上的 WebSphere 信任库中。我通过转到 SSL 证书和 key 管理 > SSL 配置 > NodeDefaultSSLSettings > keystore 和证书 > NodeDefaultTrustStore > 签名者证书来完成此操作;然后我使用“从端口检索”工具导入证书。

但是,我在尝试联系服务提供商时仍然收到此错误:“javax.net.ssl.SSLHandshakeException:SSLHandshakeException 调用 https://somesvcprovider.com/appname/svc/myservice:com.ibm.jsse2.util.h:未找到受信任的证书”。

Spring配置文件如下:

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:sec="http://cxf.apache.org/configuration/security"
  xmlns:http="http://cxf.apache.org/transports/http/configuration"
  xmlns:jaxws="http://cxf.apache.org/jaxws"
  xsi:schemaLocation="
      http://cxf.apache.org/configuration/security
      http://cxf.apache.org/schemas/configuration/security.xsd
      http://cxf.apache.org/transports/http/configuration
      http://cxf.apache.org/schemas/configuration/http-conf.xsd
      http://cxf.apache.org/jaxws
      http://cxf.apache.org/schemas/jaxws.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd">
    <http:conduit name="*.http-conduit">
        <!-- deactivate HTTPS url hostname verification (localhost, etc) -->
        <!-- WARNING ! disableCNcheck=true should not used in production. -->
        <http:tlsClientParameters disableCNCheck="true" />
    </http:conduit>
    <!-- Read properties from property file(s). -->
    <bean id="propertyPlaceholderConfigurer"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <!-- The *.spring.properties files are prefixed with a system property
                    that is set on the WebSphere server. -->
                <value>classpath:spring.${my.env}.properties</value>
            </list>
        </property>
    </bean>
    <jaxws:client id="myServiceClient"
        serviceClass="com.client.stub.cxf.IMyService"
        address="${my.svc.url}" />
    <bean id="myReport" class="com.client.MyReportRequestor">
        <property name="client" ref="myServiceClient"/>
    </bean>
</beans>

如上所示,CXF 客户端是通过 Spring 通过 setter 注入(inject)的。联系服务的代码如下:

List<String> formNames = client.retrieveNames(formIdsList);

此外,我不知道这是否相关,但是当我在运行时检查 CXF 客户端上的 TLSClientParameters 对象时,没有返回任何信任管理器。执行检查的代码如下:

// Get the trust managers for this client.
Client proxy = ClientProxy.getClient(client);
HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
TLSClientParameters tls = conduit.getTlsClientParameters();
TrustManager[] trustManagers = tls.getTrustManagers();  // trustManagers is null

我还需要做些什么来让 Apache CXF 客户端信任自签名证书吗?

我宁愿不必在配置文件中指定信任库的路径和密码。

谢谢!

最佳答案

CXF 可能使用了错误的 SSL 套接字工厂。

尝试将此添加到您的 Spring 配置中:

<http-conf:conduit name="*.http-conduit">
    <http-conf:tlsClientParameters useHttpsURLConnectionDefaultSslSocketFactory="true"/>
</http-conf:conduit>

关于ssl - 如何设置 Apache CXF 客户端以使用 WebSphere 信任库? (接收到 "No trusted certificate found"异常。),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7275063/

相关文章:

php - 第一次身份验证以获得 token

java - 从 SOAP 安全 header 获取 X 509 证书

java - Websphere ScheduledExecutorService 线程

java - 如何使用基于 WSDL 的 Web 服务通知客户端(Java、C#)

java - Apache-cxf JAXRSClient 自定义日期格式

sql - 带加密的同步框架

delphi - 印地 "Could not load SSL library"德尔福 XE2 IW14

ssl - 使用 NSURLConnection 时 Mac OS 10.9 以上的默认 SSLLevel

java - Spring org.apache.openjpa.persistence.InvalidStateException : you cannot access the EntityTransaction when using managed transactions

java - Websphere 与 Oracle DB 部署错误 NosuchMethod