2013-12-12 58 views
2

我正在嘗試爲我也寫過的基於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 ...

+1

你錯過的是,你需要指向一個有效信任庫具有與服務器證書相匹配的有效證書。 – GreyBeardedGeek

+0

@GreyBeardedGeek謝謝。你是否在說,除非我爲有效的信任庫提供了與服務器證書相匹配的有效證書,否則生成/編譯後的代碼將把我的'pom.xml'中的' Withheld

+1

不,我的意思是你的管道指定了一個信任庫,這樣信任庫必須包含服務器的證書,並且有一個有效的證書鏈給一個可信的證書,否則你會得到你得到的錯誤。 – GreyBeardedGeek

回答

3

問題解決了!

我跟着this magicmonster article小心(注意,「舊版本的Java」的亮點,和默認密碼「的changeit」),進口the entire self signed certificate chain到Java的信任證書列表:

http://magicmonster.com/kb/prg/java/ssl/pkix_path_building_failed.html

有一個非常重要的額外的扭曲:爲鏈中的所有證書,而不僅僅是根!(在我的情況下,有三個:我的組織,中間和根)

然後...轉到Spring應用程序上下文XML配置和修改<http:conduit部分對Java的cacerts的正確路徑(和密碼)文件:

<http:tlsClientParameters> 
    <sec:keyManagers keyPassword="changeit"> 
    <sec:keyStore type="JKS" password="changeit" 
        file="C:\Program Files (x86)\Java\jdk1.6.0_45\jre\lib\security\cacerts"/> 
    </sec:keyManagers> 
    <sec:trustManagers> 
    <sec:keyStore type="JKS" password="changeit" 
        file="C:\Program Files (x86)\Java\jdk1.6.0_45\jre\lib\security\cacerts"/> 
    </sec:trustManagers> 
相關問題