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

发布于 2024-11-19 14:49:23 字数 2318 浏览 3 评论 0 原文

我正在尝试设置一个 Web 应用程序,使其在 Windows 注册表中的 FIPSAlgorithmPolicy 设置为 1 的环境中工作(具体来说,HKLM/SYSTEM/CurrentControlSet/Control /LSA)。启用此标志后,对类 MD5CryptoServiceProvider 的任何调用都将导致抛出 无效操作异常,并显示以下堆栈跟踪:

[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

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

<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 而不是让我的应用程序捕获异常?
  • 我需要做什么才能让我的网络应用程序能够使用

I'm trying to set up a web application to work in an environment where the FIPSAlgorithmPolicy is set to 1 in the Windows registry (specifically, HKLM/SYSTEM/CurrentControlSet/Control/Lsa). When this flag is enabled, any call to the class MD5CryptoServiceProvider will cause an Invalid Operation Exception to be thrown with the following stack trace:

[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

Based on what I read in this article, you're supposed to be able to add the following to your config file to disable the algorithm check:

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

This works for me in a test Console application by modifying its app.config. However, it doesn't seem to work when a modify a .NET 2.0 web application's web.config.

What's interesting to me is that even though I'm catching all exceptions when I go instantiate an MD5CryptoServiceProvider in code, it doesn't seem to even make it to that portion of my code. This is the code that's called in my test app:

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

And this is what I see when I visit the page:

screenshot of YSOD

So this brings up a couple of questions:

  • Why is IIS throwing a YSOD instead of allowing my app to catch the exception?
  • What do I need to do so that my web app is able to use <enforceFIPSPolicy enabled="false"/>?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谁人与我共长歌 2024-11-26 14:49:24

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

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

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

2)。不应该被忽略。如果我发现什么,

MD5CryptoServiceProvider 可能仍然不符合 FIPS。 .NET 中的 SHA-1 和 SHA-2 哈希算法以 CryptoServiceProvider 结尾的加密函数依赖于 Windows CSP;另一种方法是使用 BouncyCastle 而不是 .NET 的实现,因为它不关心该标志。

1). Your code isn't throwing the exception. ASP.NET is doing something else. ASP.NET is trying to serialize the ViewState; which can be encrypted by the machine key. When ASP.NET does this internally; it uses the RijndaelManaged class (which is not FIPS 140 compliant; and blows up. Likewise; when ASP.NET tries to encrypt / decrypt a forms authentication ticket; it will use the machine key as well.

You have a few options for the Machine Key issue. You can use 3DES (which will always use a FIPS compliant implementation by setting the MachineKey in your web.config to look like this:

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

2). I'm not sure why your flag is being ignored. It shouldn't be. I'll edit if I figure anything out.

Note that the MD5CryptoServiceProvider might still bomb. MD5 is not a FIPS compliant hash. As far as I know; only the SHA-1 and SHA-2 hash algorithms are in .NET. The crypto functions that end in CryptoServiceProvider rely on the Windows CSP; which also acknowledges that flag. An alternative would be to use BouncyCastle instead of .NET's implementation since it doesn't care about that flag.

吃兔兔 2024-11-26 14:49:24

我认为您需要更新更多文件。从此处

  1. 转到C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0或包含 WebDev.WebServer.Exe 的任何文件夹
  2. 创建一个名为“WebDev.WebServer.Exe.config”的文本文件。确保扩展名是“config”而不是“txt”。
  3. 将以下文本添加到文件中。

    <代码><配置>;
    <运行时>


  4. 如果 ASP.NET 开发服务器正在运行,请将其停止。您可以通过右键单击系统托盘中的图标并选择“停止”来执行此操作。

  5. 转到 C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ 或包含 devenv.exe.config 的任何文件夹。
  6. 将以下行添加到 devenv.exe.config 的运行时部分。

  7. 如果 Visual Studio 已打开,则将其关闭,然后再次打开。

一些可以尝试的附加操作

  1. 仔细检查您是否没有您的 Web.config。当设置调试编译时,.NET 使用 MD5 哈希进行某些内部簿记。 MD5 不符合 FIPS,因此您会收到此错误。

  2. ASP.NET 2.0 在处理视图状态数据时使用 AES 算法的 RijndaelManaged 实现。 RijndaelManaged 实施尚未经过美国国家标准与技术研究所 (NIST) 的认证,符合联邦信息处理标准 (FIPS)。因此,AES 算法不是 Windows 平台 FIPS 验证的加密算法的一部分。要解决此问题,您可以使用以下行在 web.config 中指定不同的算法:

它也确认了此处(来自 MSFT),您遇到了相同的错误。要修复它:

在记事本等文本编辑器中,打开应用程序级 Web.config 文件。
在 Web.config 文件中,找到该部分。
将以下部分添加到该部分中:

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

保存 Web.config 文件。
重新启动 Microsoft Internet 信息服务 (IIS) 服务。为此,请在命令提示符下运行以下命令:
iis重置

I think you need to update a few more files. From here

  1. Go to C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0 or whatever folder contains WebDev.WebServer.Exe
  2. Create a text file named “WebDev.WebServer.Exe.config.” Be sure the extension is “config” and not “txt.”
  3. Add the following text to the file.

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

  4. If the ASP.NET Development Server is running, stop it. You can do this by right-clicking its icon in the system tray and selecting Stop.

  5. Go to C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ or whatever folder contains devenv.exe.config.
  6. Add the following line to the runtime section of devenv.exe.config.

    <enforceFIPSPolicy enabled=”0” />

  7. If Visual Studio is open then close it and open it again.

Some addition things to try

  1. Double check that you don't have in your Web.config. When debug compilation is set, .NET uses an MD5 hash for some internal bookkeeping. MD5 is not FIPS compliant so you get this error.

  2. ASP.NET 2.0 uses the RijndaelManaged implementation of the AES algorithm when it processes view state data. The RijndaelManaged implementation has not been certified by the National Institute of Standards and Technology (NIST) as compliant with the Federal Information Processing Standard (FIPS). Therefore, the AES algorithm is not part of the Windows Platform FIPS validated cryptographic algorithms. To solve this, you can specify a different algorithm in your web.config using this line:
    <machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps" validation="3DES" decryption="3DES"/>

Its also confirms here by MSFT that you get the same error. To fix it:

In a text editor such as Notepad, open the application-level Web.config file.
In the Web.config file, locate the section.
Add the following section to in the section:

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

Save the Web.config file.
Restart the Microsoft Internet Information Services (IIS) service. To do this, run the following command at a command prompt:
iisreset

遇到 2024-11-26 14:49:24

正如您所发现的,web.config 条目不起作用,至少在 iis 7.5 及更高版本中是这样。相反,您需要使用应用程序池配置文件,如这里

As you've found, the web.config entry doesn't work, at least in iis 7.5 forward. Instead, you need to use an application pool configuration file, as described here

神魇的王 2024-11-26 14:49:24

所以,尽管这是旧的,但它仍然有点相关。该设置

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

位于 Framework 和/或 Framework64 .net 文件夹中的 aspnet.config 中。此绕过设置适用于应用程序配置文件。 Web.config 不是应用程序配置文件。

So, even though this is old, it's still a bit relevant. The setting

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

goes in aspnet.config in the Framework and/or Framework64 .net folders. This bypass setting works on an application config file. Web.config is not an application configuration file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文