【问题标题】:CXF client: unable to find valid certification path to requested targetCXF 客户端:无法找到请求目标的有效证书路径
【发布时间】:2013-12-12 21:25:01
【问题描述】:

我正在尝试为我也编写的基于 CXF 的 Web 服务实现一个客户端。

我的 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 的证书,例如:

 <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 谢谢。你是说除非我提供有效的信任库和与服务器证书匹配的有效证书,否则生成/编译的代码会将我的pom.xml 中的&lt;http:conduit 部分视为我从未将它放在那里?
  • 不,我是说您的管道指定了一个信任库,因此该信任库必须包含服务器的证书,并具有指向受信任证书的有效证书链,否则您将收到以下错误你得到了。
  • @GreyBeardedGeek 我现在要试试你的建议(见上面的更新)。我在这非常兼职工作,所以我需要一些时间才能对新的见解采取行动。感谢您迄今为止的帮助。
  • @GreyBeardedGeek 好的,我终于从头开始构建一个完整的信任库,包含整个证书链并包含在客户端的 JAR 中,但这根本没有帮助,发出了同样的错误。我有一种感觉是错误的方向。现在的问题是我如何从这里开始?

标签: java spring web-services ssl cxf


【解决方案1】:

问题解决了!

我仔细按照this magicmonster article(注意“older version of java”的突出显示,以及默认密码'changeit'),将the entire self signed certificate chain导入Java的受信任证书列表:

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

还有一个非常重要的附加转折:对链中的所有证书都这样做,而不仅仅是根!(在我的例子中,有三个:我的组织的、中间和根)

然后... 转到 Spring 应用程序上下文配置 XML 并修改 &lt;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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 2011-10-18
    • 2020-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多