Skip to content

Commit 40eac4a

Browse files
panvaaduh95
authored andcommitted
test: account for varied OpenSSL CCM final behaviours
Signed-off-by: Filip Skokan <[email protected]> PR-URL: #65542 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Marco Ippolito <[email protected]>
1 parent 59d853a commit 40eac4a

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

test/parallel/test-crypto-authenticated.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -626,19 +626,33 @@ 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';
630629
const key = Buffer.alloc(16);
631630
const iv = Buffer.alloc(12);
632631
const opts = { authTagLength: 10 };
633632

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-
});
633+
const control = crypto.createCipheriv('aes-128-ccm', key, iv, opts);
634+
control.update(Buffer.alloc(0));
635+
control.final();
636+
const expectedTag = control.getAuthTag();
637+
638+
const cipher = crypto.createCipheriv('aes-128-ccm', key, iv, opts);
639+
let output;
640+
try {
641+
output = cipher.final();
642+
} catch (err) {
643+
// OpenSSL without https://github.com/openssl/openssl/pull/32427
644+
// cannot finalize an empty CCM message unless update() was called.
645+
if (hasOpenSSL3) {
646+
assert.strictEqual(err.code, 'ERR_OSSL_TAG_NOT_SET');
647+
} else {
648+
assert.match(err.message, /Unsupported state/);
649+
}
650+
}
651+
652+
if (output !== undefined) {
653+
assert.deepStrictEqual(output, Buffer.alloc(0));
654+
assert.deepStrictEqual(cipher.getAuthTag(), expectedTag);
655+
}
642656
}
643657

644658
{

0 commit comments

Comments
 (0)