forms-authentication – 使用不同Web应用程序之间的FormsAuthentication“无法验证数据”

我在同一台服务器上运行了两个.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,以便将sentinel.mydomain.com设置的cookie与请求一起发送到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() 

机器键是相同的 – 我已经在每页的标记中包含了这些(令人讨厌的!)代码:

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 />");

并验证在运行时使用的机器密钥完全相同.

特别令人沮丧的是,它一直致力于我们的开发和登台服务器,并且只在生产中失败了.服务器之间的唯一区别是生产盒经常安装Windows更新,而我们的开发/暂存盒可能缺少一些更新;它们在其他方面是相同的(从相同的图像克隆并使用相同的设置脚本创建)

所以……同样的服务器;同一台机器钥匙. ASP.NET 4设置了FormsAuthentication cookie. ASP.NET 2应用程序无法解密它.只在某些服务器上发生错误;在其他人身上,它正在发挥作用.在这一点上,我完全陷入困境……任何想法?

编辑:实时服务器已达到最新的补丁级别.我试过申请

<add key="aspnet:UseLegacyEncryption" value="true" />

对于登录应用程序和fortknox应用程序,无论是真还是假.仍然没有运气……

最佳答案 它有可能与旧的2010年填充oracle安全补丁 –
http://weblogs.asp.net/scottgu/archive/2010/09/28/asp-net-security-update-now-available.aspx有关吗?尝试设置

<add key="aspnet:UseLegacyEncryption" value="true" />

强制修补的服务器像补丁之前那样行事?

(或者,你知道……修补你的服务器.你的选择.)

点赞