mirror of
https://github.com/danbulant/jose
synced 2026-05-19 04:18:52 +00:00
fix: defer AES CBC w/ HMAC decryption after tag verification passes
This commit is contained in:
parent
9a8404a759
commit
08e1bc5ce7
1 changed files with 5 additions and 1 deletions
|
|
@ -44,13 +44,17 @@ const decrypt = (size, sign, { [KEYOBJECT]: keyObject }, ciphertext, { iv, tag =
|
|||
const expectedTag = sign({ [KEYOBJECT]: macKey }, macData, tag).slice(0, keySize)
|
||||
const macCheckPassed = timingSafeEqual(tag, expectedTag)
|
||||
|
||||
if (!macCheckPassed) {
|
||||
throw new JWEDecryptionFailed()
|
||||
}
|
||||
|
||||
let cleartext
|
||||
try {
|
||||
const cipher = createDecipheriv(`aes-${size}-cbc`, encKey, iv)
|
||||
cleartext = Buffer.concat([cipher.update(ciphertext), cipher.final()])
|
||||
} catch (err) {}
|
||||
|
||||
if (!cleartext || !macCheckPassed) {
|
||||
if (!cleartext) {
|
||||
throw new JWEDecryptionFailed()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue