Skip to content

Commit ddd7847

Browse files
committed
src: set CONF_MFLAGS_DEFAULT_SECTION for OpenSSL 3
This commit adds a call to OPENSSL_init_crypto to initialize OPENSSL_INIT_LOAD_CONFIG to avoid the default behavior where errors raised during the parsing of the OpenSSL configuration file are not propagated and cannot be detected. The motivation for this is that if FIPS is configured the OpenSSL configuration file will have an .include pointing to the fipsmodule.cnf file generated by the openssl fipsinstall command. If the path to this file is incorrect no error will be reported. For Node.js this will mean that EntropySource will be called by V8 as part of its initalization process, and EntropySource will in turn call CheckEntropy. CheckEntropy will call RAND_status which will now always return 0 leading to an endless loop and the node process will appear to hang/freeze. I'll continue investigating the cause of this and see if this is expected behavior or not, but in the mean time it would be good to be able to workaround this issue with this commit.
1 parent 910efc2 commit ddd7847

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/node.cc

+29-2
Original file line numberDiff line numberDiff line change
@@ -1024,12 +1024,39 @@ InitializationResult InitializeOncePerProcess(int argc, char** argv) {
10241024
// In the case of FIPS builds we should make sure
10251025
// the random source is properly initialized first.
10261026
#if OPENSSL_VERSION_MAJOR >= 3
1027-
if (EVP_default_properties_is_fips_enabled(nullptr)) {
1027+
// Call OPENSSL_init_crypto to initialize OPENSSL_INIT_LOAD_CONFIG to
1028+
// avoid the default behavior where errors raised during the parsing of the
1029+
// OpenSSL configuration file are not propagated and cannot be detected.
1030+
//
1031+
// If FIPS is configured the OpenSSL configuration file will have an .include
1032+
// pointing to the fipsmodule.cnf file generated by the openssl fipsinstall
1033+
// command. If the path to this file is incorrect no error will be reported.
1034+
// For Node.js this will mean that EntropySource will be called by V8 as part
1035+
// of its initalization process, and EntropySource will in turn call
1036+
// CheckEntropy. CheckEntropy will call RAND_status which will now always
1037+
// return 0 leading to an endless loop and the node process will appear to
1038+
// hang/freeze.
1039+
std::string openssl_conf;
1040+
credentials::SafeGetenv("OPENSSL_CONF", &openssl_conf);
1041+
if (!per_process::cli_options->openssl_config.empty() ||
1042+
!openssl_conf.empty()) {
1043+
OPENSSL_INIT_SETTINGS* settings = OPENSSL_INIT_new();
1044+
OPENSSL_INIT_set_config_file_flags(settings, CONF_MFLAGS_DEFAULT_SECTION);
1045+
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, settings);
1046+
OPENSSL_INIT_free(settings);
1047+
if (ERR_peek_error() != 0) {
1048+
result.exit_code = ERR_GET_REASON(ERR_peek_error());
1049+
result.early_return = true;
1050+
fprintf(stderr, "OpenSSL configuration error:\n");
1051+
ERR_print_errors_fp(stderr);
1052+
return result;
1053+
}
1054+
}
10281055
#else
10291056
if (FIPS_mode()) {
10301057
OPENSSL_init();
1031-
#endif
10321058
}
1059+
#endif
10331060
// V8 on Windows doesn't have a good source of entropy. Seed it from
10341061
// OpenSSL's pool.
10351062
V8::SetEntropySource(crypto::EntropySource);

0 commit comments

Comments
 (0)