AES-256-CBC has no key verification: decrypting with a random wrong key
yields accidentally valid PKCS#7 padding ~0.4% of the time, so the old
toThrow assertion failed randomly in CI. The wrong-key test now accepts
both legal outcomes (KsefSessionCryptoException or garbage != plaintext),
and a new deterministic test covers the exception-wrapping path via a
truncated ciphertext, which always fails decipher.final().
No production code changes.
Closes #1538
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: norbert-kulus-blockydevs <norbert.kulus@blockydevs.com>
What / Why
The KSeF unit test
aes-cipher > should throw KsefSessionCryptoException when decrypting with the wrong keywas inherently flaky (~0.4% of CI runs). AES-256-CBC has no built-in key verification: decrypting with a random wrong key produces pseudo-random bytes that end in accidentally valid PKCS#7 padding with probability ~1/256 (+ smaller contributions from longer paddings), in which casedecryptAesCbcreturns garbage instead of throwing and thetoThrowassertion failed. Observed on PR #1515 CI run 29322744163, which touched only a workflow file.Test-only fix, per the issue:
decryptAesCbcthrowsKsefSessionCryptoException, or it returns a value different from the original plaintext ('secret'). Both are legal outcomes.KsefSessionCryptoExceptionwrapping path: a ciphertext truncated by 1 byte is not a multiple of the AES block size, sodecipher.final()always throws.No changes to
aes-cipher.ts.Verification
jest --testPathPattern aes-cipherin@openlinker/integrations-ksef: 6/6 tests pass.encryptAesCbc/decryptAesCbcfunctions directly:KsefSessionCryptoException, 374 returned garbage (the ~0.4% case that used to fail CI - now asserted as legal), 0 failures.KsefSessionCryptoException(deterministic).eslinton the spec) andpnpm --filter @openlinker/integrations-ksef... build(tsc -b) pass.Closes #1538
🤖 Generated with Claude Code