Skip to content

Commit 557875b

Browse files
panvaeverett1992
authored andcommitted
test: account for varied OpenSSL CCM final behaviours
Backport of the test-only commit from #65542. Distributions that build Node against their own newer OpenSSL and run the upstream test suite already see this test fail on v22.x and v24.x. The same backport is needed if and when these lines update the bundled OpenSSL. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Signed-off-by: Caleb ツ Everett <calebev@amazon.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: #65710 Refs: #65711 Assisted-by: a closed-source coding agent
1 parent 3376e27 commit 557875b

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)