【问题标题】:How does STR-Transform works?STR-Transform 是如何工作的?
【发布时间】:2018-01-05 22:14:03
【问题描述】:

在使用 WS Security 时,STR-Transform 转换算法如何用于 XML 签名?我需要对用于 SOAP 消息签名的 SecurityTokenReference 进行签名,这是安全令牌所需的转换。我正在使用 x509 证书进行签名,所以安全令牌就是这个证书。但是,在消息中我只需要对证书指纹的引用。

这是我需要复制的签名结构,我唯一缺少的是对 SecurityTokenReference 的签名引用:

<dsig:Signature xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
  <dsig:SignedInfo>
    <dsig:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    <dsig:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
    <dsig:Reference URI="#Timestamp_C1Ih1AB1vpPT5uG2">
      <dsig:Transforms>
        <dsig:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
      </dsig:Transforms>
      <dsig:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
      <dsig:DigestValue>fVSyToUO8yS131cV8oT1h6fa69Jvtt+pKFeP4BFf1P4=</dsig:DigestValue>
    </dsig:Reference>
    <!-- Other signature references -->
    <dsig:Reference URI="#str_U1sjQ5j8JtKnObLk">
      <dsig:Transforms>
        <dsig:Transform Algorithm="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#STR-Transform">
          <wsse:TransformationParameters>
            <dsig:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
          </wsse:TransformationParameters>
        </dsig:Transform>
      </dsig:Transforms>
      <dsig:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
      <dsig:DigestValue>gRa3zakGn13XISoKpekB3zl0iDqb/LmNy7+aMDtzKIY=</dsig:DigestValue>
    </dsig:Reference>
  </dsig:SignedInfo>
  <dsig:SignatureValue>ptO...E9Q==</dsig:SignatureValue>
  <dsig:KeyInfo>
    <wsse:SecurityTokenReference
                    xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                    xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"
                    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                    wsse11:TokenType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"
                    wsu:Id="str_U1sjQ5j8JtKnObLk">
      <wsse:KeyIdentifier
                        EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
                        ValueType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1">h5...ow=</wsse:KeyIdentifier>
    </wsse:SecurityTokenReference>
  </dsig:KeyInfo>
</dsig:Signature>

有人可以解释我如何为此类令牌进行签名吗?算法的分步描述,或使用任何语言/库的示例都会很好。

In this document is the description of the transformation,从第 38 页开始,但我无法理解如何在实践中应用它。

【问题讨论】:

    标签: language-agnostic x509 ws-security xml-signature


    【解决方案1】:

    好的,在检查了 Oracle 的 WebLogic 服务器调试和详细日志文件(包含一个工作服务示例)并设置了标志 -Dweblogic.xml.crypto.dsig.debug=true -Dweblogic.xml.crypto.dsig.verbose=true -Dweblogic.xml.crypto.keyinfo.debug=true -Dweblogic.xml.crypto.keyinfo.verbose=true -Dweblogic.wsee.verbose=* -Dweblogic.wsee.debug=*(更多信息 herehereherehere)之后,感谢上帝关于如何取消引用安全令牌是一个很好的见解。基本上,具有用于 x509 证书的 SecurityTokenReferenceKeyIdentifier 以这种方式被取消引用为 BinarySecurityToken

    <wsse:BinarySecurityToken xmlns="" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">CertificateBase64String</wsse:BinarySecurityToken>
    

    需要注意的一些重要事项是:

    • ValueType 以及BinarySecurityToken 的内容由SecurityTokenReferenceTokenType 定义。在这种情况下,BinarySecurityToken 的文本是由 KeyIdentifier 元素引用的 x509 证书,编码为 base64 字符串。
    • 根据规范,BinarySecurityToken 只包含ValueType 属性。所以它不应该包含EncodingType 属性,也不应该包含SecurityTokenReference 所具有的Id 属性。
    • 使用与SecurityTokenReference 相同的命名空间前缀。此外,此前缀的命名空间包含在标记中。
    • 默认命名空间属性设置为空:xmlns=""

    所以基本上整个SecurityTokenReference 元素被新的BinarySecurityToken 替换,这是要规范化和散列的元素(以获取其摘要值)。请注意,它是按原样进行规范化和摘要化的,因此如果通过删除空的 xmlns 命名空间或前缀命名空间或更改命名空间前缀来简化 XML,则该操作可能会提供错误的结果。

    示例 BinarySecurityToken 已经使用算法“http://www.w3.org/2001/10/xml-exc-c14n#”进行规范化,因此在 .NET 中,使用摘要算法“http://www.w3.org/2001/04/xmlenc#sha256”获取 DigestValue 就足够了:

    System.Security.Cryptography.SHA256 sha = System.Security.Cryptography.SHA256.Create();
    byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes("<wsse:BinarySecurityToken xmlns=\"\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\">MIIF...2A8=</wsse:BinarySecurityToken>"));
    string digestValue = Convert.ToBase64String(hash);
    

    【讨论】:

    • it is canonicalized and digested as is, so the operation may provide a wrong result if the XML is simplified by removing the empty xmlns namespace or the prefix namespace, or by changing the namespace prefix. “空的 xmlns 命名空间”是什么意思?你能详细说明吗?您是说引用的 BinarySecurityToken 元素必须显式包含一个顶级属性,例如 xmlns=""
    • 您还说“根据规范,BinarySecurityToken 仅包含 ValueType 属性。”你能引用你所指的规范吗?
    • @Cheeso about it is canonicalized and digested as is 我的意思是取消引用的 BinarySecurityToken 应该按原样使用,而不删除任何空属性。如果 xmlns 属性为空,则有一些解析 XML 库会删除它。
    • @Cheeso 关于According to the specification, the BinarySecurityToken only includes the ValueType attribute.,说实话,我不记得了。我想我的意思是消息中的Security 部分。
    • 感谢您的回复!
    猜你喜欢
    • 2015-07-18
    • 1970-01-01
    • 2021-12-10
    • 2020-06-23
    • 2021-10-27
    • 2013-08-10
    • 2015-06-18
    • 1970-01-01
    • 2013-09-27
    相关资源
    最近更新 更多