Fix integrity_protect = false

This commit is contained in:
Daniel Huigens 2018-05-17 19:09:11 +02:00
parent d67526338e
commit 58eca571bf

View File

@ -19,11 +19,13 @@
* @requires config * @requires config
* @requires crypto * @requires crypto
* @requires enums * @requires enums
* @requires stream
*/ */
import config from '../config'; import config from '../config';
import crypto from '../crypto'; import crypto from '../crypto';
import enums from '../enums'; import enums from '../enums';
import stream from '../stream';
/** /**
* Implementation of the Symmetrically Encrypted Data Packet (Tag 9) * Implementation of the Symmetrically Encrypted Data Packet (Tag 9)
@ -76,7 +78,7 @@ 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, this.encrypted, true); const decrypted = crypto.cfb.decrypt(sessionKeyAlgorithm, key, await stream.readToEnd(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.');
@ -97,7 +99,7 @@ SymmetricallyEncrypted.prototype.decrypt = async function (sessionKeyAlgorithm,
SymmetricallyEncrypted.prototype.encrypt = async function (algo, key) { SymmetricallyEncrypted.prototype.encrypt = async function (algo, key) {
const data = this.packets.write(); const data = this.packets.write();
this.encrypted = crypto.cfb.encrypt(await crypto.getPrefixRandom(algo), algo, data, key, true); this.encrypted = crypto.cfb.encrypt(await crypto.getPrefixRandom(algo), algo, await stream.readToEnd(data), key, true);
return true; return true;
}; };