@@ -5962,32 +5962,24 @@ void SetEngine(const FunctionCallbackInfo<Value>& args) {
59625962}
59635963#endif // !OPENSSL_NO_ENGINE
59645964
5965+ #ifdef NODE_FIPS_MODE
59655966void GetFipsCrypto (const FunctionCallbackInfo<Value>& args) {
5966- if (FIPS_mode ()) {
5967- args.GetReturnValue ().Set (1 );
5968- } else {
5969- args.GetReturnValue ().Set (0 );
5970- }
5967+ args.GetReturnValue ().Set (FIPS_mode () ? 1 : 0 );
59715968}
59725969
59735970void SetFipsCrypto (const FunctionCallbackInfo<Value>& args) {
5971+ CHECK (!force_fips_crypto);
59745972 Environment* env = Environment::GetCurrent (args);
5975- #ifdef NODE_FIPS_MODE
59765973 const bool enabled = FIPS_mode ();
59775974 const bool enable = args[0 ]->BooleanValue ();
59785975 if (enable == enabled)
59795976 return ; // No action needed.
5980- if (force_fips_crypto) {
5981- return env->ThrowError (
5982- " Cannot set FIPS mode, it was forced with --force-fips at startup." );
5983- } else if (!FIPS_mode_set (enable)) {
5977+ if (!FIPS_mode_set (enable)) {
59845978 unsigned long err = ERR_get_error (); // NOLINT(runtime/int)
59855979 return ThrowCryptoError (env, err);
59865980 }
5987- #else
5988- return env->ThrowError (" Cannot set FIPS mode in a non-FIPS build." );
5989- #endif /* NODE_FIPS_MODE */
59905981}
5982+ #endif /* NODE_FIPS_MODE */
59915983
59925984void InitCrypto (Local<Object> target,
59935985 Local<Value> unused,
@@ -6013,8 +6005,12 @@ void InitCrypto(Local<Object> target,
60136005#ifndef OPENSSL_NO_ENGINE
60146006 env->SetMethod (target, " setEngine" , SetEngine);
60156007#endif // !OPENSSL_NO_ENGINE
6008+
6009+ #ifdef NODE_FIPS_MODE
60166010 env->SetMethod (target, " getFipsCrypto" , GetFipsCrypto);
60176011 env->SetMethod (target, " setFipsCrypto" , SetFipsCrypto);
6012+ #endif
6013+
60186014 env->SetMethod (target, " PBKDF2" , PBKDF2);
60196015 env->SetMethod (target, " randomBytes" , RandomBytes);
60206016 env->SetMethod (target, " randomFill" , RandomBytesBuffer);
0 commit comments