-
Notifications
You must be signed in to change notification settings - Fork 40
How do I modify the defaults for Antiforgery to make it FIPS-compliant #95
Comments
Creating a new ASP.NET Core Web Application using .NET Core works fine. Creating one using the .NET Framework with FIPS enabled doesn't work. |
/cc @blowdart |
Strange. What OS, and do you have a stack trace? @rynowak This may end up being deep in data protection. There's a fun bug in creating SHA signing pieces where you tell it to use FIPS algorithms and it doesn't. nuget had the same problem, |
I'm on Windows 10.0 (Build 10240). Here's the stack trace:
|
Thanks for providing this. This callstack is using Can you try the following workaround:
The purpose of the random cookie name is just to avoid colliding with other applications using our antiforgery system when using shared hosting. If you have your own domain name then there's no risk of collision. |
/cc @blowdart - see above, it looks like we have to do something about this, but it's local to antiforgery |
Oh dear. This is a bug in the desktop framework. SHA256.Create should create a FIPS compliant CSP, but doesn't in some circumstances. nuget had the same problem (NuGet/Home#2335) Switch from SHA256.Create() to (HashAlgorithm)new SHA256CryptoServiceProvider() |
Prospectively putting this in the 1.0.1 milestone, but will need to get approval for it. |
I tried the workaround above and it seems like it's no longer failing in Antiforgery but in the TagHelpers. Looks like a general bug. Where should I redirect this issue to? Here's the stack trace.
|
@NTaylorMullen ... |
@thanhos I have a work around for you. Firstly my apologies. This is a bug in the .NET framework, and it's fixed in 4.6.2 but I presume because you have FIPS enabled that upgrading when that drops is probably painful. I'm currently creating a new FIPS VM to check this. What you can do is in
You'll need to add the following reference
If you're targeting .NET Core the error won't occur, we got rid of all the managed crypto packages, so everything is left to the underlying platform, thus no FIPS concerns. We'll also get the code adjusted as well. |
Thanks for the feedback so far @blowdart I tried the suggestion above and still received the same error. |
Darn I was so hopefully. It's probably too late in the initialization process then (I'm still attempting to get a FIPS machine up and running) |
I know it's a lot to ask, but could you try installing 4.6.2 beta on a machine and see if that works? It's likely 4.6.2 will drop before we officially release a patch for this. |
Sure, I'll give that a try and see how it goes. |
Thanks. Apologies for forcing a beta on you. |
No worries. I installed the 4.6.2 Preview and still getting the same exceptions. |
Darn. Emailing some folks. |
FWIW, an ASOS user experienced the same thing and this snippet worked: // Make sure to replace both "SHA256" and "System.Security.Cryptography.SHA256"
CryptoConfig.AddAlgorithm(typeof(SHA256Cng), typeof(SHA256).Name, typeof(SHA256).FullName); I presume @blowdart's snippet doesn't work because it doesn't override "System.Security.Cryptography.SHA256". |
grumble grumble. That's my bad, I advised him without looking at the implementation on referencesource. Aes.Create() queries for "AES", so for some reason I assumed SHA256 queried for "SHA256". How absurd of me 😄. Installing 4.6.2 preview should've worked. At least, it's in the public changelog (with a terrible description):
Guess that's something for me to dig into. |
Hahaha, guys who use |
@PinpointTownes Nah, you missed "in FIPS-only mode". Since the ctor of SHA256Managed is what throws SHA256.Create() never exited in that case; so we've changed an exceptional case to a passing case. Non-FIPS mode is left as-was, for precisely that bad pattern. |
@bartonjs ah yeah good point 😄 On a related note, is there a plan to change the default key size used by |
@PinpointTownes That's a hard argument with compat (but one I'll have at some point). But hopefully https://github.com/dotnet/corefx/issues/8688 will take the sting off. |
@PinpointTownes 's suggestion worked. Thanks! I'll have to investigate as to why installing 4.6.2 didn't work on my machine. Thanks for the help everyone. |
FYI Antiforgery and MVC use
|
FYI, I logged aspnet/Mvc#5103 for the MVC issues. |
@Eilon is this really a MVC issue? It already does the right thing by calling The fact you don't get a FIPS-compliant instance on .NET Desktop < 4.6.2 is another story, but I'm not sure there's anything you can do in MVC. |
@PinpointTownes to be honest, not sure - but MVC's code looks the same as anti-forgery's, so wouldn't it be the same issue? |
Well, IMHO, there's no bug in Antiforgery or MVC, as they both correctly use The "bug" (by design?) was more caused by I guess the right thing to do is to document that somewhere. People who need FIPS support on .NET Desktop should either migrate to .NET 4.6.2 or override the default SHA-256 implementation to use CAPI ( |
@PinpointTownes yeah I think it boils down to: the system as a whole doesn't work on FIPS-enabled machines, so we want to do whatever we can reasonably do to make it work, regardless of where the actual root bug is. So if we need to just work around bugs in our own codebase (while that codebase is getting the "real" fix), then we'll try to do that. Does that make sense? |
It does. I'm just concerned by the the fact your workaround might break cross-platform scenarios:
I guess one viable option might be to call Is it really worth it? IMHO, the "right" fix is something people should add in their entry point depending on their own needs:
|
@thanhos 4.6.2 (final) released today: https://blogs.msdn.microsoft.com/dotnet/2016/08/02/announcing-net-framework-4-6-2/. I very much hope/expect that the CryptoConfig issue would be resolved for you with that build installed. The CryptoConfig change is only conditional on the FIPS setting, so it doesn't require changing your calling executable to be explicitly compiled against 4.6.2. (Though, like many things with the FIPS setting, it reads it once at startup and never again, in case your scenario flipped the bit after app start) |
@PinpointTownes Having people jump through hoops isn't the right answer. The right answer is making it work on our supported platforms. |
PR is ready to go in. Waiting for patch-approved. Once in, will need to work out changes to templates to ensure they reference 1.0.1 Antiforgery. |
I'm working on a system that has FIPS-compliant enabled and am wondering is there a way to change the Antiforgery defaults to make it compliant. If someone could provide some direction or feedback that would appreciated.
Thanks
The text was updated successfully, but these errors were encountered: