3

我正在尝试将 SAML2 IdP 配置Salesforce为 IdentityServer3 中的外部提供程序。我正在使用SustainSys/Saml2库。因此,出于测试目的,我下载了SampleIdentityServer3。并配置 SAML2 IdP,如下所示

    private void ConfigureSaml2(IAppBuilder app, string signInAsType)
    {
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

        var options = new Saml2AuthenticationOptions(false)
        {
            SPOptions = new SPOptions
            {
                EntityId = new EntityId("http://localhost:4589/IdSrv3/Saml2"),    
                MinIncomingSigningAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
            },
            SignInAsAuthenticationType = signInAsType,
            Caption = "SAML2p",

        };

        UseIdSrv3LogoutOnFederatedLogout(app, options);

        options.SPOptions.ServiceCertificates.Add(new X509Certificate2(
            AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "/App_Data/Sustainsys.Saml2.Tests.pfx"));

        var idp = new IdentityProvider(
            new EntityId("https://XXXXXX-dev-ed.my.salesforce.com"),
            options.SPOptions)
        {
            MetadataLocation = "https://XXXXXX-dev-ed.my.salesforce.com/.well-known/samlidp.xml",
            LoadMetadata = true,                
        };

        options.IdentityProviders.Add(idp);
        app.UseSaml2Authentication(options);
    }

请注意,如果我没有设置MinIncomingSigningAlgorithm为 sh1,那么 SustainSys 库会引发错误。

Sustainsys.Saml2.Exceptions.InvalidSignatureException:签名算法http://www.w3.org/2000/09/xmldsig#rsa-sha1弱于最低接受 http://www.w3.org/2001/04/ xmldsig-more#rsa-sha256。如果要允许此签名算法,请使用 minIncomingSigningAlgorithm 配置属性。

所以我设置为MinIncomingSigningAlgorithm摆脱"http://www.w3.org/2000/09/xmldsig#rsa-sha1"错误。

但后来我得到不同的错误

Sustainsys.Saml2.Exceptions.InvalidSignatureException:使用签名中包含的密钥正确验证了签名,但该密钥不受信任。

根据问题#493 #735,元数据中的证书必须与 SAML2 响应中的证书匹配。

在元数据中,证书是(注意开始和结束值)

  <ds:X509Data>
    <ds:X509Certificate>
       MIIGk... removed from brevity....tmv6J1g==
    </ds:X509Certificate>
  </ds:X509Data>

但在 SAML2 响应中(由 SustainSys 库记录的响应)

<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" Destination="http://localhost:4589/IdSrv3/Saml2/Acs" ID="_19fd2d8d9aab0401f56fXXXXXXXXX" InResponseTo="id473a52c49f194bXXXXXXXXX"    IssueInstant="2018-08-27T20:10:04.296Z" Version="2.0">
    <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">https://XXXXXXX-dev-ed.my.salesforce.com</saml:Issuer>
    <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="#_19fd2d8d9aab0401f56f642dXXXXXXXXXXXXX">
                <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#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="ds saml samlp" /></ds:Transform>
                </ds:Transforms>
                <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                <ds:DigestValue>fQiiyd0T57Ztr5BAfMFe9MTrhY0=</ds:DigestValue>
            </ds:Reference>
        </ds:SignedInfo>
        <ds:SignatureValue>
            B6hndlsBgY45J+hm8My2gPVo....removed for brevity....YT88ajt7jQ==
        </ds:SignatureValue>
        <ds:KeyInfo>
            <ds:X509Data>
                <ds:X509Certificate>
                    MIIENz... remove for brevity....y2Ul24Jyc4V/jJN
                </ds:X509Certificate>
            </ds:X509Data>
        </ds:KeyInfo>
        </ds:Signature>
        <samlp:Status>
            <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:AuthnFailed" />
        </samlp:Status>
    </samlp:Response>

查看X509Certificate元数据和 SAML2 响应中的值,它们不匹配。

问题SAML2 响应中
的值是否应该与元数据中的值匹配?如果是,为什么 SustainSys 库不能始终使用SAML2 响应中的值?X509CertificateX509CertificateX509Certificate

更新
只是为了看看匹配值是否有效,我将 SAML2 响应中的证书值保存到单独的.cer文件中。然后在 KeyInfoSerializer.cs 文件中我更新ReadX509Certificate了方法(这是从元数据加载证书的方法)

    private static SecurityKeyIdentifierClause ReadX509Certificate(XmlReader reader)
    {
        reader.ReadStartElement("X509Certificate", SignedXml.XmlDsigNamespaceUrl);
        ((XmlDictionaryReader)reader).ReadContentAsString();

        var cer = new X509Certificate2(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "/App_Data/salesforcepublickey.cer");
        var clause = new X509RawDataKeyIdentifierClause(cer);
        reader.ReadEndElement();
        return clause;
    }

但是,它仍然会引发错误The signature verified correctly with the key contained in the signature, but that key is not trusted.

4

2 回答 2

3

找到了。
这是 Salesforce 方面的问题。在 Saleforce 中,当我检查日志时,Identity->Identity Provider Event Log我看到了错误Error: User does not have access to this service provider

为此,用户没有被授予权限。即使用户是系统管理员,默认情况下也不会授予对 Connected App 的访问权限。要授予权限,请转到“管理用户-> 用户”并单击您正在测试的用户的编辑。单击配置文件名称链接。例如系统管理员。这需要配置文件页面。您可以在下方滚动到“连接的应用程序访问”,您会看到未授予访问权限。通过单击页面顶部的编辑配置文件授予访问权限。

于 2018-08-27T22:48:17.090 回答
1

与这个无关,但是当我们用谷歌搜索错误时,这个问题首先出现,所以在这里发布解决方案。我们在我们的 ASP.net 应用程序中与第三方提供商的 kentor auth 服务库进行了集成,但由于上述错误而失败。

问题是 IIS 不知何故无法访问证书存储。我们为我们的网站启用loadUserProfile了设置,Application Pool它能够完美运行。我们在 Windows Server 2016 上应用了这个。

于 2019-12-03T07:09:16.940 回答