我正在嘗試爲我也寫過的基於CXF的Web服務實現客戶端。CXF客戶端:找不到要求的目標的有效證書路徑
我的web服務的偉大工程(經測試通過的soapUI工作正常),但在運行客戶端失敗,出現以下:
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:323)
消息明確指出在證書有問題,所以我做了快速搜索,發現正確的方法來supporting SSL in CXF並添加以下到我的Spring應用程序上下文XML配置:
<http:conduit name="https://myserver/myws/register/soap?wsdl:{http://glob.reg.com/myws}.http-conduit">
<http:tlsClientParameters>
<sec:keyManagers keyPassword="password">
<sec:keyStore type="JKS" password="password"
file="my/file/dir/Morpit.jks"/>
</sec:keyManagers>
<sec:trustManagers>
<sec:keyStore type="JKS" password="password"
file="my/file/dir/Truststore.jks"/>
</sec:trustManagers>
<sec:cipherSuitesFilter>
<!-- these filters ensure that a ciphersuite with
export-suitable or null encryption is used,
but exclude anonymous Diffie-Hellman key change as
this is vulnerable to man-in-the-middle attacks -->
<sec:include>.*_EXPORT_.*</sec:include>
<sec:include>.*_EXPORT1024_.*</sec:include>
<sec:include>.*_WITH_DES_.*</sec:include>
<sec:include>.*_WITH_AES_.*</sec:include>
<sec:include>.*_WITH_NULL_.*</sec:include>
<sec:exclude>.*_DH_anon_.*</sec:exclude>
</sec:cipherSuitesFilter>
</http:tlsClientParameters>
<http:authorization>
<sec:UserName>Betty</sec:UserName>
<sec:Password>password</sec:Password>
</http:authorization>
<http:client AutoRedirect="true" Connection="Keep-Alive"/>
</http:conduit>
並重建客戶端。客戶端的內置成功,但我仍然得到相同的確切的錯誤和相同的確切的堆棧跟蹤,就好像我從來沒有添加這個http:conduit
的東西。
我還沒有將商店證書添加到商店,商店路徑不正確,但這是故意的,因爲我只是想看看重新構建的客戶端如何報告此問題,並調整爲新的http:conduit
信息。
相反,我很驚訝地發現它完全被忽略。
我錯過了什麼?
接近這個的正確方法是什麼?
更新:我只注意到我的applicationContext.xml強調http:conduit
與此錯誤消息:
The prefix "http" for element "http:conduit" is not bound.
所以我做了快速搜索,發現a thread這表明:
客戶端需要配置帶有密鑰庫的HTTP管道, 包含STS的證書,e .G:
<http:conduit name="https://localhost:.*">
<http:tlsClientParameters disableCNCheck="true">
<sec:trustManagers>
<sec:keyStore type="jks" password="cspass" resource="clientstore.jks"/>
</sec:trustManagers>
</http:tlsClientParameters>
</http:conduit>
這強化什麼@GreyBeardedGeek寫道。現在去work on this ...
你錯過的是,你需要指向一個有效信任庫具有與服務器證書相匹配的有效證書。 – GreyBeardedGeek
@GreyBeardedGeek謝謝。你是否在說,除非我爲有效的信任庫提供了與服務器證書相匹配的有效證書,否則生成/編譯後的代碼將把我的'pom.xml'中的'
Withheld
不,我的意思是你的管道指定了一個信任庫,這樣信任庫必須包含服務器的證書,並且有一個有效的證書鏈給一個可信的證書,否則你會得到你得到的錯誤。 – GreyBeardedGeek