Skip to content

Commit efdaebc

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

22 files changed

+299
-194
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: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -626,22 +626,25 @@ 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

644-
{
647+
if (!process.features.openssl_is_boringssl) {
645648
const key = Buffer.alloc(32);
646649
const iv = Buffer.alloc(12);
647650

@@ -653,11 +656,13 @@ for (const test of TEST_CASES) {
653656
message: errMessages.authTagLength
654657
});
655658
}
659+
} else {
660+
common.printSkipMessage('Skipping unsupported chacha20-poly1305 test');
656661
}
657662

658663
// ChaCha20-Poly1305 should respect the authTagLength option and should not
659664
// require the authentication tag before calls to update() during decryption.
660-
{
665+
if (!process.features.openssl_is_boringssl) {
661666
const key = Buffer.alloc(32);
662667
const iv = Buffer.alloc(12);
663668

@@ -697,6 +702,8 @@ for (const test of TEST_CASES) {
697702
}
698703
}
699704
}
705+
} else {
706+
common.printSkipMessage('Skipping unsupported chacha20-poly1305 test');
700707
}
701708

702709
// ChaCha20-Poly1305 should default to an authTagLength of 16. When encrypting,
@@ -706,7 +713,7 @@ for (const test of TEST_CASES) {
706713
// shorter tags as long as their length was valid according to NIST SP 800-38D.
707714
// For ChaCha20-Poly1305, we intentionally deviate from that because there are
708715
// no recommended or approved authentication tag lengths below 16 bytes.
709-
{
716+
if (!process.features.openssl_is_boringssl) {
710717
const rfcTestCases = TEST_CASES.filter(({ algo, tampered }) => {
711718
return algo === 'chacha20-poly1305' && tampered === false;
712719
});
@@ -740,10 +747,12 @@ for (const test of TEST_CASES) {
740747

741748
assert.strictEqual(plaintext.toString('hex'), testCase.plain);
742749
}
750+
} else {
751+
common.printSkipMessage('Skipping unsupported chacha20-poly1305 test');
743752
}
744753

745754
// https://github.com/nodejs/node/issues/45874
746-
{
755+
if (!process.features.openssl_is_boringssl) {
747756
const rfcTestCases = TEST_CASES.filter(({ algo, tampered }) => {
748757
return algo === 'chacha20-poly1305' && tampered === false;
749758
});
@@ -771,4 +780,6 @@ for (const test of TEST_CASES) {
771780
assert.throws(() => {
772781
decipher.final();
773782
}, /Unsupported state or unable to authenticate data/);
783+
} else {
784+
common.printSkipMessage('Skipping unsupported chacha20-poly1305 test');
774785
}

test/parallel/test-crypto-default-shake-lengths-oneshot.js

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

7+
if (process.features.openssl_is_boringssl) {
8+
common.skip('Skipping unsupported shake128 digest method test');
9+
}
10+
711
const { hash } = require('crypto');
812

913
common.expectWarning({

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);

0 commit comments

Comments
 (0)