具有自定义 SAML2 策略和 Sha256 作为签名算法的 Azure B2C
Azure B2C with custom SAML2 policy and Sha256 as the signing algorithm
我正在使用 Sustainsys 包 Sustainsys.Saml2.AspNetCore2
在 ASP.NET Core 3.1 中构建服务提供商 Web 应用程序,它使用 Azure B2C 作为使用 SAML2
的身份提供商。我有以下问题:
如果我使用 Sha1
作为签名算法,使用选项 MinIncomingSigningAlgorithm
,那么 CryptoConfig.CreateFromName
会抛出异常,因为该方法不知道Sha1
算法。
如果我使用 Sha256
作为签名算法,那么 Azure B2C 使用 Sha1
对响应进行签名,即使我在 RelyingParty
我的自定义策略。 我应该注意到,这似乎只发生在服务提供商启动单点注销流程时。 登录流程顺利完成,签名算法为 Sha256
。这是我的 RelyingParty 部分:
<RelyingParty>
<DefaultUserJourney ReferenceId="SignUpOrSignIn" />
<TechnicalProfile Id="PolicyProfile">
<DisplayName>PolicyProfile</DisplayName>
<Protocol Name="SAML2"/>
<Metadata>
<Item Key="XmlSignatureAlgorithm">Sha256</Item>
</Metadata>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="displayName" />
<OutputClaim ClaimTypeReferenceId="givenName" />
</OutputClaims>
<SubjectNamingInfo ClaimType="objectId" ExcludeAsClaim="true"/>
</TechnicalProfile>
</RelyingParty>
此外,Azure B2C的元数据使用Sha256
作为签名和摘要方法。这是相关部分:
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="...">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="saml samlp xenc xs"/>
</Transform>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
</Reference>
</SignedInfo>
非常感谢任何帮助。谢谢。
事实证明,我还需要将 <Item Key="XmlSignatureAlgorithm">Sha256</Item>
添加到技术配置文件中(除了它是 RelyingParty 的一部分,如上所示)。这解决了我在单点注销时遇到的问题。
<TechnicalProfile Id="Saml2AssertionIssuer">
<Protocol Name="None"/>
<OutputTokenFormat>SAML2</OutputTokenFormat>
<Metadata>
<Item Key="XmlSignatureAlgorithm">Sha256</Item>
</Metadata>
</TechnicalProfile>
我正在使用 Sustainsys 包 Sustainsys.Saml2.AspNetCore2
在 ASP.NET Core 3.1 中构建服务提供商 Web 应用程序,它使用 Azure B2C 作为使用 SAML2
的身份提供商。我有以下问题:
如果我使用
Sha1
作为签名算法,使用选项MinIncomingSigningAlgorithm
,那么CryptoConfig.CreateFromName
会抛出异常,因为该方法不知道Sha1
算法。如果我使用
Sha256
作为签名算法,那么 Azure B2C 使用Sha1
对响应进行签名,即使我在RelyingParty
我的自定义策略。 我应该注意到,这似乎只发生在服务提供商启动单点注销流程时。 登录流程顺利完成,签名算法为Sha256
。这是我的 RelyingParty 部分:
<RelyingParty>
<DefaultUserJourney ReferenceId="SignUpOrSignIn" />
<TechnicalProfile Id="PolicyProfile">
<DisplayName>PolicyProfile</DisplayName>
<Protocol Name="SAML2"/>
<Metadata>
<Item Key="XmlSignatureAlgorithm">Sha256</Item>
</Metadata>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="displayName" />
<OutputClaim ClaimTypeReferenceId="givenName" />
</OutputClaims>
<SubjectNamingInfo ClaimType="objectId" ExcludeAsClaim="true"/>
</TechnicalProfile>
</RelyingParty>
此外,Azure B2C的元数据使用Sha256
作为签名和摘要方法。这是相关部分:
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="...">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="saml samlp xenc xs"/>
</Transform>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
</Reference>
</SignedInfo>
非常感谢任何帮助。谢谢。
事实证明,我还需要将 <Item Key="XmlSignatureAlgorithm">Sha256</Item>
添加到技术配置文件中(除了它是 RelyingParty 的一部分,如上所示)。这解决了我在单点注销时遇到的问题。
<TechnicalProfile Id="Saml2AssertionIssuer">
<Protocol Name="None"/>
<OutputTokenFormat>SAML2</OutputTokenFormat>
<Metadata>
<Item Key="XmlSignatureAlgorithm">Sha256</Item>
</Metadata>
</TechnicalProfile>