Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: Use system's openssl.cnf for OpenSSL configuration #5739

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/api/tls.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ To test the server, connect to it with `openssl s_client -connect address:port`
and tap `R<CR>` (i.e., the letter `R` followed by a carriage return) a few
times.

## Use system default OpenSSL configuration

Use the `--openssl-system-conf` command line switch to force Node.js use system
default configuration for OpenSSL.

```
node --openssl-system-conf
```

When Node.js is run with this switch, OpenSSL is initialized with the
configuration file specified in the OPENSSL_CONF environment variable, and if
that is not set then a system default configuration file location is used.
See [OPENSSL_config]
(https://www.openssl.org/docs/manmaster/crypto/OPENSSL_config.html)
for defails.

## Modifying the Default TLS Cipher suite

Node.js is built with a default suite of enabled and disabled TLS ciphers.
Expand Down
10 changes: 9 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,14 @@ static const char* icu_data_dir = nullptr;
// used by C++ modules as well
bool no_deprecation = false;

#if HAVE_OPENSSL && NODE_FIPS_MODE
#if HAVE_OPENSSL
// used by crypto module
bool openssl_system_conf = false;
# if NODE_FIPS_MODE
// used by crypto module
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems redundant now, doesn't it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

bool enable_fips_crypto = false;
bool force_fips_crypto = false;
# endif
#endif

// process-relative uptime base, initialized at start-up
Expand Down Expand Up @@ -3320,6 +3324,8 @@ static void PrintHelp() {
" --v8-options print v8 command line options\n"
#if HAVE_OPENSSL
" --tls-cipher-list=val use an alternative default TLS cipher list\n"
" --openssl-system-conf use system's openssl.cnf for OpenSSL\n"
" configuration\n"
#if NODE_FIPS_MODE
" --enable-fips enable FIPS crypto at startup\n"
" --force-fips force FIPS crypto (cannot be disabled)\n"
Expand Down Expand Up @@ -3468,6 +3474,8 @@ static void ParseArgs(int* argc,
#if HAVE_OPENSSL
} else if (strncmp(arg, "--tls-cipher-list=", 18) == 0) {
default_cipher_list = arg + 18;
} else if (strcmp(arg, "--openssl-system-conf") == 0) {
openssl_system_conf = true;
#if NODE_FIPS_MODE
} else if (strcmp(arg, "--enable-fips") == 0) {
enable_fips_crypto = true;
Expand Down
6 changes: 5 additions & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,13 @@ typedef intptr_t ssize_t;
namespace node {

NODE_EXTERN extern bool no_deprecation;
#if HAVE_OPENSSL && NODE_FIPS_MODE

#if HAVE_OPENSSL
NODE_EXTERN extern bool openssl_system_conf;
# if NODE_FIPS_MODE
NODE_EXTERN extern bool enable_fips_crypto;
NODE_EXTERN extern bool force_fips_crypto;
# endif
#endif

NODE_EXTERN int Start(int argc, char *argv[]);
Expand Down
7 changes: 7 additions & 0 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5644,6 +5644,13 @@ void ExportChallenge(const FunctionCallbackInfo<Value>& args) {


void InitCryptoOnce() {
#ifdef HAVE_OPENSSL
// Use system's openssl.cnf for OpenSSL configuration
if (openssl_system_conf) {
OPENSSL_config(nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this try OPENSSL_CONF environment variable first?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It tries it internally

}
#endif // HAVE_OPENSSL

SSL_library_init();
OpenSSL_add_all_algorithms();
SSL_load_error_strings();
Expand Down