SAML 错误 "SignatureStatus: NOT_PRESENT"

SAML error "SignatureStatus: NOT_PRESENT"

更新

我发现,如果我将受信任的证书添加到 SPOptions.ServiceCertificates 并设置 SPOptions.AuthenticateRequestSigningBehavior = Sustainsys.Saml2.Configuration.SigningBehavior.IfIdpWantAuthnRequestsSigned; 并设置 IdentityProvider.WantAuthnRequestsSigned = true,则包含签名元素。


原问题:

使用以下 AuthnRequest 连接到 IDP 时遇到问题:

<saml2p:AuthnRequest xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="idf299bf8aa08542d193e022cb047e5ecc" Version="2.0" IssueInstant="2019-07-23T00:10:13Z" Destination="https://example-idp.com" AssertionConsumerServiceURL="https://example-sp.com/Acs">
<saml2:Issuer>https://example-sp.com</saml2:Issuer>
</saml2p:AuthnRequest>

IDP 说:“SignatureStatus:NOT_PRESENT”。我猜这意味着 authnrequest 应该有一个 <ds:Signature 部分?如果是这样,我如何配置 Sustainsys.Saml2.AspNetCore2 以包含它?

我从 idp 收到的元数据 xml 包含一个 <ds:Signature 部分,但是查看 Sustainsys.Saml2.AspNetCore2 的源代码,看起来这部分元数据在反序列化?

我不是很熟悉 SAML 的内部结构,如果这是一个愚蠢的问题,我很抱歉。

您需要生成一个 self-signed .pfx 文件,其中包含您的 public 证书和私钥。我们使用 azure key vault,但您也可以使用 openssl。许多资源解释了如何生成其中一个并将其加载到 c# X509Certificate2 实例中。

获得 X509Certificate2 实例后,设置 options.SPOptions.AuthenticateRequestSigningBehavior = Sustainsys.Saml2.Configuration.SigningBehavior.IfIdpWantAuthnRequestsSigned;

并设置IdentityProvider.WantAuthnRequestsSigned = true.

然后像这样添加 X509Certificate2 实例:options.SPOptions.ServiceCertificates.Add(myX509Certificate2);

然后 运行 您的应用程序并启动 SAML SSO 过程。您可以使用 hookbin 或类似工具查看它在 AuthnRequest 中为 SAMLRequest 发送的内容。您可以通过 url 解码从中提取 xml,然后像 javascript 中那样对其进行 base64 解码,例如确认签名 xml 已设置且正确:atob(decodeURIComponent(samlRequestValue))