签名使用签名中包含的密钥正确验证,但该密钥不受信任

问题描述 投票:1回答:1

我正在尝试将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响应中的X509Certificate值是否应与元数据中的X509Certificate值匹配?如果是,为什么SustainSys库总是不能使用来自SAML2响应的X509Certificate值?

更新 只是为了查看匹配值是否有效,我将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.

salesforce kentor-authservices sustainsys-saml2
1个回答
2
投票

找到了。 这是Salesforce方面的问题。在Saleforce,当我检查日志qazxsw poi我看到错误qazxsw poi

为此,用户未获得许可。即使用户是系统管理员,默认情况下也不会授予对已连接应用程序的访问权限。要获得许可,请转到“管理用户 - >用户”,然后单击要测试的用户的编辑。单击配置文件名称链接.e.g系统管理员。这需要配置文件页面。您可以在下面滚动到“已连接的应用程序访问”,您将看到未提供访问权限。通过单击页面顶部的编辑配置文件来授予访问权限。

© www.soinside.com 2019 - 2024. All rights reserved.