File tree 2 files changed +14
-2
lines changed 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -6060,11 +6060,14 @@ void GetFipsCrypto(const FunctionCallbackInfo<Value>& args) {
6060
6060
void SetFipsCrypto (const FunctionCallbackInfo<Value>& args) {
6061
6061
Environment* env = Environment::GetCurrent (args);
6062
6062
#ifdef NODE_FIPS_MODE
6063
- bool mode = args[0 ]->BooleanValue ();
6063
+ const bool enabled = FIPS_mode ();
6064
+ const bool enable = args[0 ]->BooleanValue ();
6065
+ if (enable == enabled)
6066
+ return ; // No action needed.
6064
6067
if (force_fips_crypto) {
6065
6068
return env->ThrowError (
6066
6069
" Cannot set FIPS mode, it was forced with --force-fips at startup." );
6067
- } else if (!FIPS_mode_set (mode )) {
6070
+ } else if (!FIPS_mode_set (enable )) {
6068
6071
unsigned long err = ERR_get_error (); // NOLINT(runtime/int)
6069
6072
return ThrowCryptoError (env, err);
6070
6073
}
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