Skip to content

Commit 12cbdcb

Browse files
committed
src: only initialize openssl once
For compatibility with OpenSSL 1.1.0 and 1.0.1 a series of initialization wrappers were being called, many deprecated, and many calling each other internally already. Compatibility is unnecessary in 12.x and later, which support only OpenSSL 1.1.1, and the multiple calls cause the configuration file to be loaded multiple times. Fixes: nodejs#29702 See: - https://mta.openssl.org/pipermail/openssl-users/2019-October/011303.html - https://www.openssl.org/docs/man1.1.1/man3/OPENSSL_init_ssl.html - https://www.openssl.org/docs/man1.1.1/man3/OPENSSL_init_crypto.html
1 parent c8df5cf commit 12cbdcb

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

src/node.cc

-7
Original file line numberDiff line numberDiff line change
@@ -833,13 +833,6 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
833833
&default_env_options->redirect_warnings);
834834
}
835835

836-
#if HAVE_OPENSSL
837-
std::string* openssl_config = &per_process::cli_options->openssl_config;
838-
if (openssl_config->empty()) {
839-
credentials::SafeGetenv("OPENSSL_CONF", openssl_config);
840-
}
841-
#endif
842-
843836
#if !defined(NODE_WITHOUT_NODE_OPTIONS)
844837
std::string node_options;
845838

src/node_crypto.cc

+8-19
Original file line numberDiff line numberDiff line change
@@ -6975,30 +6975,19 @@ void TimingSafeEqual(const FunctionCallbackInfo<Value>& args) {
69756975
}
69766976

69776977
void InitCryptoOnce() {
6978-
SSL_load_error_strings();
6979-
OPENSSL_no_config();
6978+
#ifndef OPENSSL_IS_BORINGSSL
6979+
OPENSSL_INIT_SETTINGS* settings = OPENSSL_INIT_new();
69806980

69816981
// --openssl-config=...
69826982
if (!per_process::cli_options->openssl_config.empty()) {
6983-
OPENSSL_load_builtin_modules();
6984-
#ifndef OPENSSL_NO_ENGINE
6985-
ENGINE_load_builtin_engines();
6986-
#endif
6987-
ERR_clear_error();
6988-
CONF_modules_load_file(per_process::cli_options->openssl_config.c_str(),
6989-
nullptr,
6990-
CONF_MFLAGS_DEFAULT_SECTION);
6991-
int err = ERR_get_error();
6992-
if (0 != err) {
6993-
fprintf(stderr,
6994-
"openssl config failed: %s\n",
6995-
ERR_error_string(err, nullptr));
6996-
CHECK_NE(err, 0);
6997-
}
6983+
const char* conf = per_process::cli_options->openssl_config.c_str();
6984+
OPENSSL_INIT_set_config_filename(settings, conf);
69986985
}
69996986

7000-
SSL_library_init();
7001-
OpenSSL_add_all_algorithms();
6987+
OPENSSL_init_ssl(0, settings);
6988+
OPENSSL_INIT_free(settings);
6989+
settings = nullptr;
6990+
#endif
70026991

70036992
#ifdef NODE_FIPS_MODE
70046993
/* Override FIPS settings in cnf file, if needed. */

0 commit comments

Comments
 (0)