Skip to content

Commit 25fc16c

Browse files
panvaeverett1992
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> (cherry picked from commit 28b571c) Refs: openssl/openssl#32427 Refs: #65711 Refs: #65710
1 parent 3376e27 commit 25fc16c

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
@@ -631,14 +631,29 @@ for (const test of TEST_CASES) {
631631
const iv = Buffer.alloc(12);
632632
const opts = { authTagLength: 10 };
633633

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

644659
{

0 commit comments

Comments
 (0)