首页 > 解决方案 > WCF 服务器和 WS-Security 到 Java 客户端 (SoapUI)

问题描述

我正在尝试将 WS-Security 添加到我拥有的现有服务中,通过 TLS 访问所述服务,并且我已经成功地使用 SoapUI 对其进行了测试。

但是,我对返回的响应有疑问;即使响应看起来很完整,SoapUI 也会报告:

ERROR:org.apache.ws.security.WSSecurityException: An invalid security token was provided (Bad TokenType "")
   org.apache.ws.security.WSSecurityException: An invalid security token was provided (Bad TokenType "")
    at org.apache.ws.security.str.BSPEnforcer.checkEncryptedKeyBSPCompliance(BSPEnforcer.java:113)
    at org.apache.ws.security.str.SecurityTokenRefSTRParser.processPreviousResult(SecurityTokenRefSTRParser.java:313)
    at org.apache.ws.security.str.SecurityTokenRefSTRParser.parseSecurityTokenReference(SecurityTokenRefSTRParser.java:101)
    at org.apache.ws.security.processor.ReferenceListProcessor.decryptDataRefEmbedded(ReferenceListProcessor.java:169)
    at org.apache.ws.security.processor.ReferenceListProcessor.handleReferenceList(ReferenceListProcessor.java:104)
    at org.apache.ws.security.processor.ReferenceListProcessor.handleToken(ReferenceListProcessor.java:64)
    at org.apache.ws.security.WSSecurityEngine.processSecurityHeader(WSSecurityEngine.java:402)

我正在阅读的内容来看,这是由于回复中 SecurityTokenReference 元素上缺少 TokenType 属性,这是遵守基本安全配置文件的条件。

问题是 - 如何在 WCF 中填充此属性?我没有找到任何明确的信息。

WCF 服务的 SOAP 响应中的加密密钥部分如下所示:

 <e:EncryptedKey Id="_0" xmlns:e="http://www.w3.org/2001/04/xmlenc#">
    <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
       <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" xmlns="http://www.w3.org/2000/09/xmldsig#"/>
    </e:EncryptionMethod>
    <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
       <o:SecurityTokenReference>
          <o:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">K6Ag94AG3hQuQ+rqQcBvb88Vl+Y=</o:KeyIdentifier>
       </o:SecurityTokenReference>
    </KeyInfo>
    <e:CipherData>
       <e:CipherValue>FQ58hAfisez2D8J9A49xFRQjfTSFhrWP9wJDnWq0MctAyLhoAynzu3/Z0jYK91uE4DVCgkFo9QGH6O/kR1icQxkpv/xb5gcB1mJTbIpbCOzw6ZtMEfbY0r9ML2fDcChGFPM/nh70Daqi4P9IO8dIZ5EAUcERvDMFvj4fhwwVycSNFUX40/8ywQALQksPb+1j2B3pzHntcyb6CJ0qD10xjbyyQoT0BgR/HeDQEJDQNvx41eqoDSy2/ImkNNfFCXQ47/k1sN48tWur6GEzDuwUBbiAJxVrCgzc6a7F9CrhWiE6DAublBzM8/EBKP5UD5p2WTcjDQxI4cBhqRwIGYcfhQ==</e:CipherValue>
    </e:CipherData>
 </e:EncryptedKey>

我的 WCF 绑定如下所示:

  <customBinding>
    <binding name="NewBinding0">
      <security
          authenticationMode="MutualCertificate"
          allowSerializedSigningTokenOnReply="true"
          messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
          securityHeaderLayout="Lax"

          requireSignatureConfirmation="false"
          messageProtectionOrder="EncryptBeforeSign"
          includeTimestamp="false"
      >
        <localServiceSettings detectReplays="false" />

      </security>
      <textMessageEncoding messageVersion="Soap11" />
      <httpsTransport />
    </binding>
  </customBinding>

作为事后的想法,是否严格要求 BSP 是“好”消息?我看不到在 SoapUI 中关闭 BSP 检查的任何方法,但鉴于 WCF 不应用它,我认为它是可以接受的?最终,服务的消费者可能是 Java,可能是 .NET,可能是其他东西,所以如果可以禁用 BSP,我很高兴以更广泛的兼容性的名义放弃 BSP 支持。如果这看起来确实是一个可接受的路径,那么我如何在 SoapUI 中关闭 BSP 处理以进行测试,而不是尝试符合 BSP 的 .NET?(也就是说,如果通过调整绑定在 .NET 中启用 BSP 是直接的,我很乐意说服)。

标签: wcfsoapsoapuiws-security

解决方案


推荐阅读