验证来自 ADFS 的 SAML 响应

Verify SAML Response from ADFS

我在验证从 ADFS 服务器获得的 SAML 响应时遇到问题。我得到的响应是 url,例如 CALLBACK_URL?SAMLResponse=ENCODED_XML&Signature=SIGNATURE_VALUE&SigAlg=SIGNATURE_ALGORITHM,而 SIGNATURE_ALGORITHMhttp://www.w3.org/2001/04/xmldsig-more#rsa-sha256。我设法解码了响应,但无法找到使用给定签名验证响应的方法。

我的主要问题是签名的格式非常出乎意料。由于给定的签名算法,我希望签名的长度为 32 个字节,但是当我对签名进行 base64 解码时得到的是一个长度为 256 的字符串。

我预计使用 base64 解码签名是不够的。不幸的是,到目前为止我还没有找到下一步该做什么。所以我的问题是:我需要做什么才能正确解码签名才能验证它?

我认为您将哈希与签名混为一谈。

签名将消息的散列作为输入并使用密钥对其进行加密。在您的情况下,SigAlg 参数表示 SAML 消息的 32 字节散列使用(显然)2048 位 RSA 私钥加密,可能使用 https://www.rfc-editor.org/rfc/rfc6931#section-2.3.2 中所述的 PKCS#1 v1.5 填充生成一个 256 字节的签名,可以使用发送方的相关 2048 位 RSA public 密钥进行验证。

除此之外:我假设您指的是 SAML 请求而不是 SAML 响应,因为后者不得使用 HTTP 重定向绑定发送,如 Web 浏览器 SSO 配置文件规范第 16 页中所述:https://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf(页面顶部):

  1. Identity Provider issues to Service Provider In step 5, the identity provider issues a message to be delivered by the user agent to the service provider. Either the HTTP POST, or HTTP Artifact binding can be used to transfer the message to the service provider through the user agent. The message may indicate an error, or will include (at least) an authentication assertion. The HTTP Redirect binding MUST NOT be used, as the response will typically exceed the URL length permitted by most user agents.