mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
test: check against run-time OpenSSL version
Update `common.hasOpenSSL3*` to check against the run-time version of OpenSSL instead of the version of OpenSSL that Node.js was compiled against. Add a generalized `common.hasOpenSSL()` so we do not need to keep adding new checks for each new major/minor of OpenSSL. PR-URL: https://github.com/nodejs/node/pull/53456 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
parent
5909cf3b04
commit
3e7129e5d6
2 changed files with 32 additions and 12 deletions
|
@ -57,14 +57,24 @@ const noop = () => {};
|
||||||
const hasCrypto = Boolean(process.versions.openssl) &&
|
const hasCrypto = Boolean(process.versions.openssl) &&
|
||||||
!process.env.NODE_SKIP_CRYPTO;
|
!process.env.NODE_SKIP_CRYPTO;
|
||||||
|
|
||||||
const hasOpenSSL3 = hasCrypto &&
|
// Synthesize OPENSSL_VERSION_NUMBER format with the layout 0xMNN00PPSL
|
||||||
require('crypto').constants.OPENSSL_VERSION_NUMBER >= 0x30000000;
|
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 hasOpenSSL31 = hasCrypto &&
|
let OPENSSL_VERSION_NUMBER;
|
||||||
require('crypto').constants.OPENSSL_VERSION_NUMBER >= 0x30100000;
|
const hasOpenSSL = (major = 0, minor = 0, patch = 0) => {
|
||||||
|
if (!hasCrypto) return false;
|
||||||
const hasOpenSSL32 = hasCrypto &&
|
if (OPENSSL_VERSION_NUMBER === undefined) {
|
||||||
require('crypto').constants.OPENSSL_VERSION_NUMBER >= 0x30200000;
|
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;
|
const hasQuic = hasCrypto && !!process.config.variables.openssl_quic;
|
||||||
|
|
||||||
|
@ -977,9 +987,7 @@ const common = {
|
||||||
getTTYfd,
|
getTTYfd,
|
||||||
hasIntl,
|
hasIntl,
|
||||||
hasCrypto,
|
hasCrypto,
|
||||||
hasOpenSSL3,
|
hasOpenSSL,
|
||||||
hasOpenSSL31,
|
|
||||||
hasOpenSSL32,
|
|
||||||
hasQuic,
|
hasQuic,
|
||||||
hasMultiLocalhost,
|
hasMultiLocalhost,
|
||||||
invalidArgTypeHelper,
|
invalidArgTypeHelper,
|
||||||
|
@ -1040,6 +1048,18 @@ const common = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get hasOpenSSL3() {
|
||||||
|
return hasOpenSSL(3);
|
||||||
|
},
|
||||||
|
|
||||||
|
get hasOpenSSL31() {
|
||||||
|
return hasOpenSSL(3, 1);
|
||||||
|
},
|
||||||
|
|
||||||
|
get hasOpenSSL32() {
|
||||||
|
return hasOpenSSL(3, 2);
|
||||||
|
},
|
||||||
|
|
||||||
get inFreeBSDJail() {
|
get inFreeBSDJail() {
|
||||||
if (inFreeBSDJail !== null) return inFreeBSDJail;
|
if (inFreeBSDJail !== null) return inFreeBSDJail;
|
||||||
|
|
||||||
|
|
|
@ -86,8 +86,8 @@ const crypto = require('crypto');
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const v = crypto.constants.OPENSSL_VERSION_NUMBER;
|
const hasOpenSSL3WithNewErrorMessage = (common.hasOpenSSL(3, 0, 12) && !common.hasOpenSSL(3, 1, 1)) ||
|
||||||
const hasOpenSSL3WithNewErrorMessage = (v >= 0x300000c0 && v <= 0x30100000) || (v >= 0x30100040 && v <= 0x30200000);
|
(common.hasOpenSSL(3, 1, 4) && !common.hasOpenSSL(3, 2, 1));
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
dh3.computeSecret('');
|
dh3.computeSecret('');
|
||||||
}, { message: common.hasOpenSSL3 && !hasOpenSSL3WithNewErrorMessage ?
|
}, { message: common.hasOpenSSL3 && !hasOpenSSL3WithNewErrorMessage ?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue