File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -6021,11 +6021,14 @@ void GetFipsCrypto(const FunctionCallbackInfo<Value>& args) {
6021
6021
void SetFipsCrypto (const FunctionCallbackInfo<Value>& args) {
6022
6022
Environment* env = Environment::GetCurrent (args);
6023
6023
#ifdef NODE_FIPS_MODE
6024
- bool mode = args[0 ]->BooleanValue ();
6024
+ const bool enabled = FIPS_mode ();
6025
+ const bool enable = args[0 ]->BooleanValue ();
6026
+ if (enable == enabled)
6027
+ return ; // No action needed.
6025
6028
if (force_fips_crypto) {
6026
6029
return env->ThrowError (
6027
6030
" Cannot set FIPS mode, it was forced with --force-fips at startup." );
6028
- } else if (!FIPS_mode_set (mode )) {
6031
+ } else if (!FIPS_mode_set (enable )) {
6029
6032
unsigned long err = ERR_get_error (); // NOLINT(runtime/int)
6030
6033
return ThrowCryptoError (env, err);
6031
6034
}
Original file line number Diff line number Diff line change @@ -212,6 +212,15 @@ testHelper(
212
212
'require("crypto").fips = false' ,
213
213
process . env ) ;
214
214
215
+ // --force-fips makes setFipsCrypto enable a no-op (FIPS stays on)
216
+ testHelper (
217
+ compiledWithFips ( ) ? 'stdout' : 'stderr' ,
218
+ [ '--force-fips' ] ,
219
+ compiledWithFips ( ) ? FIPS_ENABLED : OPTION_ERROR_STRING ,
220
+ '(require("crypto").fips = true,' +
221
+ 'require("crypto").fips)' ,
222
+ process . env ) ;
223
+
215
224
// --force-fips and --enable-fips order does not matter
216
225
testHelper (
217
226
'stderr' ,
You can’t perform that action at this time.
0 commit comments