Skip to content

Commit f659ab0

Browse files
committed
test,crypto: adjust tests for BoringSSL
1 parent 33ea43e commit f659ab0

20 files changed

+269
-188
lines changed

test/parallel/test-crypto-async-sign-verify.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ if (!process.features.openssl_is_boringssl) {
102102
// ECDSA w/ ieee-p1363 signature encoding
103103
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384', false,
104104
{ dsaEncoding: 'ieee-p1363' });
105-
}
106105

107-
// DSA w/ der signature encoding
108-
test('dsa_public.pem', 'dsa_private.pem', 'sha256',
109-
false);
110-
test('dsa_public.pem', 'dsa_private.pem', 'sha256',
111-
false, { dsaEncoding: 'der' });
106+
// DSA w/ der signature encoding
107+
test('dsa_public.pem', 'dsa_private.pem', 'sha256',
108+
false);
109+
test('dsa_public.pem', 'dsa_private.pem', 'sha256',
110+
false, { dsaEncoding: 'der' });
112111

113-
// DSA w/ ieee-p1363 signature encoding
114-
test('dsa_public.pem', 'dsa_private.pem', 'sha256', false,
115-
{ dsaEncoding: 'ieee-p1363' });
112+
// DSA w/ ieee-p1363 signature encoding
113+
test('dsa_public.pem', 'dsa_private.pem', 'sha256', false,
114+
{ dsaEncoding: 'ieee-p1363' });
115+
}
116116

117117
// Test Parallel Execution w/ KeyObject is threadsafe in openssl3
118118
{

test/parallel/test-crypto-authenticated.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -626,19 +626,22 @@ for (const test of TEST_CASES) {
626626

627627
{
628628
// CCM cipher without data should not crash, see https://github.com/nodejs/node/issues/38035.
629-
const algo = 'aes-128-ccm';
630-
const key = Buffer.alloc(16);
631-
const iv = Buffer.alloc(12);
632-
const opts = { authTagLength: 10 };
629+
if (!ciphers.includes('aes-128-ccm')) {
630+
common.printSkipMessage(`unsupported aes-128-ccm test`);
631+
} else {
632+
const key = Buffer.alloc(16);
633+
const iv = Buffer.alloc(12);
634+
const opts = { authTagLength: 10 };
633635

634-
const cipher = crypto.createCipheriv(algo, key, iv, opts);
635-
assert.throws(() => {
636-
cipher.final();
637-
}, hasOpenSSL3 ? {
638-
code: 'ERR_OSSL_TAG_NOT_SET'
639-
} : {
640-
message: /Unsupported state/
641-
});
636+
const cipher = crypto.createCipheriv('aes-128-ccm', key, iv, opts);
637+
assert.throws(() => {
638+
cipher.final();
639+
}, hasOpenSSL3 ? {
640+
code: 'ERR_OSSL_TAG_NOT_SET'
641+
} : {
642+
message: /Unsupported state/
643+
});
644+
}
642645
}
643646

644647
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' +
1616
crypto.createDiffieHellman(p, 'hex');
1717

1818
// Confirm DH_check() results are exposed for optional examination.
19-
const bad_dh = crypto.createDiffieHellman('02', 'hex');
19+
const bad_dh = crypto.createDiffieHellman('abcd', 'hex', 0);
2020
assert.notStrictEqual(bad_dh.verifyError, 0);
2121

2222
const availableCurves = new Set(crypto.getCurves());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ assert.throws(() => crypto.createDiffieHellman('abcdef', 13.37), {
2727
for (const bits of [-1, 0, 1]) {
2828
if (hasOpenSSL3) {
2929
assert.throws(() => crypto.createDiffieHellman(bits), {
30-
code: 'ERR_OSSL_DH_MODULUS_TOO_SMALL',
30+
code: /ERR_OSSL_(BN_BITS|DH_MODULUS)_TOO_SMALL/,
3131
name: 'Error',
3232
message: /modulus too small/,
3333
});
3434
} else {
3535
assert.throws(() => crypto.createDiffieHellman(bits), {
36-
code: 'ERR_OSSL_BN_BITS_TOO_SMALL',
36+
code: /ERR_OSSL_(BN_BITS|DH_MODULUS)_TOO_SMALL/,
3737
name: 'Error',
3838
message: /bits[\s_]too[\s_]small/i,
3939
});

test/parallel/test-crypto-dh-group-setters.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ if (!common.hasCrypto)
66
const assert = require('assert');
77
const crypto = require('crypto');
88

9+
if (process.features.openssl_is_boringssl) {
10+
common.skip('Skipping unsupported Diffie-Hellman tests');
11+
}
12+
913
// Unlike DiffieHellman, DiffieHellmanGroup does not have any setters.
1014
const dhg = crypto.getDiffieHellman('modp1');
1115
assert.strictEqual(dhg.constructor, crypto.DiffieHellmanGroup);

test/parallel/test-crypto-dh-modp2-views.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const assert = require('assert');
77
const crypto = require('crypto');
88
const { modp2buf } = require('../common/crypto');
99

10+
if (process.features.openssl_is_boringssl) {
11+
common.skip('Skipping unsupported Diffie-Hellman tests');
12+
}
13+
1014
const modp2 = crypto.createDiffieHellmanGroup('modp2');
1115

1216
const views = common.getArrayBufferViews(modp2buf);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ if (!common.hasCrypto)
66
const assert = require('assert');
77
const crypto = require('crypto');
88
const { modp2buf } = require('../common/crypto');
9+
10+
if (process.features.openssl_is_boringssl) {
11+
common.skip('Skipping unsupported Diffie-Hellman tests');
12+
}
13+
914
const modp2 = crypto.createDiffieHellmanGroup('modp2');
1015

1116
{

test/parallel/test-crypto-dh.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,21 @@ const {
9797
dh3.computeSecret('');
9898
}, { message: hasOpenSSL3 && !hasOpenSSL3WithNewErrorMessage ?
9999
'Unspecified validation error' :
100-
'Supplied key is too small' });
100+
/Supplied key is (too small|invalid)/ });
101101
}
102102
}
103103

104104
// Through a fluke of history, g=0 defaults to DH_GENERATOR (2).
105-
{
105+
if (!process.features.openssl_is_boringssl) {
106106
const g = 0;
107107
crypto.createDiffieHellman('abcdef', g);
108108
crypto.createDiffieHellman('abcdef', 'hex', g);
109+
} else {
110+
common.printSkipMessage('Skipping unsupported g=0 Diffie-Hellman tests');
109111
}
110112

111-
{
113+
if (!process.features.openssl_is_boringssl) {
112114
crypto.createDiffieHellman('abcdef', Buffer.from([2])); // OK
115+
} else {
116+
common.printSkipMessage('Skipping unsupported g=0 Diffie-Hellman tests');
113117
}

test/parallel/test-crypto-hash-stream-pipe.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ const crypto = require('crypto');
3030

3131
const stream = require('stream');
3232
const s = new stream.PassThrough();
33-
const h = crypto.createHash('sha3-512');
34-
const expect = '36a38a2a35e698974d4e5791a3f05b05' +
35-
'198235381e864f91a0e8cd6a26b677ec' +
36-
'dcde8e2b069bd7355fabd68abd6fc801' +
37-
'19659f25e92f8efc961ee3a7c815c758';
33+
const h = crypto.createHash('sha512');
34+
const expect = 'fba055c6fd0c5b6645407749ed7a8b41' +
35+
'b8f629f2163c3ca3701d864adabda1f8' +
36+
'93c37bf82b22fdd151ba8e357f611da4' +
37+
'88a74b6a5525dd9b69554c6ce5138ad7';
3838

3939
s.pipe(h).on('data', common.mustCall(function(c) {
4040
assert.strictEqual(c, expect);

test/parallel/test-crypto-key-objects.js

Lines changed: 74 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
302302
}, hasOpenSSL3 ? {
303303
message: 'error:1E08010C:DECODER routines::unsupported',
304304
} : {
305-
message: 'error:0909006C:PEM routines:get_name:no start line',
305+
message: /no.start.line/i,
306306
code: 'ERR_OSSL_PEM_NO_START_LINE',
307-
reason: 'no start line',
307+
reason: /no.start.line/i,
308308
library: 'PEM routines',
309-
function: 'get_name',
309+
function: /get_name|OPENSSL_internal/,
310310
});
311311

312312
// This should not abort either: https://github.com/nodejs/node/issues/29904
@@ -329,53 +329,65 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
329329
message: /error:1E08010C:DECODER routines::unsupported/,
330330
library: 'DECODER routines'
331331
} : {
332-
message: /asn1 encoding/,
333-
library: 'asn1 encoding routines'
332+
message: /asn1 encoding|public key routines/,
333+
library: /asn1 encoding routines|public key routines/
334334
});
335335
}
336336

337-
[
338-
{ private: fixtures.readKey('ed25519_private.pem', 'ascii'),
337+
const infos = [
338+
{
339+
private: fixtures.readKey('ed25519_private.pem', 'ascii'),
339340
public: fixtures.readKey('ed25519_public.pem', 'ascii'),
340341
keyType: 'ed25519',
341342
jwk: {
342343
crv: 'Ed25519',
343344
x: 'K1wIouqnuiA04b3WrMa-xKIKIpfHetNZRv3h9fBf768',
344345
d: 'wVK6M3SMhQh3NK-7GRrSV-BVWQx1FO5pW8hhQeu_NdA',
345346
kty: 'OKP'
346-
} },
347-
{ private: fixtures.readKey('ed448_private.pem', 'ascii'),
348-
public: fixtures.readKey('ed448_public.pem', 'ascii'),
349-
keyType: 'ed448',
350-
jwk: {
351-
crv: 'Ed448',
352-
x: 'oX_ee5-jlcU53-BbGRsGIzly0V-SZtJ_oGXY0udf84q2hTW2RdstLktvwpkVJOoNb7o' +
353-
'Dgc2V5ZUA',
354-
d: '060Ke71sN0GpIc01nnGgMDkp0sFNQ09woVo4AM1ffax1-mjnakK0-p-S7-Xf859QewX' +
355-
'jcR9mxppY',
356-
kty: 'OKP'
357-
} },
358-
{ private: fixtures.readKey('x25519_private.pem', 'ascii'),
347+
}
348+
},
349+
{
350+
private: fixtures.readKey('x25519_private.pem', 'ascii'),
359351
public: fixtures.readKey('x25519_public.pem', 'ascii'),
360352
keyType: 'x25519',
361353
jwk: {
362354
crv: 'X25519',
363355
x: 'aSb8Q-RndwfNnPeOYGYPDUN3uhAPnMLzXyfi-mqfhig',
364356
d: 'mL_IWm55RrALUGRfJYzw40gEYWMvtRkesP9mj8o8Omc',
365357
kty: 'OKP'
366-
} },
367-
{ private: fixtures.readKey('x448_private.pem', 'ascii'),
358+
}
359+
},
360+
]
361+
362+
if (!process.features.openssl_is_boringssl) {
363+
infos.push({
364+
private: fixtures.readKey('ed448_private.pem', 'ascii'),
365+
public: fixtures.readKey('ed448_public.pem', 'ascii'),
366+
keyType: 'ed448',
367+
jwk: {
368+
crv: 'Ed448',
369+
x: 'oX_ee5-jlcU53-BbGRsGIzly0V-SZtJ_oGXY0udf84q2hTW2RdstLktvwpkVJOoNb7o' +
370+
'Dgc2V5ZUA',
371+
d: '060Ke71sN0GpIc01nnGgMDkp0sFNQ09woVo4AM1ffax1-mjnakK0-p-S7-Xf859QewX' +
372+
'jcR9mxppY',
373+
kty: 'OKP'
374+
}
375+
}, {
376+
private: fixtures.readKey('x448_private.pem', 'ascii'),
368377
public: fixtures.readKey('x448_public.pem', 'ascii'),
369378
keyType: 'x448',
370379
jwk: {
371380
crv: 'X448',
372381
x: 'ioHSHVpTs6hMvghosEJDIR7ceFiE3-Xccxati64oOVJ7NWjfozE7ae31PXIUFq6cVYg' +
373-
'vSKsDFPA',
382+
'vSKsDFPA',
374383
d: 'tMNtrO_q8dlY6Y4NDeSTxNQ5CACkHiPvmukidPnNIuX_EkcryLEXt_7i6j6YZMKsrWy' +
375-
'S0jlSYJk',
384+
'S0jlSYJk',
376385
kty: 'OKP'
377-
} },
378-
].forEach((info) => {
386+
}
387+
});
388+
}
389+
390+
infos.forEach((info) => {
379391
const keyType = info.keyType;
380392

381393
{
@@ -417,8 +429,9 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
417429
}
418430
});
419431

420-
[
421-
{ private: fixtures.readKey('ec_p256_private.pem', 'ascii'),
432+
const ecInfos = [
433+
{
434+
private: fixtures.readKey('ec_p256_private.pem', 'ascii'),
422435
public: fixtures.readKey('ec_p256_public.pem', 'ascii'),
423436
keyType: 'ec',
424437
namedCurve: 'prime256v1',
@@ -428,19 +441,10 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
428441
kty: 'EC',
429442
x: 'X0mMYR_uleZSIPjNztIkAS3_ud5LhNpbiIFp6fNf2Gs',
430443
y: 'UbJuPy2Xi0lW7UYTBxPK3yGgDu9EAKYIecjkHX5s2lI'
431-
} },
432-
{ private: fixtures.readKey('ec_secp256k1_private.pem', 'ascii'),
433-
public: fixtures.readKey('ec_secp256k1_public.pem', 'ascii'),
434-
keyType: 'ec',
435-
namedCurve: 'secp256k1',
436-
jwk: {
437-
crv: 'secp256k1',
438-
d: 'c34ocwTwpFa9NZZh3l88qXyrkoYSxvC0FEsU5v1v4IM',
439-
kty: 'EC',
440-
x: 'cOzhFSpWxhalCbWNdP2H_yUkdC81C9T2deDpfxK7owA',
441-
y: '-A3DAZTk9IPppN-f03JydgHaFvL1fAHaoXf4SX4NXyo'
442-
} },
443-
{ private: fixtures.readKey('ec_p384_private.pem', 'ascii'),
444+
}
445+
},
446+
{
447+
private: fixtures.readKey('ec_p384_private.pem', 'ascii'),
444448
public: fixtures.readKey('ec_p384_public.pem', 'ascii'),
445449
keyType: 'ec',
446450
namedCurve: 'secp384r1',
@@ -450,8 +454,10 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
450454
kty: 'EC',
451455
x: 'hON3nzGJgv-08fdHpQxgRJFZzlK-GZDGa5f3KnvM31cvvjJmsj4UeOgIdy3rDAjV',
452456
y: 'fidHhtecNCGCfLqmrLjDena1NSzWzWH1u_oUdMKGo5XSabxzD7-8JZxjpc8sR9cl'
453-
} },
454-
{ private: fixtures.readKey('ec_p521_private.pem', 'ascii'),
457+
}
458+
},
459+
{
460+
private: fixtures.readKey('ec_p521_private.pem', 'ascii'),
455461
public: fixtures.readKey('ec_p521_public.pem', 'ascii'),
456462
keyType: 'ec',
457463
namedCurve: 'secp521r1',
@@ -464,8 +470,27 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
464470
'CbhMeHRavUS6P10rsTtBn',
465471
y: 'Ad3flexBeAfXceNzRBH128kFbOWD6W41NjwKRqqIF26vmgW_8COldGKZjFkOSEASxPB' +
466472
'cvA2iFJRUyQ3whC00j0Np'
467-
} },
468-
].forEach((info) => {
473+
}
474+
},
475+
]
476+
477+
if (!process.features.openssl_is_boringssl) {
478+
ecInfos.push({
479+
private: fixtures.readKey('ec_secp256k1_private.pem', 'ascii'),
480+
public: fixtures.readKey('ec_secp256k1_public.pem', 'ascii'),
481+
keyType: 'ec',
482+
namedCurve: 'secp256k1',
483+
jwk: {
484+
crv: 'secp256k1',
485+
d: 'c34ocwTwpFa9NZZh3l88qXyrkoYSxvC0FEsU5v1v4IM',
486+
kty: 'EC',
487+
x: 'cOzhFSpWxhalCbWNdP2H_yUkdC81C9T2deDpfxK7owA',
488+
y: '-A3DAZTk9IPppN-f03JydgHaFvL1fAHaoXf4SX4NXyo'
489+
}
490+
});
491+
}
492+
493+
ecInfos.forEach((info) => {
469494
const { keyType, namedCurve } = info;
470495

471496
{
@@ -540,7 +565,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
540565
format: 'pem',
541566
passphrase: Buffer.alloc(1024, 'a')
542567
}), {
543-
message: /bad decrypt/
568+
message: /bad.decrypt/i
544569
});
545570

546571
const publicKey = createPublicKey(publicDsa);
@@ -566,7 +591,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
566591

567592
{
568593
// Test RSA-PSS.
569-
{
594+
if (!process.features.openssl_is_boringssl) {
570595
// This key pair does not restrict the message digest algorithm or salt
571596
// length.
572597
const publicPem = fixtures.readKey('rsa_pss_public_2048.pem');
@@ -625,6 +650,8 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
625650
}, {
626651
code: 'ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS'
627652
});
653+
} else {
654+
common.skip('Skipping unsupported RSA-PSS key test');
628655
}
629656

630657
{

0 commit comments

Comments
 (0)