【发布时间】:2014-07-23 05:17:17
【问题描述】:
我们可以设置签名算法如下:
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 消息,则应该存在此限制。以下是该文章的摘录:
更改 IdP 签名/摘要算法和相关设置是 目前是全球运营。算法将改变所有 与之交互的依赖方。在您完成之前不要进行此更改 已验证您的所有依赖方都可以使用 您选择的新算法
更新:终于找到了完成这项工作的方法。已将其添加为答案。
【问题讨论】:
-
这不就是sha256到底是什么吗?
-
据我了解签名算法和 DigestMethod 算法(在 Reference 元素内)是两个不同的东西。
标签: opensaml