Skip to content

Commit db411cf

Browse files
indutnyrvagg
authored andcommitted
node: --openssl-config cli argument
Do not load `openssl.cnf` file automatically, load the one provided by `--openssl-config` at node startup. PR-URL: nodejs-private/node-private#78 Reviewed-By: Rod Vagg <[email protected]>
1 parent 69fc85d commit db411cf

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/node.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,14 @@ static const char* icu_data_dir = nullptr;
168168
// used by C++ modules as well
169169
bool no_deprecation = false;
170170

171-
#if HAVE_OPENSSL && NODE_FIPS_MODE
171+
#if HAVE_OPENSSL
172+
# if NODE_FIPS_MODE
172173
// used by crypto module
173174
bool enable_fips_crypto = false;
174175
bool force_fips_crypto = false;
175-
#endif
176+
# endif // NODE_FIPS_MODE
177+
const char* openssl_config = nullptr;
178+
#endif // HAVE_OPENSSL
176179

177180
// true if process warnings should be suppressed
178181
bool no_process_warnings = false;
@@ -3558,6 +3561,8 @@ static void PrintHelp() {
35583561
" --enable-fips enable FIPS crypto at startup\n"
35593562
" --force-fips force FIPS crypto (cannot be disabled)\n"
35603563
#endif /* NODE_FIPS_MODE */
3564+
" --openssl-config=path load OpenSSL configuration file from the\n"
3565+
" specified path\n"
35613566
#endif /* HAVE_OPENSSL */
35623567
#if defined(NODE_HAVE_I18N_SUPPORT)
35633568
" --icu-data-dir=dir set ICU data load path to dir\n"
@@ -3718,6 +3723,8 @@ static void ParseArgs(int* argc,
37183723
} else if (strcmp(arg, "--force-fips") == 0) {
37193724
force_fips_crypto = true;
37203725
#endif /* NODE_FIPS_MODE */
3726+
} else if (strncmp(arg, "--openssl-config=", 17) == 0) {
3727+
openssl_config = arg + 17;
37213728
#endif /* HAVE_OPENSSL */
37223729
#if defined(NODE_HAVE_I18N_SUPPORT)
37233730
} else if (strncmp(arg, "--icu-data-dir=", 15) == 0) {

src/node.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,13 @@ typedef intptr_t ssize_t;
179179
namespace node {
180180

181181
NODE_EXTERN extern bool no_deprecation;
182-
#if HAVE_OPENSSL && NODE_FIPS_MODE
182+
#if HAVE_OPENSSL
183+
# if NODE_FIPS_MODE
183184
NODE_EXTERN extern bool enable_fips_crypto;
184185
NODE_EXTERN extern bool force_fips_crypto;
185-
#endif
186+
# endif // NODE_FIPS_MODE
187+
NODE_EXTERN extern const char* openssl_config;
188+
#endif // HAVE_OPENSSL
186189

187190
NODE_EXTERN int Start(int argc, char *argv[]);
188191
NODE_EXTERN void Init(int* argc,

src/node_crypto.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5767,7 +5767,23 @@ void TimingSafeEqual(const FunctionCallbackInfo<Value>& args) {
57675767
}
57685768

57695769
void InitCryptoOnce() {
5770-
OPENSSL_config(NULL);
5770+
OPENSSL_no_config();
5771+
5772+
// --openssl-config=...
5773+
if (openssl_config != nullptr) {
5774+
CONF_modules_load_file(
5775+
openssl_config,
5776+
nullptr,
5777+
CONF_MFLAGS_DEFAULT_SECTION | CONF_MFLAGS_IGNORE_MISSING_FILE);
5778+
int err = ERR_get_error();
5779+
if (0 != err) {
5780+
fprintf(stderr,
5781+
"openssl config failed: %s\n",
5782+
ERR_error_string(err, NULL));
5783+
CHECK_NE(err, 0);
5784+
}
5785+
}
5786+
57715787
SSL_library_init();
57725788
OpenSSL_add_all_algorithms();
57735789
SSL_load_error_strings();

0 commit comments

Comments
 (0)