GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: check against run-time OpenSSL version · nodejs/node@cc3cdf7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test
    • common
      • index.js
    • parallel
      • test-crypto-dh.js
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.