GeezerVison is showing github.com — test: check against run-time OpenSSL version · nodejs/node@cc3cdf7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/common/index.js +30-10Lines changed: 30 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,14 +55,24 @@ const noop = () => {}; | 55 | 55 | const hasCrypto = Boolean(process.versions.openssl) && | 56 | 56 | !process.env.NODE_SKIP_CRYPTO; | 57 | 57 |
| 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 | +}; | 63 | 65 |
| 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 | +}; | 66 | 76 |
| 67 | 77 | const hasQuic = hasCrypto && !!process.config.variables.openssl_quic; | 68 | 78 |
| @@ -903,9 +913,7 @@ const common = { | 903 | 913 | getTTYfd, | 904 | 914 | hasIntl, | 905 | 915 | hasCrypto, | 906 | | - hasOpenSSL3, | 907 | | - hasOpenSSL31, | 908 | | - hasOpenSSL32, | | 916 | + hasOpenSSL, | 909 | 917 | hasQuic, | 910 | 918 | hasMultiLocalhost, | 911 | 919 | invalidArgTypeHelper, | @@ -966,6 +974,18 @@ const common = { | 966 | 974 | }); | 967 | 975 | }, | 968 | 976 |
| | 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 | + | 969 | 989 | get inFreeBSDJail() { | 970 | 990 | if (inFreeBSDJail !== null) return inFreeBSDJail; | 971 | 991 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-crypto-dh.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -86,8 +86,8 @@ const crypto = require('crypto'); | 86 | 86 | } | 87 | 87 |
| 88 | 88 | { | 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)); | 91 | 91 | assert.throws(() => { | 92 | 92 | dh3.computeSecret(''); | 93 | 93 | }, { message: common.hasOpenSSL3 && !hasOpenSSL3WithNewErrorMessage ? | |
|