我正在尝试使我的 ASP.NET MVC 4 应用程序与 FIPS 兼容。幸运的是,在 .NET 4.5 中,ASP.NET 已经使用 FIPS 批准的 AES 实现来进行 View 状态和 cookie 加密,因此这方面没有问题。
但是我遇到了一个奇怪的问题。这可以使用非常简约的 ASP.NET MVC 应用程序来重现。
创建简单的 Controller :
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[OutputCache(Duration = 5)]
public ActionResult Data()
{
return View();
}
}
为索引创建非常简单的 View :
<h2>Page</h2>
@Html.Action("Data")
和数据操作:
<h2>Data</h2>
所以基本上我们在这里尝试做的是对子操作使用输出缓存(在没有启用 FIPS 的情况下就像一个魅力)。
现在,如果我们运行它,我们将看到可怕的 FIPS 死机屏幕:
[InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.]
System.Security.Cryptography.SHA256Managed..ctor() +10840001[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +339 System.Security.Cryptography.CryptoConfig.CreateFromName(String name, Object[] args) +656 System.Security.Cryptography.SHA256.Create() +14 System.Web.Mvc.OutputCacheAttribute.GetChildActionUniqueId(ActionExecutingContext filterContext) +315
System.Web.Mvc.OutputCacheAttribute.OnActionExecuting(ActionExecutingContext filterContext) +118
正如您在这里看到的,异常本身发生在 OutputCacheAttribute.GetChildActionUniqueId
的 MVC 内部深处 - 显然它正在尝试使用非 FIPS 批准的 SHA256 哈希器,并且我看不到指示它的方法使用不同的。
因此,要尝试解决此问题,首先想到的就是在配置元素下的 web.config 文件中包含以下内容:
<runtime>
<enforceFIPSPolicy enabled="false"/>
</runtime>
但是,我意识到像我之前的许多人一样,此设置对 Web 应用程序没有影响(无论托管在 IIS 或 Cassini 中),尽管它对于同一台计算机上的控制台应用程序来说工作得很好。
常见的ASP.NET 2.0解决方案切换到三重des,也没有效果
<machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps" validation="3DES" decryption="3DES"/>
毕竟在 .NET 4.5 中,我们已经将 FIPS 批准的 AES 用于这些目的。
在整台计算机上禁用 FIPS(通过注册表或组策略工具)效果非常好,但当然,目标是让它与在计算机级别启用的 FIPS 一起使用。
我可能遗漏了什么吗?有什么方法可以通过从输出缓存子操作的所有实例中剥离应用程序来使其正常工作吗?
最佳答案
这与 http://forums.asp.net/p/1979986/5672126.aspx?Can+t+use+SignalR+on+Win+Server+2008+with+FIPS+mode+on 是同一问题。 CLR 团队已意识到这一点并正在考虑修复。
与此同时,您可以使用与上面的错误报告中相同的解决方法。将以下内容添加到 Global.asax 中的 Application_Start 中:
CryptoConfig.AddAlgorithm(typeof(SHA256Cng), "System.Security.Cryptography.SHA256");
关于asp.net-mvc-4 - 子操作输出缓存与 FIPS 不兼容吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25878830/