src: fix dynamically linked OpenSSL version by richardlau · Pull Request #53456 · nodejs/node · GitHub
Skip to content
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
9 changes: 5 additions & 4 deletions src/node_metadata.cc
40 changes: 30 additions & 10 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,24 @@ const noop = () => {};
const hasCrypto = Boolean(process.versions.openssl) &&
!process.env.NODE_SKIP_CRYPTO;

const hasOpenSSL3 = hasCrypto &&
require('crypto').constants.OPENSSL_VERSION_NUMBER >= 0x30000000;

const hasOpenSSL31 = hasCrypto &&
require('crypto').constants.OPENSSL_VERSION_NUMBER >= 0x30100000;
// Synthesize OPENSSL_VERSION_NUMBER format with the layout 0xMNN00PPSL
const opensslVersionNumber = (major = 0, minor = 0, patch = 0) => {
assert(major >= 0 && major <= 0xf);
assert(minor >= 0 && minor <= 0xff);
assert(patch >= 0 && patch <= 0xff);
return (major << 28) | (minor << 20) | (patch << 4);
};

const hasOpenSSL32 = hasCrypto &&
require('crypto').constants.OPENSSL_VERSION_NUMBER >= 0x30200000;
let OPENSSL_VERSION_NUMBER;
const hasOpenSSL = (major = 0, minor = 0, patch = 0) => {
if (!hasCrypto) return false;
if (OPENSSL_VERSION_NUMBER === undefined) {
const regexp = /(?<m>\d+)\.(?<n>\d+)\.(?<p>\d+)/;
const { m, n, p } = process.versions.openssl.match(regexp).groups;
OPENSSL_VERSION_NUMBER = opensslVersionNumber(m, n, p);
}
return OPENSSL_VERSION_NUMBER >= opensslVersionNumber(major, minor, patch);
};

const hasQuic = hasCrypto && !!process.config.variables.openssl_quic;

Expand Down Expand Up @@ -969,9 +979,7 @@ const common = {
getTTYfd,
hasIntl,
hasCrypto,
hasOpenSSL3,
hasOpenSSL31,
hasOpenSSL32,
hasOpenSSL,
hasQuic,
hasMultiLocalhost,
invalidArgTypeHelper,
Expand Down Expand Up @@ -1032,6 +1040,18 @@ const common = {
});
},

get hasOpenSSL3() {
return hasOpenSSL(3);
},

get hasOpenSSL31() {
return hasOpenSSL(3, 1);
},

get hasOpenSSL32() {
return hasOpenSSL(3, 2);
},

get inFreeBSDJail() {
if (inFreeBSDJail !== null) return inFreeBSDJail;

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-crypto-dh.js