gpt4 book ai didi

opensaml - 如何使用 OpenSAML 设置 Signature DigestMethod 算法

转载 作者:行者123 更新时间:2023-12-02 21:45:44 31 4
gpt4 key购买 nike

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

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

我正在尝试找到一种方法来设置 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>

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

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

Changing the IdP signature/digest algorithm and related settings is currently a global operation. The algorithm will be changed for all relying parties it interacts with. Do not make this change until you have verified that all your relying parties can handle responses using the new algorithm(s) you choose

更新:终于找到了完成此任务的方法。已将其添加为答案。

最佳答案

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

例如

authnRequest.setSignature(signature);

((SAMLObjectContentReference)signature.getContentReferences().get(0))
.setDigestAlgorithm(EncryptionConstants.ALGO_ID_DIGEST_SHA256);

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

关于opensaml - 如何使用 OpenSAML 设置 Signature DigestMethod 算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24902391/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com