【问题标题】:WIF- ID1014: The signature is not valid. The data may have been tampered withWIF-ID1014:签名无效。数据可能已被篡改
【发布时间】:2012-06-11 15:35:04
【问题描述】:

我一直在使用 WIF 来验证我们的新网站,STS 基于 starter-sts 实现。

为了使它能够在负载平衡环境中正常工作,我在 global.asax 中使用了以下内容来覆盖默认证书行为。

void onServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
        {
            List<CookieTransform> sessionTransforms = new List<CookieTransform>(new CookieTransform[] 
            { 
                new DeflateCookieTransform(), 
                new RsaEncryptionCookieTransform(e.ServiceConfiguration.ServiceCertificate),
                new RsaSignatureCookieTransform(e.ServiceConfiguration.ServiceCertificate)
            });

            SessionSecurityTokenHandler sessionHandler = new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly());
            e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler);
        }

这一切都在工作,人们已经成功地使用了这个系统,但是我们时不时地得到一个爆炸:

ID1014:签名无效。数据可能已被篡改。

在事件日志中,所以我打开了 WIF 跟踪并在日志中看到了以下内容。

ID1074:尝试使用 ProtectedData API 加密 cookie 时发生 CryptographicException(有关详细信息,请参阅内部异常)。如果您使用的是 IIS 7.5,这可能是由于应用程序池上的 loadUserProfile 设置设置为 false。

我有一种感觉,正如我所想的那样,这让我走上了一条黑暗的小巷,因为我已将实现更改为使用 RSA,这不应该影响我。

有什么想法可以帮助我吗?

【问题讨论】:

  • 感谢您的回复,仔细检查了所有内容,它工作正常,可以看到断点被捕获并且跟踪正在输出。我有 FederatedAuthentication.ServiceConfigurationCreated += onServiceConfigurationCreated;在应用程序启动中。

标签: wif federated-identity windows-identity ws-federation


【解决方案1】:

浏览器 cookie 使用“旧”机制 - DPAPI 进行加密。 因此,当服务器尝试解密 cookie 时,它​​会失败 - 您的代码现在使用 RSA,而不是 DPAPI。

作为一种解决方法,清除浏览器缓存,应用程序将按预期开始运行。

【讨论】:

  • 我们从未使用过其他系统,因为我们处于负载平衡环境中。
【解决方案2】:

我更改了实现以修改 onkencreated 方法中的超时。这样可以防止重新发布。

protected override void OnSessionSecurityTokenCreated(Microsoft.IdentityModel.Web.SessionSecurityTokenCreatedEventArgs args)
        {
            args.SessionToken = FederatedAuthentication.SessionAuthenticationModule.CreateSessionSecurityToken(
                args.SessionToken.ClaimsPrincipal,
                args.SessionToken.Context,
                DateTime.UtcNow,
                DateTime.UtcNow.AddDays(365),
                true
                );
            //base.OnSessionSecurityTokenCreated(args);
        }

【讨论】:

  • 这个覆盖对你得到的异常有什么作用?
  • 对不起,我不记得了,我得看看代码库。
  • 谢谢,如果有机会,可以告诉我吗?
【解决方案3】:

您是否尝试将 loadUserProfile 选项设置为 true?问题是否仍然存在?

(在 IIS 中选择应用程序池,然后点击右侧的“高级设置”。“加载用户配置文件”在“进程模型”部分)。

【讨论】:

  • 我们没有尝试过这个纯粹是因为我们使用的是 RSA 而不是 DPAPI。
【解决方案4】:

您的错误间歇性发生,再加上跟踪中显示的 DPAPI 异常,这表明您实际上并未覆盖 cookie 转换,您的服务仍在使用 DPAPI。

这可能是一个长镜头,但在您的代码 sn-p 中,我注意到您的方法覆盖“onServiceConfigurationCreated”以小写 o 开头。这样的错字确实会阻止您正确覆盖默认 WIF 行为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-28
    • 2016-06-24
    • 2012-07-18
    • 1970-01-01
    相关资源
    最近更新 更多