Fix unhandled promise rejection when decrypting non-MDC message

This commit is contained in:
Daniel Huigens 2018-10-31 11:09:35 +01:00
parent 13c29b1fc9
commit 11fd2313a7
2 changed files with 7 additions and 6 deletions

View File

@ -78,7 +78,8 @@ SymmetricallyEncrypted.prototype.write = function () {
* @async * @async
*/ */
SymmetricallyEncrypted.prototype.decrypt = async function (sessionKeyAlgorithm, key) { SymmetricallyEncrypted.prototype.decrypt = async function (sessionKeyAlgorithm, key) {
const decrypted = crypto.cfb.decrypt(sessionKeyAlgorithm, key, await stream.readToEnd(this.encrypted), true); this.encrypted = await stream.readToEnd(this.encrypted);
const decrypted = crypto.cfb.decrypt(sessionKeyAlgorithm, key, this.encrypted, true);
// If MDC errors are not being ignored, all missing MDC packets in symmetrically encrypted data should throw an error // If MDC errors are not being ignored, all missing MDC packets in symmetrically encrypted data should throw an error
if (!this.ignore_mdc_error) { if (!this.ignore_mdc_error) {
throw new Error('Decryption failed due to missing MDC.'); throw new Error('Decryption failed due to missing MDC.');

View File

@ -77,12 +77,12 @@ describe("Packet", function() {
await enc.encrypt(algo, key); await enc.encrypt(algo, key);
const msg2 = new openpgp.packet.List(); const msg2 = new openpgp.message.Message();
await msg2.read(message.write()); await msg2.packets.read(message.write());
msg2[0].ignore_mdc_error = true; msg2.packets[0].ignore_mdc_error = true;
await msg2[0].decrypt(algo, key); const dec = await msg2.decrypt(null, null, [{ algorithm: algo, data: key }]);
expect(await stringify(msg2[0].packets[0].data)).to.equal(stringify(literal.data)); expect(await stringify(dec.packets[0].data)).to.equal(stringify(literal.data));
}); });
it('Symmetrically encrypted packet - MDC error for modern cipher', async function() { it('Symmetrically encrypted packet - MDC error for modern cipher', async function() {