我正在尝试为我也写过的基于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
一样。
我还没有将证书添加到商店,并且商店的路径不正确,但这是故意的,因为我只是想看看重建的客户端如何报告此问题,调整为新的{{1信息。
相反,我很惊讶地发现它完全被忽略了。
我错过了什么?
接近这个的正确方法是什么?
更新:我刚注意到我的applicationcontext.xml以{1}}为下划线,显示以下错误消息:
http:conduit
所以我做了一个快速搜索,发现a thread暗示:
客户端需要使用密钥库配置HTTP管道 包含STS的证书,例如:
http:conduit
这加强了@GreyBeardedGeek所写的内容。现在去work on this ......
答案 0 :(得分:3)
问题解决了!
我仔细跟踪this magicmonster article(请注意“旧版java”的重点,以及默认密码'changeit'),将the entire self signed certificate chain导入到Java的可信证书列表中: / p>
http://magicmonster.com/kb/prg/java/ssl/pkix_path_building_failed.html
有一个非常重要的附加扭曲:为链中的所有证书执行此操作,而不仅仅是root!(在我的情况下有三个:我的组织,中间和根)
然后...转到 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>