Fix FIPS-mode exceptions on Windows for SHA256 #3774
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
FIPS stands for Federal Information Processing Standard, and it specifies a list of cryptographic algorithms that are considered secure enough for security:
Windows has a setting to throw exceptions if an application tries to use one of its official crypto objects that isn't FIPS-compliant. (Of course, if you roll your own SHA1 function, it has no idea you've done that.)
CKAN uses hashes to detect corrupted downloads, not for security purposes.
Problem
CKAN users with the FIPS setting enabled report this exception after downloading mods:
Causes
Apparently using
SHA1Managed
orSHA256Managed
throws this exception if you have FIPS enabled.This happened once before for SHA1, see #1497 and #1850. At that time the SHA1 code was fixed and the SHA256 code was not touched because the client wasn't using it (in #2243 the client began using SHA256 to validate downloads). Back then
SHA1Managed
was replaced bySHA1Cng
, which #2820 later changed toSHA1CryptoServiceProvider
.CKAN/Core/Net/NetFileCache.cs
Lines 702 to 703 in 98f2836
Since the exception is thrown for SHA256, which is calculated after SHA1, I take this to mean that
SHA1CryptoServiceProvider
works without upsetting FIPS.Changes
Now we use
SHA256CryptoServiceProvider
. This should suppress the FIPS exception.Fixes #3773.