Skip to content

Commit b019ccd

Browse files
sam-githubMylesBorins
authored andcommitted
src: initialize openssl only 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: #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 PR-URL: #29999 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com>
1 parent ccf5883 commit b019ccd

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
@@ -6964,30 +6964,19 @@ void TimingSafeEqual(const FunctionCallbackInfo<Value>& args) {
69646964
}
69656965

69666966
void InitCryptoOnce() {
6967-
SSL_load_error_strings();
6968-
OPENSSL_no_config();
6967+
#ifndef OPENSSL_IS_BORINGSSL
6968+
OPENSSL_INIT_SETTINGS* settings = OPENSSL_INIT_new();
69696969

69706970
// --openssl-config=...
69716971
if (!per_process::cli_options->openssl_config.empty()) {
6972-
OPENSSL_load_builtin_modules();
6973-
#ifndef OPENSSL_NO_ENGINE
6974-
ENGINE_load_builtin_engines();
6975-
#endif
6976-
ERR_clear_error();
6977-
CONF_modules_load_file(per_process::cli_options->openssl_config.c_str(),
6978-
nullptr,
6979-
CONF_MFLAGS_DEFAULT_SECTION);
6980-
int err = ERR_get_error();
6981-
if (0 != err) {
6982-
fprintf(stderr,
6983-
"openssl config failed: %s\n",
6984-
ERR_error_string(err, nullptr));
6985-
CHECK_NE(err, 0);
6986-
}
6972+
const char* conf = per_process::cli_options->openssl_config.c_str();
6973+
OPENSSL_INIT_set_config_filename(settings, conf);
69876974
}
69886975

6989-
SSL_library_init();
6990-
OpenSSL_add_all_algorithms();
6976+
OPENSSL_init_ssl(0, settings);
6977+
OPENSSL_INIT_free(settings);
6978+
settings = nullptr;
6979+
#endif
69916980

69926981
#ifdef NODE_FIPS_MODE
69936982
/* Override FIPS settings in cnf file, if needed. */

0 commit comments

Comments
 (0)