Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cc3cdf7

Browse filesBrowse files
committed
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: #53456 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent fc43c68 commit cc3cdf7
Copy full SHA for cc3cdf7

2 files changed

+32-12Lines changed: 32 additions & 12 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/common/index.js‎

Copy file name to clipboardExpand all lines: test/common/index.js
+30-10Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,24 @@ const noop = () => {};
5555
const hasCrypto = Boolean(process.versions.openssl) &&
5656
!process.env.NODE_SKIP_CRYPTO;
5757

58-
const hasOpenSSL3 = hasCrypto &&
59-
require('crypto').constants.OPENSSL_VERSION_NUMBER >= 0x30000000;
60-
61-
const hasOpenSSL31 = hasCrypto &&
62-
require('crypto').constants.OPENSSL_VERSION_NUMBER >= 0x30100000;
58+
// Synthesize OPENSSL_VERSION_NUMBER format with the layout 0xMNN00PPSL
59+
const opensslVersionNumber = (major = 0, minor = 0, patch = 0) => {
60+
assert(major >= 0 && major <= 0xf);
61+
assert(minor >= 0 && minor <= 0xff);
62+
assert(patch >= 0 && patch <= 0xff);
63+
return (major << 28) | (minor << 20) | (patch << 4);
64+
};
6365

64-
const hasOpenSSL32 = hasCrypto &&
65-
require('crypto').constants.OPENSSL_VERSION_NUMBER >= 0x30200000;
66+
let OPENSSL_VERSION_NUMBER;
67+
const hasOpenSSL = (major = 0, minor = 0, patch = 0) => {
68+
if (!hasCrypto) return false;
69+
if (OPENSSL_VERSION_NUMBER === undefined) {
70+
const regexp = /(?<m>\d+)\.(?<n>\d+)\.(?<p>\d+)/;
71+
const { m, n, p } = process.versions.openssl.match(regexp).groups;
72+
OPENSSL_VERSION_NUMBER = opensslVersionNumber(m, n, p);
73+
}
74+
return OPENSSL_VERSION_NUMBER >= opensslVersionNumber(major, minor, patch);
75+
};
6676

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

@@ -903,9 +913,7 @@ const common = {
903913
getTTYfd,
904914
hasIntl,
905915
hasCrypto,
906-
hasOpenSSL3,
907-
hasOpenSSL31,
908-
hasOpenSSL32,
916+
hasOpenSSL,
909917
hasQuic,
910918
hasMultiLocalhost,
911919
invalidArgTypeHelper,
@@ -966,6 +974,18 @@ const common = {
966974
});
967975
},
968976

977+
get hasOpenSSL3() {
978+
return hasOpenSSL(3);
979+
},
980+
981+
get hasOpenSSL31() {
982+
return hasOpenSSL(3, 1);
983+
},
984+
985+
get hasOpenSSL32() {
986+
return hasOpenSSL(3, 2);
987+
},
988+
969989
get inFreeBSDJail() {
970990
if (inFreeBSDJail !== null) return inFreeBSDJail;
971991

Collapse file

‎test/parallel/test-crypto-dh.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-dh.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ const crypto = require('crypto');
8686
}
8787

8888
{
89-
const v = crypto.constants.OPENSSL_VERSION_NUMBER;
90-
const hasOpenSSL3WithNewErrorMessage = (v >= 0x300000c0 && v <= 0x30100000) || (v >= 0x30100040 && v <= 0x30200000);
89+
const hasOpenSSL3WithNewErrorMessage = (common.hasOpenSSL(3, 0, 12) && !common.hasOpenSSL(3, 1, 1)) ||
90+
(common.hasOpenSSL(3, 1, 4) && !common.hasOpenSSL(3, 2, 1));
9191
assert.throws(() => {
9292
dh3.computeSecret('');
9393
}, { message: common.hasOpenSSL3 && !hasOpenSSL3WithNewErrorMessage ?

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.