如何诊断 AWS Cognito 的 SAML 断言处理错误的原因?

How can I diagnose the cause of AWS Cognito's SAML assertion processing errors?

我正在尝试将 AWS Cognito 与第三方 SAML SSO 身份提供商集成。第三方 IdP 在登录时以成功的 SAML 断言进行响应。

Cognito 然后尝试验证断言的签名,但失败并显示以下错误消息:

Error in SAML response processing: SAML Assertion signature is invalid

如何诊断 Cognito 断言处理的原因?


我们已经用 samltest.id 测试了我们的 Cognito SP,它完全有效。

阅读 samltest.id's FAQ,来自 Shibboleth 的签名验证错误(与我的解决方案无关)通常意味着“用于签署断言的密钥与 usage="signing" 或 null 的任何有效密钥都不匹配在您的 IdP 的元数据中使用。"

这是我的 SP 元数据的编辑副本:

<?xml version="1.0"?>
<EntityDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" entityID="urn:amazon:cognito:sp:us-east-2_[REDACTED]" validUntil="2023-04-04T00:00:00Z">
  <SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol" WantAssertionsSigned="true">
    <KeyDescriptor use="signing">
      <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <ds:X509Data>
          <ds:X509Certificate>
            [REDACTED]
          </ds:X509Certificate>
        </ds:X509Data>
      </ds:KeyInfo>
    </KeyDescriptor>
    <NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent</NameIDFormat>
    <NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress</NameIDFormat>
    <NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName</NameIDFormat>
    <AssertionConsumerService index="1" isDefault="true" Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://[REDACTED].auth.us-east-2.amazoncognito.com/saml2/idpresponse" />
    <AssertionConsumerService index="2" isDefault="false" Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://[REDACTED].auth.us-east-2.amazoncognito.com/saml2/idpresponse" />
    <AttributeConsumingService index="1">
      <ServiceName xml:lang="en">AWS Vermeer Single Sign-On</ServiceName>
      <RequestedAttribute isRequired="true" Name="mail" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" FriendlyName="email" />
      <RequestedAttribute isRequired="false" Name="given_name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" FriendlyName="firstName" />
      <RequestedAttribute isRequired="false" Name="family_name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" FriendlyName="lastName" />
    </AttributeConsumingService>
  </SPSSODescriptor>
  <Organization>
    <OrganizationName xml:lang="en">[REDACTED]</OrganizationName>
    <OrganizationDisplayName xml:lang="en">[REDACTED]</OrganizationDisplayName>
    <OrganizationURL xml:lang="en">[REDACTED]</OrganizationURL>
  </Organization>
</EntityDescriptor>

不相关的 Whosebug 问题

首先查看 IdP 元数据。 IdP 使用 IdP 私钥签署 SAML 响应,SP 使用 IdP public 密钥验证签名。

IdP 元数据将包含证书,您可以验证证书是否与 SAML 响应中的证书匹配。

Could you please elaborate on how these keys work and how, if at all, the certificates in an IdP's metadata align with those in an SP's metadata?

这些将是标准 public 和私有 key-pair。当用于数字签名时,使用发件人的私钥对消息进行签名,并使用发件人的 public 密钥验证签名。

在 SAML 交换中,将有一个 SAML 请求(从 SP 到 IdP)和一个 SAML 响应(从 IdP 到 SP)。正式来说,请求 and/or 响应的签名是可选的,尽管 IdP/SP 可能需要它。 SAML 请求通常没有签名(尽管可以)。

因此,SAML 响应由 IDP 使用 IdP 私钥签名,签名由 SP 使用 IdP-supplied public 密钥验证。 SAML 请求将由 SP 使用 SP 的私钥签名,并由 IDP 使用 SP-supplied public 密钥进行验证。

IdP 元数据中的证书与 SP 元数据中的证书之间没有任何关系,除了两者都是 public 用于验证数字签名的证书。