From 54fc1dde3dc1fc36d5d50a03f928f826fa94036b Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Tue, 12 Feb 2019 11:43:39 +0100 Subject: [PATCH] Throw error before decrypting in non-MDC packets --- src/packet/symmetrically_encrypted.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/packet/symmetrically_encrypted.js b/src/packet/symmetrically_encrypted.js index f06fbf9c..79a5944b 100644 --- a/src/packet/symmetrically_encrypted.js +++ b/src/packet/symmetrically_encrypted.js @@ -80,16 +80,17 @@ SymmetricallyEncrypted.prototype.write = function () { * @async */ SymmetricallyEncrypted.prototype.decrypt = async function (sessionKeyAlgorithm, key) { + // If MDC errors are not being ignored, all missing MDC packets in symmetrically encrypted data should throw an error + if (!this.ignore_mdc_error) { + throw new Error('Decryption failed due to missing MDC.'); + } + this.encrypted = await stream.readToEnd(this.encrypted); const decrypted = await crypto.cfb.decrypt(sessionKeyAlgorithm, key, this.encrypted.subarray(crypto.cipher[sessionKeyAlgorithm].blockSize + 2), this.encrypted.subarray(2, crypto.cipher[sessionKeyAlgorithm].blockSize + 2) ); - // If MDC errors are not being ignored, all missing MDC packets in symmetrically encrypted data should throw an error - if (!this.ignore_mdc_error) { - throw new Error('Decryption failed due to missing MDC.'); - } await this.packets.read(decrypted); return true;