gpt4 book ai didi

c# - web.config 中的 enforceFIPSPolicy 标志似乎不适用于 Web 应用程序

转载 作者:可可西里 更新时间:2023-11-01 09:09:12 33 4
gpt4 key购买 nike

我正在尝试设置一个 Web 应用程序以在 FIPSAlgorithmPolicy设置为 1在 Windows 注册表中(特别是 HKLM/SYSTEM/CurrentControlSet/Control/Lsa)。启用此标志后,对类 MD5CryptoServiceProvider 的任何调用会导致 Invalid Operation Exception与以下堆栈跟踪一起抛出:

[InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.]
System.Security.Cryptography.RijndaelManaged..ctor() +10480142
System.Web.Configuration.MachineKeySection.ConfigureEncryptionObject() +439
System.Web.Configuration.MachineKeySection.EnsureConfig() +152
System.Web.Configuration.MachineKeySection.GetEncodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32& length) +48
System.Web.UI.ObjectStateFormatter.Serialize(Object stateGraph) +381
System.Web.UI.Util.SerializeWithAssert(IStateFormatter formatter, Object stateGraph) +59
System.Web.UI.HiddenFieldPageStatePersister.Save() +89
System.Web.UI.Page.SaveAllState() +1117
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3864

基于我在 this article 中阅读的内容,您应该能够将以下内容添加到您的配置文件以禁用算法检查:

<configuration>
<runtime>
<enforceFIPSPolicy enabled="false"/>
</runtime>
</configuration>

通过修改其 app.config,这对我适用于测试控制台应用程序。但是,当修改 .NET 2.0 Web 应用程序的 web.config 时,它似乎不起作用。

对我来说有趣的是,尽管我在实例化 MD5CryptoServiceProvider 时捕获了所有异常。在代码中,它似乎甚至没有进入我的那部分代码。这是在我的测试应用程序中调用的代码:

    protected string printSomething()
{
string toPrint = String.Empty;
try
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
toPrint = "Created algorithm.";
}
catch (Exception e)
{
toPrint = e.ToString();
}
return toPrint;
}

这是我访问该页面时看到的内容:

screenshot of YSOD

所以这带来了几个问题:

  • 为什么 IIS 抛出 YSOD 而不是让我的应用捕获异常?
  • 我需要做什么才能让我的网络应用程序能够使用 <enforceFIPSPolicy enabled="false"/>

最佳答案

1).您的代码没有抛出异常。 ASP.NET 正在做其他事情。 ASP.NET 正在尝试序列化 ViewState;可以用机器 key 加密。当 ASP.NET 在内部执行此操作时;它使用 RijndaelManaged 类(不符合 FIPS 140;并且会爆炸。同样地;当 ASP.NET 尝试加密/解密表单例份验证票证时;它也会使用机器 key 。

对于机器 key 问题,您有几种选择。您可以使用 3DES(通过将 web.config 中的 MachineKey 设置为如下所示,它将始终使用符合 FIPS 的实现:

<machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps" validation="3DES" decryption="3DES" />

2).我不确定为什么你的旗帜被忽略了。不应该的。如果我发现任何问题,我会进行编辑。

请注意 MD5CryptoServiceProvider 可能仍然会爆炸。 MD5 不是符合 FIPS 的散列。据我所知; .NET 中只有 SHA-1 和 SHA-2 哈希算法。以 CryptoServiceProvider 结尾的加密函数依赖于 Windows CSP;这也承认该标志。另一种方法是使用 BouncyCastle而不是 .NET 的实现,因为它不关心该标志。

关于c# - web.config 中的 enforceFIPSPolicy 标志似乎不适用于 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6652850/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com