Skip to content

Commit 426fc64

Browse files
committed
Make FIPS related options and functionality always awailable.
There is no reason to hide FIPS functionality behind build flags. OpenSSL always provide the information about FIPS availability via `FIPS_mode()` function. This makes the user experience more consistent, because the OpenSSL library is always queried and the `crypto.getFips()` always returns OpenSSL settings. Fixes nodejs#34903
1 parent 0dae5d9 commit 426fc64

6 files changed

+3
-26
lines changed

node.gypi

-3
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,6 @@
337337
[ 'node_use_openssl=="true"', {
338338
'defines': [ 'HAVE_OPENSSL=1' ],
339339
'conditions': [
340-
['openssl_fips != "" or openssl_is_fips=="true"', {
341-
'defines': [ 'NODE_FIPS_MODE' ],
342-
}],
343340
[ 'node_shared_openssl=="false"', {
344341
'dependencies': [
345342
'./deps/openssl/openssl.gyp:openssl',

src/node.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1028,11 +1028,11 @@ InitializationResult InitializeOncePerProcess(int argc, char** argv) {
10281028
if (credentials::SafeGetenv("NODE_EXTRA_CA_CERTS", &extra_ca_certs))
10291029
crypto::UseExtraCaCerts(extra_ca_certs);
10301030
}
1031-
#ifdef NODE_FIPS_MODE
10321031
// In the case of FIPS builds we should make sure
10331032
// the random source is properly initialized first.
1034-
OPENSSL_init();
1035-
#endif // NODE_FIPS_MODE
1033+
if (FIPS_mode()) {
1034+
OPENSSL_init();
1035+
}
10361036
// V8 on Windows doesn't have a good source of entropy. Seed it from
10371037
// OpenSSL's pool.
10381038
V8::SetEntropySource(crypto::EntropySource);

src/node_config.cc

-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ static void Initialize(Local<Object> target,
4242
READONLY_FALSE_PROPERTY(target, "hasOpenSSL");
4343
#endif // HAVE_OPENSSL
4444

45-
#ifdef NODE_FIPS_MODE
4645
READONLY_TRUE_PROPERTY(target, "fipsMode");
47-
#endif
4846

4947
#ifdef NODE_HAVE_I18N_SUPPORT
5048

src/node_crypto.cc

-14
Original file line numberDiff line numberDiff line change
@@ -3611,12 +3611,10 @@ void CipherBase::Init(const char* cipher_type,
36113611
HandleScope scope(env()->isolate());
36123612
MarkPopErrorOnReturn mark_pop_error_on_return;
36133613

3614-
#ifdef NODE_FIPS_MODE
36153614
if (FIPS_mode()) {
36163615
return env()->ThrowError(
36173616
"crypto.createCipher() is not supported in FIPS mode.");
36183617
}
3619-
#endif // NODE_FIPS_MODE
36203618

36213619
const EVP_CIPHER* const cipher = EVP_get_cipherbyname(cipher_type);
36223620
if (cipher == nullptr)
@@ -3802,13 +3800,11 @@ bool CipherBase::InitAuthenticated(const char* cipher_type, int iv_len,
38023800
return false;
38033801
}
38043802

3805-
#ifdef NODE_FIPS_MODE
38063803
// TODO(tniessen) Support CCM decryption in FIPS mode
38073804
if (mode == EVP_CIPH_CCM_MODE && kind_ == kDecipher && FIPS_mode()) {
38083805
env()->ThrowError("CCM decryption not supported in FIPS mode");
38093806
return false;
38103807
}
3811-
#endif
38123808

38133809
// Tell OpenSSL about the desired length.
38143810
if (!EVP_CIPHER_CTX_ctrl(ctx_.get(), EVP_CTRL_AEAD_SET_TAG, auth_tag_len,
@@ -4683,7 +4679,6 @@ static AllocatedBuffer Node_SignFinal(Environment* env,
46834679
}
46844680

46854681
static inline bool ValidateDSAParameters(EVP_PKEY* key) {
4686-
#ifdef NODE_FIPS_MODE
46874682
/* Validate DSA2 parameters from FIPS 186-4 */
46884683
if (FIPS_mode() && EVP_PKEY_DSA == EVP_PKEY_base_id(key)) {
46894684
DSA* dsa = EVP_PKEY_get0_DSA(key);
@@ -4699,7 +4694,6 @@ static inline bool ValidateDSAParameters(EVP_PKEY* key) {
46994694
(L == 2048 && N == 256) ||
47004695
(L == 3072 && N == 256);
47014696
}
4702-
#endif // NODE_FIPS_MODE
47034697

47044698
return true;
47054699
}
@@ -6859,7 +6853,6 @@ void InitCryptoOnce() {
68596853
settings = nullptr;
68606854
#endif
68616855

6862-
#ifdef NODE_FIPS_MODE
68636856
/* Override FIPS settings in cnf file, if needed. */
68646857
unsigned long err = 0; // NOLINT(runtime/int)
68656858
if (per_process::cli_options->enable_fips_crypto ||
@@ -6874,8 +6867,6 @@ void InitCryptoOnce() {
68746867
ERR_error_string(err, nullptr));
68756868
UNREACHABLE();
68766869
}
6877-
#endif // NODE_FIPS_MODE
6878-
68796870

68806871
// Turn off compression. Saves memory and protects against CRIME attacks.
68816872
// No-op with OPENSSL_NO_COMP builds of OpenSSL.
@@ -6920,7 +6911,6 @@ void SetEngine(const FunctionCallbackInfo<Value>& args) {
69206911
}
69216912
#endif // !OPENSSL_NO_ENGINE
69226913

6923-
#ifdef NODE_FIPS_MODE
69246914
void GetFipsCrypto(const FunctionCallbackInfo<Value>& args) {
69256915
args.GetReturnValue().Set(FIPS_mode() ? 1 : 0);
69266916
}
@@ -6938,8 +6928,6 @@ void SetFipsCrypto(const FunctionCallbackInfo<Value>& args) {
69386928
return ThrowCryptoError(env, err);
69396929
}
69406930
}
6941-
#endif /* NODE_FIPS_MODE */
6942-
69436931

69446932
void Initialize(Local<Object> target,
69456933
Local<Value> unused,
@@ -6976,10 +6964,8 @@ void Initialize(Local<Object> target,
69766964
env->SetMethod(target, "setEngine", SetEngine);
69776965
#endif // !OPENSSL_NO_ENGINE
69786966

6979-
#ifdef NODE_FIPS_MODE
69806967
env->SetMethodNoSideEffect(target, "getFipsCrypto", GetFipsCrypto);
69816968
env->SetMethod(target, "setFipsCrypto", SetFipsCrypto);
6982-
#endif
69836969

69846970
env->SetMethod(target, "pbkdf2", PBKDF2);
69856971
env->SetMethod(target, "generateKeyPairRSA", GenerateKeyPairRSA);

src/node_options.cc

-2
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,6 @@ PerProcessOptionsParser::PerProcessOptionsParser(
749749
&PerProcessOptions::ssl_openssl_cert_store);
750750
Implies("--use-openssl-ca", "[ssl_openssl_cert_store]");
751751
ImpliesNot("--use-bundled-ca", "[ssl_openssl_cert_store]");
752-
#if NODE_FIPS_MODE
753752
AddOption("--enable-fips",
754753
"enable FIPS crypto at startup",
755754
&PerProcessOptions::enable_fips_crypto,
@@ -758,7 +757,6 @@ PerProcessOptionsParser::PerProcessOptionsParser(
758757
"force FIPS crypto (cannot be disabled)",
759758
&PerProcessOptions::force_fips_crypto,
760759
kAllowedInEnvironment);
761-
#endif
762760
#endif
763761
AddOption("--use-largepages",
764762
"Map the Node.js static code to large pages. Options are "

src/node_options.h

-2
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,8 @@ class PerProcessOptions : public Options {
237237
#endif
238238
bool use_openssl_ca = false;
239239
bool use_bundled_ca = false;
240-
#if NODE_FIPS_MODE
241240
bool enable_fips_crypto = false;
242241
bool force_fips_crypto = false;
243-
#endif
244242
#endif
245243

246244
// Per-process because reports can be triggered outside a known V8 context.

0 commit comments

Comments
 (0)