Skip to content

Commit 0563f93

Browse files
panvaaduh95
authored andcommitted
test: account for varied OpenSSL CCM final behaviours
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #65542 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
1 parent 04f02d1 commit 0563f93

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

test/parallel/test-crypto-authenticated.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,29 @@ for (const test of TEST_CASES) {
633633
const iv = Buffer.alloc(12);
634634
const opts = { authTagLength: 10 };
635635

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

0 commit comments

Comments
 (0)