-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The best test we currently have for whether Notary is running in a FIPS compliant environment is whether the MD5 hash function is registered when crypto/md5 is linked in to the program. This function is not available in FIPS mode as it is not an allowed hash function. Fix the tests to not use environment variables but private functions instead. This allows parallel testing and is cleaner. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
- Loading branch information
1 parent
a079b57
commit 9c40686
Showing
3 changed files
with
36 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package notary | ||
|
||
import "os" | ||
import ( | ||
"crypto" | ||
_ "crypto/md5" | ||
) | ||
|
||
// FIPSEnvVar is the name of the environment variable that is being used to switch | ||
// between FIPS and non-FIPS mode | ||
const FIPSEnvVar = "GOFIPS" | ||
|
||
// FIPSEnabled returns true if environment variable `GOFIPS` has been set to enable | ||
// FIPS mode | ||
// FIPSEnabled returns true if running in FIPS mode. | ||
// If compiled in FIPS mode the md5 hash function is never available | ||
// even when imported. This seems to be the best test we have for it. | ||
func FIPSEnabled() bool { | ||
return os.Getenv(FIPSEnvVar) != "" | ||
return !crypto.MD5.Available() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters