作为服务提供商,当尝试使用 SAML2 连接、使用 IdentityServer4 和 Sustainsys.Saml2.AspNetCore2 包连接到 IDP 时,我一直遇到运行时异常,并且没有真正的线索是否这是一个错误或如何解决它。据我所知,这是一个完全有效的加密算法,并且在检索 IDP 的 URL 的元数据时被接受为有效输入。不知道为什么它一直告诉我不是。客户端的元数据无法更改,并且
我确实成功连接到模拟的https://stupidp.sustainsys.com,使用
OutboundSigningAlgorithm = SignedXml.XmlDsigRSASHA1Url;
(但不确定这是否是有效的比较)。
SAML 元数据文件签名部分:
<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="#aselect-s.entree.kennisnet.nl">
<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>...
(查看完整文件https://hub-s.entree.kennisnet.nl/openaselect/profiles/saml2)
和基本配置
services.AddAuthentication()
.AddSaml2("...", "...", options =>
{ options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.SignOutScheme = IdentityServerConstants.DefaultCookieAuthenticationScheme;
options.SPOptions.ModulePath = "/Saml2";
options.SPOptions.EntityId = new EntityId("http://localhost:51827");
options.SPOptions.MetadataCacheDuration = new XsdDuration(hours: 1);
options.SPOptions.OutboundSigningAlgorithm = SignedXml.XmlDsigRSASHA1Url;
options.SPOptions.MinIncomingSigningAlgorithm = SignedXml.XmlDsigRSASHA1Url;
options.IdentityProviders.Add(
new IdentityProvider(
new EntityId("..."), options.SPOptions)
{
LoadMetadata = true,
MetadataLocation = "..."
});
options.SPOptions.ServiceCertificates.Add(new X509Certificate2("....pfx"));
options.SPOptions.Organization = organisation;
options.SPOptions.Contacts.Add(contact);
});
当单击按钮连接到此 IDP 时,这一切都会导致以下堆栈跟踪。
System.Security.Cryptography.CryptographicException: Unknown crypto algorithm 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'
at Sustainsys.Saml2.Internal.CryptographyExtensions.CreateAlgorithmFromName(String name, Object[] args)
at Sustainsys.Saml2.WebSso.Saml2RedirectBinding.AddSignature(String queryString, ISaml2Message message)
at Sustainsys.Saml2.WebSso.Saml2RedirectBinding.Bind(ISaml2Message message, ILoggerAdapter logger)
at Sustainsys.Saml2.WebSso.SignInCommand.InitiateLoginToIdp(IOptions options, IDictionary`2 relayData, Saml2Urls urls, IdentityProvider idp, Uri returnUrl)
at Sustainsys.Saml2.WebSso.SignInCommand.Run(EntityId idpEntityId, String returnPath, HttpRequestData request, IOptions options, IDictionary`2 relayData)
at Sustainsys.Saml2.AspNetCore2.Saml2Handler.ChallengeAsync(AuthenticationProperties properties)
at Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, String scheme, AuthenticationProperties properties)
我做错了什么还是没有得到正确的支持?
为什么连接到存根 IDP 时它会起作用?
这是否从CryptographyExtensions.s_extraAlgorithms
(参见开源代码)中丢失,因为它只显示列出的 3 种 RSA 类型,而代码中的其他列表通常将 SHA1 命名为第四个?