Dyl*_*tie 5 forms-authentication machinekey asp.net-mvc-4
我有两个 .NET Web 应用程序在同一台服务器上运行 - sentinel(托管在https://sentinel.mydomain.com/)和fortknox(在http://www.mydomain.com/fortknox)
Sentinel 是一个身份验证“门户”。FortKnox 是一个“概念证明”应用程序,它使用表单身份验证,但将 loginUrl 设置为https://sentinel.mydomain.com/login(以及一个特殊的 Application_EndRequest 处理程序来限定 ReturnUrl)。Sentinel 是使用 MVC 4 和 Razor 用 .NET 4.0 编写的;FortKnox 是使用 .NET 2.0 的 ASP.NET MVC 2。
我正在使用 ASP.NET FormsAuthentication 并将 cookie 域设置为 ,.mydomain.com
以便设置 的 cookiesentinel.mydomain.com
将与请求一起发送到www.mydomain.com
,反之亦然。cookie 部分运行良好- 两个应用程序都获得相同的 .ASPXAUTH 加密表单票证。
问题是,在我们的生产服务器上,fortknox无法解密由哨兵创建的cookie——即使它们具有相同的机器密钥。即使两个应用程序都在同一个物理盒子上运行,它也不起作用。
用户点击 fortknox,他们被重定向到哨兵,他们登录,设置了 cookie,他们被重定向回 fortknox,然后我得到“无法验证数据”:
Exception: Unable to validate data.
at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo, Boolean signData)
at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo)
at System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket)
at FortKnox.Web.MvcApplication.Application_BeginRequest()
Run Code Online (Sandbox Code Playgroud)
机器键是相同的 - 我已经在每个页面的标记中包含了这块(讨厌的!)代码:
try {
var cookie = Request.Cookies[".ASPXAUTH"].Value;
Response.Write("Cookie: " + cookie + Environment.NewLine);
var ticket = FormsAuthentication.Decrypt(cookie);
Response.Write("Ticket name: " + ticket.Name + Environment.NewLine);
} catch (Exception x) {
Response.Write("Exception: " + x.Message + Environment.NewLine);
Response.Write(x.StackTrace);
}
Response.Write("<hr /></pre>");
var machineConfigMachineKey = (MachineKeySection)WebConfigurationManager.OpenMachineConfiguration().SectionGroups["system.web"].Sections["machineKey"];
var webConfigMachineKey = (MachineKeySection)WebConfigurationManager.OpenWebConfiguration("").SectionGroups["system.web"].Sections["machineKey"];
Response.Write("<pre>");
Response.Write("<b>machine.config decrypt: </b>" + machineConfigMachineKey.DecryptionKey + "<br />");
Response.Write("<b>web.config decrypt: </b>" + webConfigMachineKey.DecryptionKey + "<br />");
Response.Write("<br />");
Response.Write("<b>machine.config validate: </b>" + machineConfigMachineKey.ValidationKey + "<br />");
Response.Write("<b>web.config validate: </b>" + webConfigMachineKey.ValidationKey + "<br />");
Response.Write("</pre>");
Response.Write("<hr />");
Run Code Online (Sandbox Code Playgroud)
并验证运行时使用的机器密钥完全相同。
特别令人沮丧的是,这一直在我们的开发和登台服务器上工作,但仅在生产中失败。服务器之间的唯一区别是生产设备经常安装 Windows 更新,而我们的开发/临时设备可能缺少一些更新;它们在其他方面是相同的(从同一图像克隆并使用相同的设置脚本创建)
所以...相同的服务器;相同的机器密钥。ASP.NET 4 设置 FormsAuthentication cookie。ASP.NET 2 应用程序无法解密它。错误只发生在某些服务器上;在其他人身上,它正在起作用。在这一点上,我完全被困住了……有什么想法吗?
编辑:实时服务器已升级到最新的补丁级别。我试过申请
<add key="aspnet:UseLegacyEncryption" value="true" />
Run Code Online (Sandbox Code Playgroud)
对于登录应用程序和 fortknox 应用程序,都是 true 和 false。还是没有运气...
它是否有可能与旧的 2010 padding oracle 安全补丁有关 - http://weblogs.asp.net/scottgu/archive/2010/09/28/asp-net-security-update-now-available.aspx?尝试设置
<add key="aspnet:UseLegacyEncryption" value="true" />
强制打补丁的服务器像打补丁之前一样运行?
(或者,你知道......修补你的服务器。你的选择。)