WIF-ID1014:签名无效.数据可能已被篡改

Rub*_*ord 8 federated-identity windows-identity wif ws-federation

我一直在使用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);
        }
Run Code Online (Sandbox Code Playgroud)

这一切都正常工作,人们已成功使用该系统,但不时我们得到一个爆炸:

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

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

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

我有一种感觉,正如我想的那样,这导致我走入一条黑暗的小巷,因为我改变了使用RSA的实现,这不应该影响我.

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

ZEN*_*NIT 5

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

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


Rub*_*ord 2

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

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);
        }
Run Code Online (Sandbox Code Playgroud)