Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be23526

Browse files
committed
crypto: expose process.features.openssl_is_boringssl
nodejs/node#58387
1 parent d7ace93 commit be23526

File tree

2 files changed

+100
-26
lines changed

2 files changed

+100
-26
lines changed

patches/node/fix_crypto_tests_to_run_with_bssl.patch

Lines changed: 85 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ before it's acceptable to upstream, as this patch comments out a couple
1111
of tests that upstream probably cares about.
1212

1313
diff --git a/test/parallel/test-crypto-async-sign-verify.js b/test/parallel/test-crypto-async-sign-verify.js
14-
index b35dd08e6c49796418cd9d10eb5cc9d02b39961e..c5d701f6464694456813d2aadff2fe9ec0b0acd5 100644
14+
index b35dd08e6c49796418cd9d10eb5cc9d02b39961e..97bcd79b331db140d157e6b1faf92625597edc98 100644
1515
--- a/test/parallel/test-crypto-async-sign-verify.js
1616
+++ b/test/parallel/test-crypto-async-sign-verify.js
1717
@@ -89,6 +89,7 @@ test('rsa_public.pem', 'rsa_private.pem', 'sha256', false,
@@ -37,7 +37,7 @@ index b35dd08e6c49796418cd9d10eb5cc9d02b39961e..c5d701f6464694456813d2aadff2fe9e
3737
- const expected = hasOpenSSL3 ?
3838
- /operation not supported for this keytype/ : /no default digest/;
3939
+ let expected = /no default digest/;
40-
+ if (hasOpenSSL3 || !process.features.openssl_is_boringssl) {
40+
+ if (hasOpenSSL3 || process.features.openssl_is_boringssl) {
4141
+ expected = /operation[\s_]not[\s_]supported[\s_]for[\s_]this[\s_]keytype/i;
4242
+ }
4343

@@ -109,23 +109,29 @@ index 81a469c226c261564dee1e0b06b6571b18a41f1f..58b66045dba4201b7ebedd78b129420f
109109

110110
const availableCurves = new Set(crypto.getCurves());
111111
diff --git a/test/parallel/test-crypto-dh-errors.js b/test/parallel/test-crypto-dh-errors.js
112-
index 0af4db0310750cea9350ecff7fc44404c6df6c83..85ab03f6019989ad4fe93b779c3b4772ce1f5130 100644
112+
index 0af4db0310750cea9350ecff7fc44404c6df6c83..b14b4bbf88b902b6de916b92e3d48335c01df911 100644
113113
--- a/test/parallel/test-crypto-dh-errors.js
114114
+++ b/test/parallel/test-crypto-dh-errors.js
115-
@@ -33,9 +33,9 @@ for (const bits of [-1, 0, 1]) {
115+
@@ -27,7 +27,7 @@ assert.throws(() => crypto.createDiffieHellman('abcdef', 13.37), {
116+
for (const bits of [-1, 0, 1]) {
117+
if (hasOpenSSL3) {
118+
assert.throws(() => crypto.createDiffieHellman(bits), {
119+
- code: 'ERR_OSSL_DH_MODULUS_TOO_SMALL',
120+
+ code: 'ERR_OSSL_BN_BITS_TOO_SMALL',
121+
name: 'Error',
122+
message: /modulus too small/,
116123
});
117-
} else {
124+
@@ -35,7 +35,7 @@ for (const bits of [-1, 0, 1]) {
118125
assert.throws(() => crypto.createDiffieHellman(bits), {
119-
- code: 'ERR_OSSL_BN_BITS_TOO_SMALL',
120-
+ code: /ERR_OSSL_BN_BITS_TOO_SMALL|ERR_OSSL_DH_MODULUS_TOO_LARGE/,
126+
code: 'ERR_OSSL_BN_BITS_TOO_SMALL',
121127
name: 'Error',
122128
- message: /bits too small/,
123-
+ message: /bits too small|BITS_TOO_SMALL|MODULUS_TOO_LARGE/,
129+
+ message: /bits[\s_]too[\s_]small/i,
124130
});
125131
}
126132
}
127133
diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js
128-
index d7ffbe5eca92734aa2380f482c7f9bfe7e2a36c7..21ab2333431ea70bdf98dde43624e0b712566395 100644
134+
index d7ffbe5eca92734aa2380f482c7f9bfe7e2a36c7..b4e7002d862907d2af3b4f8e985700bd03300809 100644
129135
--- a/test/parallel/test-crypto-dh.js
130136
+++ b/test/parallel/test-crypto-dh.js
131137
@@ -60,18 +60,17 @@ const {
@@ -136,10 +142,10 @@ index d7ffbe5eca92734aa2380f482c7f9bfe7e2a36c7..21ab2333431ea70bdf98dde43624e0b7
136142
- code: 'ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH',
137143
- library: 'Provider routines',
138144
- reason: 'wrong final block length'
139-
+ message: /error:1C80006B:Provider routines::wrong final block length|error:1e00007b:Cipher functions:OPENSSL_internal:WRONG_FINAL_BLOCK_LENGTH/,
145+
+ message: /wrong[\s_]final[\s_]block[\s_]length/i,
140146
+ code: /ERR_OSSL_(EVP_)?WRONG_FINAL_BLOCK_LENGTH/,
141-
+ library: /digital envelope routines|Cipher functions/,
142-
+ reason: /wrong final block length|WRONG_FINAL_BLOCK_LENGTH/
147+
+ library: /Provider routines|Cipher functions/,
148+
+ reason: /wrong[\s_]final[\s_]block[\s_]length/i,
143149
};
144150
} else {
145151
wrongBlockLength = {
@@ -148,10 +154,10 @@ index d7ffbe5eca92734aa2380f482c7f9bfe7e2a36c7..21ab2333431ea70bdf98dde43624e0b7
148154
- code: 'ERR_OSSL_EVP_WRONG_FINAL_BLOCK_LENGTH',
149155
- library: 'digital envelope routines',
150156
- reason: 'wrong final block length'
151-
+ message: /error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length|error:1e00007b:Cipher functions:OPENSSL_internal:WRONG_FINAL_BLOCK_LENGTH/,
157+
+ message: /wrong[\s_]final[\s_]block[\s_]length/i,
152158
+ code: /ERR_OSSL_(EVP_)?WRONG_FINAL_BLOCK_LENGTH/,
153159
+ library: /digital envelope routines|Cipher functions/,
154-
+ reason: /wrong final block length|WRONG_FINAL_BLOCK_LENGTH/
160+
+ reason: /wrong[\s_]final[\s_]block[\s_]length/i,
155161
};
156162
}
157163

@@ -217,33 +223,46 @@ index 61145aee0727fbe0b9781acdb3eeb641e7010729..51693e637b310981f76f23c2f35d43e4
217223
if (!hasOpenSSL(3, 4)) {
218224
assert.strictEqual(crypto.createHash('shake128').digest('hex'),
219225
diff --git a/test/parallel/test-crypto-padding.js b/test/parallel/test-crypto-padding.js
220-
index 48cd1ed4df61aaddeee8785cb90f83bdd9628187..a18aeb2bdffcc7a7e9ef12328b849994e39d6c27 100644
226+
index 48cd1ed4df61aaddeee8785cb90f83bdd9628187..d09e01712c617597833bb1320a32a967bcf1d318 100644
221227
--- a/test/parallel/test-crypto-padding.js
222228
+++ b/test/parallel/test-crypto-padding.js
223-
@@ -88,10 +88,9 @@ assert.throws(function() {
224-
code: 'ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH',
225-
reason: 'wrong final block length',
229+
@@ -84,14 +84,13 @@ assert.throws(function() {
230+
// Input must have block length %.
231+
enc(ODD_LENGTH_PLAIN, false);
232+
}, hasOpenSSL3 ? {
233+
- message: 'error:1C80006B:Provider routines::wrong final block length',
234+
- code: 'ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH',
235+
- reason: 'wrong final block length',
236+
+ message: /wrong[\s_]final[\s_]block[\s_]length/i,
237+
+ code: /ERR_OSSL(_EVP)?_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH/,
238+
+ message: /wrong[\s_]final[\s_]block[\s_]length/i,
226239
} : {
227240
- message: 'error:0607F08A:digital envelope routines:EVP_EncryptFinal_ex:' +
228241
- 'data not multiple of block length',
229242
- code: 'ERR_OSSL_EVP_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH',
230243
- reason: 'data not multiple of block length',
231-
+ message: /error:0607F08A:digital envelope routines:EVP_EncryptFinal_ex:data not multiple of block length|error:1e00006a:Cipher functions:OPENSSL_internal:DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH/,
244+
+ message: /data[\s_]not[\s_]multiple[\s_]of[\s_]block[\s_]length/i,
232245
+ code: /ERR_OSSL(_EVP)?_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH/,
233-
+ reason: /data not multiple of block length|DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH/,
246+
+ reason: /data[\s_]not[\s_]multiple[\s_]of[\s_]block[\s_]length/i,
234247
}
235248
);
236249

237-
@@ -115,10 +114,9 @@ assert.throws(function() {
238-
reason: 'bad decrypt',
239-
code: 'ERR_OSSL_BAD_DECRYPT',
240-
} : {
250+
@@ -110,15 +109,10 @@ assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED, false).length, 48);
251+
assert.throws(function() {
252+
// Must have at least 1 byte of padding (PKCS):
253+
assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED_NOPAD, true), EVEN_LENGTH_PLAIN);
254+
-}, hasOpenSSL3 ? {
255+
- message: 'error:1C800064:Provider routines::bad decrypt',
256+
- reason: 'bad decrypt',
257+
- code: 'ERR_OSSL_BAD_DECRYPT',
258+
-} : {
241259
- message: 'error:06065064:digital envelope routines:EVP_DecryptFinal_ex:' +
242260
- 'bad decrypt',
243261
- reason: 'bad decrypt',
244262
- code: 'ERR_OSSL_EVP_BAD_DECRYPT',
245-
+ message: /error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt|error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT/,
246-
+ reason: /bad decrypt|BAD_DECRYPT/,
263+
+}, {
264+
+ message: /bad[\s_]decrypt/i,
265+
+ reason: /bad[\s_]decrypt/i,
247266
+ code: /ERR_OSSL(_EVP)?_BAD_DECRYPT/,
248267
});
249268

@@ -358,6 +377,23 @@ index 0589d60736e377f24dc8550f87a6b7624173fc44..113003826fc47a589cf2334f7345e33d
358377

359378
for (const [file, length] of keys) {
360379
const privKey = fixtures.readKey(file);
380+
diff --git a/test/parallel/test-crypto-stream.js b/test/parallel/test-crypto-stream.js
381+
index 747af780469c22eb8e4c6c35424043e868f75c3d..ed0916b036a9af23d805007ebd609973ee954473 100644
382+
--- a/test/parallel/test-crypto-stream.js
383+
+++ b/test/parallel/test-crypto-stream.js
384+
@@ -73,9 +73,9 @@ const cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
385+
const decipher = crypto.createDecipheriv('aes-128-cbc', badkey, iv);
386+
387+
cipher.pipe(decipher)
388+
- .on('error', common.expectsError(hasOpenSSL3 ? {
389+
- message: /bad[\s_]decrypt/,
390+
- library: 'Provider routines',
391+
+ .on('error', common.expectsError((hasOpenSSL3 || process.features.openssl_is_boringssl) ? {
392+
+ message: /bad[\s_]decrypt/i,
393+
+ library: /Provider routines|Cipher functions/,
394+
reason: /bad[\s_]decrypt/i,
395+
} : {
396+
message: /bad[\s_]decrypt/i,
361397
diff --git a/test/parallel/test-crypto.js b/test/parallel/test-crypto.js
362398
index 84111740cd9ef6425b747e24e984e66e46b0b2ef..b1621d310536fae3fdec91a6a9d275ec8fc99a98 100644
363399
--- a/test/parallel/test-crypto.js
@@ -415,6 +451,29 @@ index 84111740cd9ef6425b747e24e984e66e46b0b2ef..b1621d310536fae3fdec91a6a9d275ec
415451
// Make sure memory isn't released before being returned
416452
console.log(crypto.randomBytes(16));
417453

454+
diff --git a/test/parallel/test-tls-alert-handling.js b/test/parallel/test-tls-alert-handling.js
455+
index 7bd42bbe721c4c9442410d524c5ca740078fc72c..de49dbdc2b75517f497af353a6b24b1beb11ed69 100644
456+
--- a/test/parallel/test-tls-alert-handling.js
457+
+++ b/test/parallel/test-tls-alert-handling.js
458+
@@ -43,7 +43,8 @@ const errorHandler = common.mustCall((err) => {
459+
460+
assert.strictEqual(err.code, expectedErrorCode);
461+
assert.strictEqual(err.library, 'SSL routines');
462+
- if (!hasOpenSSL3) assert.strictEqual(err.function, 'ssl3_get_record');
463+
+ if (!hasOpenSSL3 && !process.features.openssl_is_boringssl)
464+
+ assert.strictEqual(err.function, 'ssl3_get_record');
465+
assert.match(err.reason, expectedErrorReason);
466+
errorReceived = true;
467+
if (canCloseServer())
468+
@@ -105,7 +106,7 @@ function sendBADTLSRecord() {
469+
}
470+
assert.strictEqual(err.code, expectedErrorCode);
471+
assert.strictEqual(err.library, 'SSL routines');
472+
- if (!hasOpenSSL3)
473+
+ if (!hasOpenSSL3 && !process.features.openssl_is_boringssl)
474+
assert.strictEqual(err.function, 'ssl3_read_bytes');
475+
assert.match(err.reason, expectedErrorReason);
476+
}));
418477
diff --git a/test/parallel/test-webcrypto-wrap-unwrap.js b/test/parallel/test-webcrypto-wrap-unwrap.js
419478
index d1ca571af4be713082d32093bfb8a65f2aef9800..57b8df2ce18df58ff54b2d828af67e3c2e082fe0 100644
420479
--- a/test/parallel/test-webcrypto-wrap-unwrap.js

patches/node/fix_handle_boringssl_and_openssl_incompatibilities.patch

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,21 @@ index c42493ad958508f650917bf5ca92088714a5056c..07accfbcca491966c6c8ad9c20e146db
541541
#if OPENSSL_VERSION_MAJOR >= 3
542542
// We declare another alias here to avoid having to include crypto_util.h
543543
using EVPMDPointer = DeleteFnPtr<EVP_MD, EVP_MD_free>;
544+
diff --git a/src/node_config.cc b/src/node_config.cc
545+
index 6032bbd10f41da7bae44828a8e908c1bec0ea0b6..8597f1d6972ea111ea7e53a3199c1b4e86de166f 100644
546+
--- a/src/node_config.cc
547+
+++ b/src/node_config.cc
548+
@@ -7,6 +7,10 @@
549+
#include "node_options.h"
550+
#include "util-inl.h"
551+
552+
+#if HAVE_OPENSSL
553+
+#include <openssl/base.h>
554+
+#endif
555+
+
556+
namespace node {
557+
558+
using v8::Context;
544559
diff --git a/src/node_metadata.h b/src/node_metadata.h
545560
index 7b2072ad39c3f1a7c73101b25b69beb781141e26..d23536d88d21255d348175425a59e2424332cd19 100644
546561
--- a/src/node_metadata.h

0 commit comments

Comments
 (0)