src: report why --enable-fips failed · nodejs/node@8c4531b · GitHub
Skip to content

Commit 8c4531b

Browse files
panvaaduh95
authored andcommitted
src: report why --enable-fips failed
The startup failure always appended the OpenSSL error queue, so when Node.js itself detected the missing fips provider it printed an error header followed by nothing. Report the reason instead. Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64979 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 28cad47 commit 8c4531b

4 files changed

Lines changed: 45 additions & 21 deletions

File tree

src/crypto/crypto_util.cc

Lines changed: 27 additions & 11 deletions

src/crypto/crypto_util.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ constexpr T NumBitsToBytes(T bits) {
6262
return (bits / CHAR_BIT) + ((CHAR_BIT - 1 + (bits % CHAR_BIT)) / CHAR_BIT);
6363
}
6464

65-
bool ProcessFipsOptions();
65+
// Applies the FIPS related command line options. Returns a description of
66+
// what went wrong, or std::nullopt when there was nothing to do or the
67+
// options were applied successfully.
68+
std::optional<std::string> ProcessFipsOptions();
6669

6770
bool InitCryptoOnce(v8::Isolate* isolate);
6871
void InitCryptoOnce();

src/node.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args,
11681168
if (!(flags & ProcessInitializationFlags::kNoInitOpenSSL)) {
11691169
#if HAVE_OPENSSL
11701170
#ifndef OPENSSL_IS_BORINGSSL
1171+
#if OPENSSL_VERSION_MAJOR >= 3
11711172
auto GetOpenSSLErrorString = []() -> std::string {
11721173
std::string ret;
11731174
ERR_print_errors_cb(
@@ -1183,7 +1184,6 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args,
11831184

11841185
// In the case of FIPS builds we should make sure
11851186
// the random source is properly initialized first.
1186-
#if OPENSSL_VERSION_MAJOR >= 3
11871187
// Call OPENSSL_init_crypto to initialize OPENSSL_INIT_LOAD_CONFIG to
11881188
// avoid the default behavior where errors raised during the parsing of the
11891189
// OpenSSL configuration file are not propagated and cannot be detected.
@@ -1244,12 +1244,10 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args,
12441244
OPENSSL_init();
12451245
}
12461246
#endif
1247-
if (!crypto::ProcessFipsOptions()) {
1247+
if (auto fips_error = crypto::ProcessFipsOptions()) {
12481248
result->exit_code_ = ExitCode::kGenericUserError;
12491249
result->early_return_ = true;
1250-
result->errors_.emplace_back(
1251-
"OpenSSL error when trying to enable FIPS:\n" +
1252-
GetOpenSSLErrorString());
1250+
result->errors_.emplace_back(std::move(*fips_error));
12531251
return result;
12541252
}
12551253

test/parallel/test-crypto-fips.js

Lines changed: 11 additions & 4 deletions

0 commit comments

Comments
 (0)