c# - 我需要哪些 SOAP/WS-Security/WS-Addressing/etc 来发送这条消息

标签 c# .net visual-studio web-services ws-security

编辑: 我认为唯一需要理解的是使用 username token profile 对消息进行签名。 .任何关于如何实现的指示/线索/信息都会很棒。我玩过带有 WSE 2 的 Visual Studio .Net 2003,并且用户名 token 配置文件示例是否是默认设置 - 所以我的后备方案是使用它,但更喜欢在 Linux 上运行,因为那是我们拥有的服务器。加上没有 WSE 的单声道端口。我的印象是这没有被使用太多/它被弃用了......

我必须与 Web 服务对话,并得到了下面的示例。我正在尝试将其翻译成英语……或者至少了解我需要查看哪些 WS 安全规范才能与之通信。

我正在使用 Ruby/Savon对于其他 WS 调用,但它似乎只支持基本的 WSSE,用户名/密码。

我可以看到这条消息有一个签名 - 但它是通过外部文件/证书/代码签名的,还是我在下面有足够的详细信息来在我自己的代码中进行相同的签名。

我没有看到任何 X509 或 Cipher 条目,这似乎暗示它没有使用这样的证书(在我对此的幼稚理解中),那么生成签名的是什么 - 也许只是消息的简单散列?

它似乎还使用了某种摘要/消息检查,因为当我尝试调整样本并重新发送它时,它被退回为无效 - 虽然我猜这可能与签名问题有关......

我认为 Savon 不支持这个,所以我想我需要切换到 JRuby 并使用 Java WS 库,也许 RampartAxis2或者也许 Spring security位。任何提示/推荐/好的教程?我看到 this from IBM ,但我想我需要更高层次的东西,这样我才能掌握“大局”

<?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:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">

  <soap:Header>
    <wsa:Action wsu:Id="Id-6762c167-412b-4bf8-8839-518e9bc25da5">
    http://host/path/func</wsa:Action>
    <wsa:MessageID wsu:Id="Id-00bb0af8-232d-43a8-adbb-39f230599c56">
    uuid:2005639d-39b8-4df6-bf41-e18741c45291</wsa:MessageID>
    <wsa:ReplyTo wsu:Id="Id-c53a1dbe-244f-46a9-b656-883f4b06dcfe">
      <wsa:Address>
      http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address>
    </wsa:ReplyTo>
    <wsa:To wsu:Id="Id-017877f6-e5a3-43ae-aa2b-4886adb7060c">
    http://host/path/func.asmx</wsa:To>
    <wsse:Security soap:mustUnderstand="1">
      <wsu:Timestamp wsu:Id="Timestamp-1a38d0f9-077f-4e95-991b-fa899a171920">

        <wsu:Created>2011-03-14T15:00:09Z</wsu:Created>
        <wsu:Expires>2011-03-14T15:05:09Z</wsu:Expires>
      </wsu:Timestamp>
      <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
      wsu:Id="SecurityToken-42ae32d2-f6ff-431e-9369-7696b44965e3">
        <wsse:Username>crypteduser</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
        cryptedpass</wsse:Password>
        <wsse:Nonce>fLSoqLm9kuOumxy39JRHaw==</wsse:Nonce>
        <wsu:Created>2011-03-14T15:00:09Z</wsu:Created>
      </wsse:UsernameToken>
      <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
        <SignedInfo>
          <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"
          xmlns:ds="http://www.w3.org/2000/09/xmldsig#" />
          <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#hmac-sha1" />
          <Reference URI="#Id-6762c167-412b-4bf8-8839-518e9bc25da5">

            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            <DigestValue>SAYl5o1kh33HteOe0L7G6KIKqWg=</DigestValue>
          </Reference>
          <Reference URI="#Id-00bb0af8-232d-43a8-adbb-39f230599c56">

            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            <DigestValue>//LMuFkNC1FO1/9A9W7l6o75Y2M=</DigestValue>
          </Reference>
          <Reference URI="#Id-c53a1dbe-244f-46a9-b656-883f4b06dcfe">

            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            <DigestValue>9pgN7bU48UKi1UTnpOCikOnp2G0=</DigestValue>
          </Reference>
          <Reference URI="#Id-017877f6-e5a3-43ae-aa2b-4886adb7060c">

            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            <DigestValue>lWZNjtSHfVtiZeOFZAosV868Uos=</DigestValue>
          </Reference>
          <Reference URI="#Timestamp-1a38d0f9-077f-4e95-991b-fa899a171920">

            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            <DigestValue>H3nYPY6kfIWEIWQhpwaz8VKeQIM=</DigestValue>
          </Reference>
          <Reference URI="#Id-f95dfea2-3af8-4e95-8e60-141858db9532">

            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            <DigestValue>uRTu+Hzxw+zdaTYgW0z+j35diIQ=</DigestValue>
          </Reference>
        </SignedInfo>
        <SignatureValue>
        Hdn2wxWhmr450pefMuc41o6GgOA=</SignatureValue>
        <KeyInfo>
          <wsse:SecurityTokenReference>
            <wsse:Reference URI="#SecurityToken-42ae32d2-f6ff-431e-9369-7696b44965e3"
            ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken" />
          </wsse:SecurityTokenReference>
        </KeyInfo>
      </Signature>
    </wsse:Security>
  </soap:Header>
  <soap:Body wsu:Id="Id-f95dfea2-3af8-4e95-8e60-141858db9532">
    <func xmlns="http://host/path/">
      <xml_in>yucky xml inside xml...</xml_in>
    </func>
  </soap:Body>
</soap:Envelope>

非常感谢您提供的任何提示/指示。

问候, 克里斯

编辑

似乎与这个问题类似...它确实使用了 X509 证书,所以也许需要它。 目前正在阅读wikipedia entry为此。

编辑2

看起来像这样 - 希望基于用户名的选项... http://msdn.microsoft.com/en-us/library/ms824647.aspx

编辑3

我想我拥有大部分sorted now - 最突出的是用户名摘要。我该怎么做——签名值从哪里来...

编辑4

认为我最好的选择是在 .Net 中编写一个客户端,这将给我足够的线索来直接在 Ruby 中完成它,或者我可以将它包装在一个更简单的版本中 - 至少在短期内......

最佳答案

这并不是一个完整的答案,只是我注意到的一些事情。

wsse:SecurityTokenReference 引用此文档(以神秘的肥皂方式):http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0.pdf

我会通读:3.2 token 引用

此外,父部分提到了这个公式:

Password_Digest = Base64 ( SHA-1 ( nonce + created + password ) )  

也许尝试这样的签名?

Password_Digest = Base64 ( SHA-1 ( nonce + created + UsernameToken ) )  

关于c# - 我需要哪些 SOAP/WS-Security/WS-Addressing/etc 来发送这条消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5349546/

相关文章:

c# - 如何隐藏RadioButton控件中的圆圈?

c# - 使用MEF,如何导出ItemsControl的 View ?

c# - 指定了无效的 DN 语法 - Visual Studio 错误

visual-studio - 使用 VS 将 C++ 库编译为静态库和动态 dll

c# - 在 asp.net 环境中处理缓存

C# 应用程序 : how to view the loaded assemblies

c# - 使用 UA-.NET 调用 OPC-UA 方法

c# - 'System.ServiceModel.Diagnostics.TraceUtility' 的类型初始值设定项抛出异常

c# - 类中所有值类型的通用函数

visual-studio - 如何检测未使用的进口?