如何使用OpenSAML设置Signature DigestMethod算法

dro*_*rox 5 opensaml

我们可以将签名算法设置如下:

signature.setSignatureAlgorithm("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
Run Code Online (Sandbox Code Playgroud)

我正试图找到一种方法来设置DigestMethod算法.是否可以通过OpenSAML API?任何输入都非常感谢.

更新:为清晰度添加样本签名.这个问题关注的是它中的DigestMethod元素.

<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <ds:SignedInfo>
      <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
      <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
      <ds:Reference URI="#_884D49DAD03AD60748547F8322C11AA0">
        <ds:Transforms>
          <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
          <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
        </ds:Transforms>
        <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
        <ds:DigestValue>...</ds:DigestValue>
      </ds:Reference>
    </ds:SignedInfo>
    <ds:SignatureValue>...</ds:SignatureValue>
    <ds:KeyInfo>
      <ds:KeyName>...</ds:KeyName>
    </ds:KeyInfo>
  </ds:Signature>
Run Code Online (Sandbox Code Playgroud)

更新:弗拉基米尔的答案有效.但是,该解决方案似乎线程不安全?在我的应用程序中,我们只引导opensaml一次,然后由具有不同配置的不同线程使用 - 如不同的签名算法.有没有办法以线程安全的方式执行此操作?

更新:Shibboleth IdP使用opensaml,根据Shibboleth IdP Wiki,目前这是一个全局配置.因此,无论IdP还是SP方面,如果opensaml用于处理SAML消息,则应该存在此限制.以下是该文章的摘录:

更改IdP签名/摘要算法和相关设置目前是全局操作.该算法将针对与其交互的所有依赖方进行更改.在您确认所有依赖方都可以使用您选择的新算法处理响应之前,请不要进行此更改

更新:终于找到了完成这项工作的方法.添加了它作为答案.

Vla*_*fer 7

在应用程序初始化期间尝试以下调用:

  BasicSecurityConfiguration config = (BasicSecurityConfiguration) Configuration.getGlobalSecurityConfiguration();
  config.setSignatureReferenceDigestMethod(SignatureConstants.ALGO_ID_DIGEST_SHA256);
Run Code Online (Sandbox Code Playgroud)

  • 顺便说一句,SignatureConstants没有ALGO_ID_DIGEST_SHA256.它位于org.opensaml.xml.encryption.EncryptionConstants中. (2认同)

dro*_*rox 7

这可以通过在设置签名[1]后修改签名的内容引用来安全地完成.

例如

authnRequest.setSignature(signature);

((SAMLObjectContentReference)signature.getContentReferences().get(0))
           .setDigestAlgorithm(EncryptionConstants.ALGO_ID_DIGEST_SHA256);
Run Code Online (Sandbox Code Playgroud)

[1] https://lists.internet2.edu/sympa/arc/mace-opensaml-users/2007-10/msg00003.html