WCF - 实现需要加密一个soap:body元素的客户端,怎么做?

时间:2011-06-24 18:28:12

标签: c# wcf soap ws-security

我一直在寻找这一点,到目前为止它看起来并不乐观,试图编写一个消耗第三方服务的客户端应用程序(下面的示例请求来自Java客户端)。一个问题是,它希望身体中的一个元素被加密。

理想情况下,这将是一个WCF解决方案,虽然我已经阅读了一些关于使用WSE1 / 2/3来接近这个的地方(因为WSE停滞不是真的很想),有没有人必须解决这类问题?

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://editedURL">
  <soap:Header>
    <wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
            wsu:Id="Timestamp-2d960151-fc35-4522-a8cd-b463025209d8">
        <wsu:Created>2010-11-23T16:17:36Z</wsu:Created>
      </wsu:Timestamp>
      <wsse:BinarySecurityToken ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" 
            EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" 
            xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
            wsu:Id="SecurityToken-68e70781-8ff5-4e08-b066-8b9c6badef37"><!--token was here --></wsse:BinarySecurityToken>
      <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
        <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
        <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
          <wsse:SecurityTokenReference>
            <wsse:Reference URI="#SecurityToken-68e70781-8ff5-4e08-b066-8b9c6badef37" 
            ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
          </wsse:SecurityTokenReference>
        </KeyInfo>
        <xenc:CipherData>
          <xenc:CipherValue><!--cypher was here --></xenc:CipherValue>
        </xenc:CipherData>
        <xenc:ReferenceList>
          <xenc:DataReference URI="#Enc-5293b4f0-9aa5-4c37-ad1c-7c55c7d9ded1"/>
        </xenc:ReferenceList>
      </xenc:EncryptedKey>
    </wsse:Security>
  </soap:Header>
  <soap:Body>
    <tns:Authenticate>
      <authIn>
        <authID><!-- user id was here plaintext --></authID>
        <authPwd wsu:Id="Id-8bac7fa6-fac9-4ce4-8a5e-3b221c64ca76" 
                xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
          <xenc:EncryptedData Id="Enc-5293b4f0-9aa5-4c37-ad1c-7c55c7d9ded1" Type="http://www.w3.org/2001/04/xmlenc#Content" 
                                mlns:xenc="http://www.w3.org/2001/04/xmlenc#">
            <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
            <xenc:CipherData>
              <xenc:CipherValue><!-- encrypted password was here --></xenc:CipherValue>
            </xenc:CipherData>
          </xenc:EncryptedData>
        </authPwd>
        <authServer><!-- domain was here plaintext --></authServer>
      </authIn>
    </tns:Authenticate>
  </soap:Body>
</soap:Envelope>

痛点是soap:Body中的authPwd元素,感谢任何见解

1 个答案:

答案 0 :(得分:4)

我给你带来了一个坏消息。开箱即用的安全实现is not able to do this我不知道如何扩展WCF以支持它,除非您从头开始编写所有WS-Security内容。除了要扩展已经实现的协议的场景之外,WCF是非常可扩展的 - 这些类大多是密封/内部的,不能重用。

如果这些元素是SOAP头而不是body元素,那么整个问题就完全不同了。

编辑:

我再次检查了您提供的整个SOAP消息,我发现了另外两个问题。

  • 我怀疑您的服务提供的安全级别。它不显示纯文本密码,但它可以是全部。隐藏密码不仅是您需要的安全性,因为如果安全性未正确实施,攻击者可以简单地接收您的整个消息(按原样加密)并再次从他的计算机发送。如果服务配置不正确,它将以任何其他方式处理该请求。这称为重放攻击,对此攻击的主要防御是时间戳,但由于您的消息未签名,攻击者可以按照自己的意愿更改时间戳值。 EncryptedKey元素中可以有其他防御机制,但很难从消息本身说出来。
  • 即使服务加密整个机构,WCF也很可能无法处理消息。开箱即用的安全性需要签名 - 时间戳必须签名(由于上述原因),消息部分可以是签名或加密签名,但不仅是加密的。签署加密部分将确保攻击者不会将发布的数据替换为另一个。
相关问题