【问题标题】:WIF ID 4036 Error - Troubleshoot, Ideas?WIF ID 4036 错误 - 疑难解答,想法?
【发布时间】:2011-07-25 14:17:53
【问题描述】:

我以为理解这一点,但我很难过,希望这里有人可以增加一些清晰度。

我编写了一个自定义 STS。我编写了一个单独的、简单的依赖方来输出 STS 的声明。它适用于我的本地机器。如果我将 STS 和 RP 部署到同一台服务器,我可以让它工作。但是,尝试从我的开发盒运行 RP,访问开发服务器,我收到 ID4036 错误(ID4036:无法从以下安全密钥标识符“CN=Cin1Web07-Dev. paycor-test.com116108771XXXXXX3182074711bOkGGQaGymVHZXc9v8AsLyx / Qiy0fhmKKu88BVinXvx4ySzBMqmb1IiY7DSFAXR1PeFevfTxmzmZwu1ztPyJWpNV0LzKnVbxrqChH7iREfYhp5EHUzF0tCdJ49Q / XL3laN / Nh971hxPzj0rBQIIJ8bK / vW70x6gCkIj4Wy50Qow =”。确保SecurityTokenResolver填充了所需的关键)

我尝试在索赔指南和编程 WIF 书籍中寻找答案,但没有成功。另外,我找到了这个网站:http://consultingblogs.emc.com/simonevans/archive/2010/11/19/common-windows-identity-foundation-ws-federation-exceptions-explained.aspx,但它也没有让我更进一步。

如果有人有任何故障排除提示或想法,我将不胜感激。以下是我正在做的事情的详细信息:

STS 使用简单的 cn=LocalHost 对证书进行签名,此处设置为:

public static MetadataBase GetFederationMetadata()
{
    string endpointId = WebConfigurationManager.AppSettings["ActiveSTSUrl"];
    EntityDescriptor metadata = new EntityDescriptor();
    metadata.EntityId = new EntityId(endpointId);

    // Define the signing key
    X509Certificate2 cert = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, GetCertificateNameForSigningMetadata());
    metadata.SigningCredentials = new X509SigningCredentials(cert);

    // Create role descriptor for security token service
    SecurityTokenServiceDescriptor stsRole = new SecurityTokenServiceDescriptor();
    stsRole.ProtocolsSupported.Add(new Uri(WSFederationMetadataConstants.Namespace));
    metadata.RoleDescriptors.Add(stsRole);

    // Add a contact name
    ContactPerson person = new ContactPerson(ContactType.Administrative);
    person.GivenName = "contactName";
    stsRole.Contacts.Add(person);

    // Include key identifier for signing key in metadata
    SecurityKeyIdentifierClause clause = new X509RawDataKeyIdentifierClause(cert);
    SecurityKeyIdentifier ski = new SecurityKeyIdentifier(clause);
    KeyDescriptor signingKey = new KeyDescriptor(ski);
    signingKey.Use = KeyType.Signing;
    stsRole.Keys.Add(signingKey);

    // Add endpoints
    string activeSTSUrl = WebConfigurationManager.AppSettings["ActiveSTSUrl"];
    EndpointAddress endpointAddress = new EndpointAddress(new Uri(activeSTSUrl),
                                                null,
                                                null, GetMetadataReader(activeSTSUrl), null);
    stsRole.SecurityTokenServiceEndpoints.Add(endpointAddress);

    ExposeClaimTypesOffered(stsRole);

    return metadata;
}

并设置在这里:

public MembershipSTSConfiguration() : base()
{
    X509Certificate2 signingCert = CertificateUtil.GetCertificate(
        StoreName.My,
        StoreLocation.LocalMachine,
        Common.GetCertificateNameForSigningMetadata());

    this.SigningCredentials = new X509SigningCredentials(signingCert);
    this.SecurityTokenService = typeof(MembershipSTS);
    this.TokenIssuerName = "MembershipSTS";
}

我调用了 GetCertificateNameForSigningMetadata 方法,但我的理解是这也对令牌进行了签名。

在我的 RP 中,我有这个部分 - 指纹与来自 STS 服务器的 cn=localhost 的指纹匹配:

  <issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
    <trustedIssuers>
      <add thumbprint="A6F68xxxxxxxx575EBDC" name="http://cin1web07-dev.paycor-test.com:8080/PaycorAuthServices/PassiveSTS.aspx" />
    </trustedIssuers>
  </issuerNameRegistry>

我相信所有配置都正确。但是,加密部分是我认为存在问题的地方。这在 RP 的 web.config 中。下面的指纹引用了一个名为 RelyingParty.MyOrg 的证书。

  <serviceCertificate>
    <certificateReference x509FindType="FindByThumbprint" findValue="AA310FF423XXXXXXXX910F9C69" storeLocation="LocalMachine" storeName="My" />
  </serviceCertificate>

证书与私钥一起安装在我的开发机器(RP)上。证书颁发机构也存在于我的机器上。我将证书导出到开发服务器和 CA 证书。它们似乎设置正确。在 STS 的 GetScope 中,我有这个:

protected override Scope GetScope(IClaimsPrincipal principal, RequestSecurityToken request)
{
    Scope scope = new Scope(request.AppliesTo.Uri.AbsoluteUri, SecurityTokenServiceConfiguration.SigningCredentials);
    scope.EncryptingCredentials = new X509EncryptingCredentials(CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine,
                System.Configuration.ConfigurationManager.AppSettings["CertificateNameForEncryptingToken"]));

    scope.ReplyToAddress = scope.AppliesToAddress + "/Default.aspx";
    return scope;
}

AppSetting 映射到 cn=RelyingParty.MyOrg,并且正在查找我相信的证书(因为如果我更改 1 个字母,我会收到不同的“找不到证书”错误)。

尽管如此,当我使用 STS 时,我的开发盒上还是得到了 ID4036。

这是真正难倒我的部分——在更改为 RelyingParty.MyOrg 证书后,开发服务器上的 RP 仍然有效——即使它设置为旧的 cn=localhost 并且没有用于cn=RelyingParty.MyOrg.

很明显,我不明白其中的一些配置。我为这篇冗长的帖子道歉,但我真的很想把它结束。如果有人有任何建议,我将不胜感激。

【问题讨论】:

    标签: certificate wif


    【解决方案1】:

    您的开发盒似乎没有 RP 解密令牌所需的私钥。 STS 只需要公钥来加密令牌,这就是它没有失败的原因。如果你在开发服务器上安装了私钥,可能是私钥权限设置错误,RP无法读取。

    【讨论】:

    • 我相信当用于颁发加密证书的证书无法验证时也会出现这种情况。在引用的帖子中,加密证书放置在我的商店中。如果移动到根存储,它似乎可以解决这个问题,或者在我这边。
    • 我有同样的问题,甚至权限都是正确的。仍然没有运气:(
    • 我在我的开发盒上安装了私钥,我的证书在 root 和我的,但仍然没有骰子。
    【解决方案2】:

    说来话长——但 STS 实际上是用错误的密钥加密...

    至于故障排除,这是一个真正需要解决的 PITA,但您必须真正查看原始声明令牌。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多