【问题标题】:The provided payload cannot be decrypted because it was not protected with this protection provider on the /connect/endsession/callback提供的有效负载无法解密,因为它没有在 /connect/endsession/callback 上受到此保护提供程序的保护
【发布时间】:2020-10-12 09:13:34
【问题描述】:

有一个 .net core 3.0 web 应用程序,里面有 IdentityServe4。应用程序托管在 Azure Web 场上。 在日志中,我发现消息有几个例外:

读取受保护消息的异常 - 提供的有效负载无法解密,因为它不受此保护提供程序的保护。

请求路径:/connect/endsession/callback

堆栈跟踪:

System.Security.Cryptography.CryptographicException:
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore 
(Microsoft.AspNetCore.DataProtection, Version=3.1.8.0, Culture=neutral, 
PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect 
(Microsoft.AspNetCore.DataProtection, Version=3.1.8.0, Culture=neutral, 
PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect 
(Microsoft.AspNetCore.DataProtection, Version=3.1.8.0, Culture=neutral, 
PublicKeyToken=adb9793829ddae60)
at IdentityServer4.Stores.ProtectedDataMessageStore`1.ReadAsync (IdentityServer4, Version=3.1.3.0, 
Culture=neutral, PublicKeyToken=f294d0afe402bb2b)

数据保护设置:

services.AddDataProtection()
        .PersistKeysToAzureBlobStorage(container, keyStorage.Path)
        .ProtectKeysWithAzureKeyVault(client, keyEncryption.KeyIdentifier)

最近,我们添加了services.AddOidcStateDataFormatterCache(schemes);SQL Distributed 缓存实现。

有人知道为什么会发生这个异常以及如何解决它吗?

【问题讨论】:

  • 错误表明客户端和服务器(包括证书)没有使用相同的加密算法(和设置),因此服务器无法验证密钥。如果您删除了最近的增强功能,代码是否有效?五年前,由于安全问题,业界淘汰了 TLS 1.0/1.1,并要求使用 TLS 1.2/1.3。 6 月,微软推出了一项安全更新,该更新禁用了服务器上的 TLS 1.0/1.1。我之前没有看到您的异常,所以我不确定您的更改是否导致异常或异常是由于客户端使用 TLS 1.0/1.1 和服务器拒绝连接。
  • 感谢您的回复,很好的假设。问题是代码正在运行,我无法重现它。但我不时会看到 Application Insight 日志。
  • 知道错误发生多长时间。请求开始时是否应该记录日志文件?请参阅:social.msdn.microsoft.com/Forums/azure/en-US/…

标签: c# .net-core identityserver4 asp.net-core-3.1


【解决方案1】:

会不会是创建数据保护 API 密钥的代码已更改? 您是否有许多应用程序使用相同的密钥环存储?

我刚刚在博客中介绍了如何使用数据保护 API 以及如何在 Azure Key Vault 中存储密钥环:

Storing the ASP.NET Core Data Protection Key Ring in Azure Key Vault

【讨论】:

  • 我只有一个应用程序,它是 webfarm。有什么注意事项吗?顺便说一句,好文章,谢谢。如果您简要介绍一下密钥轮换和 WebFarm 中的具体使用(当然,如果有的话)会很有用
  • 是的,有几个问题,例如github.com/dotnet/aspnetcore/issues/26786
猜你喜欢
  • 2019-09-10
  • 1970-01-01
  • 2011-12-27
  • 2014-06-28
  • 2019-03-26
  • 1970-01-01
  • 1970-01-01
  • 2012-12-18
  • 1970-01-01
相关资源
最近更新 更多