首先,我將從總結開始。我正在使用Apache CXF客戶端通過SSL與使用自簽名證書的Apache CXF服務提供者進行通信。我將證書導入到客戶端服務器上的WebSphere信任庫中,但我仍然收到「javax.net.ssl.SSLHandshakeException:調用了SSLHandshakeException https://somesvcprovider.com/appname/svc/myservice:com.ibm.jsse2.util.h:沒有發現可信證書」異常。如何設置Apache CXF客戶端以使用WebSphere信任庫? (接收「找不到可信證書」異常。)
現在,這裏的細節:
我有我使用Spring配置一個Apache CXF Web服務客戶端,客戶端部署到WebSphere 6.1應用服務器。 CXF客戶端與不同的WebSphere服務器上的Apache CXF服務提供者進行通信。通信使用SSL。
服務提供商正在使用自簽名證書。我已經通過管理控制檯將提供者的證書導入到客戶端服務器上的WebSphere信任庫中。我通過轉到SSL證書和密鑰管理> SSL配置> NodeDefaultSSLSettings>密鑰存儲區和證書> 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注入。聯繫服務的代碼如下:
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客戶信任的自簽名證書?
我更喜歡不必在配置文件中指定信任庫的路徑和密碼。
謝謝!
我找不到使用WAS truststores的方法,所以我會假設您必須在配置文件中指定truststore,如您所述。 –
我發現@kjetil解決方案更可行,因爲它不需要自定義開發 –