Skip to content

Commit 060c1f3

Browse files
committed
src: cleanup some obsolete includes in crypto_util
1 parent 0d0cb13 commit 060c1f3

File tree

4 files changed

+18
-34
lines changed

4 files changed

+18
-34
lines changed

deps/ncrypto/ncrypto.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ DataPointer DataPointer::Alloc(size_t len) {
113113

114114
DataPointer DataPointer::SecureAlloc(size_t len) {
115115
#ifndef OPENSSL_IS_BORINGSSL
116-
printf("... %zu\n", len);
117116
auto ptr = OPENSSL_secure_zalloc(len);
118117
if (ptr == nullptr) return {};
119118
return DataPointer(ptr, len, true);
@@ -236,7 +235,8 @@ bool setFipsEnabled(bool enable, CryptoErrorList* errors) {
236235
if (isFipsEnabled() == enable) return true;
237236
ClearErrorOnReturn clearErrorOnReturn(errors);
238237
#if OPENSSL_VERSION_MAJOR >= 3
239-
return EVP_default_properties_enable_fips(nullptr, enable ? 1 : 0) == 1;
238+
return EVP_default_properties_enable_fips(nullptr, enable ? 1 : 0) == 1 &&
239+
EVP_default_properties_is_fips_enabled(nullptr);
240240
#else
241241
return FIPS_mode_set(enable ? 1 : 0) == 1;
242242
#endif
@@ -249,18 +249,17 @@ bool testFipsEnabled() {
249249
if (OSSL_PROVIDER_available(nullptr, "fips")) {
250250
fips_provider = OSSL_PROVIDER_load(nullptr, "fips");
251251
}
252-
const auto enabled = fips_provider == nullptr ? 0
253-
: OSSL_PROVIDER_self_test(fips_provider) ? 1
254-
: 0;
252+
if (fips_provider == nullptr) return false;
253+
int result = OSSL_PROVIDER_self_test(fips_provider);
254+
OSSL_PROVIDER_unload(fips_provider);
255+
return result;
255256
#else
256257
#ifdef OPENSSL_FIPS
257-
const auto enabled = FIPS_selftest() ? 1 : 0;
258+
return FIPS_selftest();
258259
#else // OPENSSL_FIPS
259-
const auto enabled = 0;
260+
return false;
260261
#endif // OPENSSL_FIPS
261262
#endif
262-
263-
return enabled;
264263
}
265264

266265
// ============================================================================

src/crypto/crypto_hkdf.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ bool HKDFTraits::DeriveBits(
118118
params.length);
119119
if (!dp) return false;
120120

121-
DCHECK(!data.isSecure());
121+
DCHECK(!dp.isSecure());
122122
*out = ByteSource::Allocated(dp.release());
123123
return true;
124124
}

src/crypto/crypto_util.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include "openssl/provider.h"
2323
#endif
2424

25-
#include <openssl/rand.h>
26-
2725
namespace node {
2826

2927
using ncrypto::BignumPointer;
@@ -85,8 +83,14 @@ bool ProcessFipsOptions() {
8583
/* Override FIPS settings in configuration file, if needed. */
8684
if (per_process::cli_options->enable_fips_crypto ||
8785
per_process::cli_options->force_fips_crypto) {
86+
#if OPENSSL_VERSION_MAJOR >= 3
8887
if (!ncrypto::testFipsEnabled()) return false;
89-
return ncrypto::setFipsEnabled(true, nullptr) && ncrypto::isFipsEnabled();
88+
return ncrypto::setFipsEnabled(true, nullptr);
89+
#else
90+
// TODO(@jasnell): Remove this ifdef branch when openssl 1.1.1 is
91+
// no longer supported.
92+
if (FIPS_mode() == 0) return FIPS_mode_set(1);
93+
#endif
9094
}
9195
return true;
9296
}

src/crypto/crypto_util.h

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,6 @@
1414

1515
#include "ncrypto.h"
1616

17-
#include <openssl/dsa.h>
18-
#include <openssl/ec.h>
19-
#include <openssl/err.h>
20-
#include <openssl/evp.h>
21-
#include <openssl/hmac.h>
22-
#include <openssl/kdf.h>
23-
#include <openssl/rsa.h>
24-
#include <openssl/ssl.h>
25-
26-
// The FIPS-related functions are only available
27-
// when the OpenSSL itself was compiled with FIPS support.
28-
#if defined(OPENSSL_FIPS) && OPENSSL_VERSION_MAJOR < 3
29-
# include <openssl/fips.h>
30-
#endif // OPENSSL_FIPS
31-
3217
#include <algorithm>
3318
#include <climits>
3419
#include <cstdio>
@@ -37,9 +22,7 @@
3722
#include <string>
3823
#include <vector>
3924

40-
namespace node {
41-
42-
namespace crypto {
25+
namespace node::crypto {
4326
// Currently known sizes of commonly used OpenSSL struct sizes.
4427
// OpenSSL considers it's various structs to be opaque and the
4528
// sizes may change from one version of OpenSSL to another, so
@@ -606,9 +589,7 @@ namespace Util {
606589
void Initialize(Environment* env, v8::Local<v8::Object> target);
607590
void RegisterExternalReferences(ExternalReferenceRegistry* registry);
608591
} // namespace Util
609-
610-
} // namespace crypto
611-
} // namespace node
592+
} // namespace node::crypto
612593

613594
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
614595
#endif // SRC_CRYPTO_CRYPTO_UTIL_H_

0 commit comments

Comments
 (0)