Symmetrically encrypted packet: raise error if MDC is missing for modern cipher.
This commit is contained in:
parent
9589fa0b52
commit
2ee347154c
|
@ -35,7 +35,10 @@ module.exports = {
|
||||||
prefer_hash_algorithm: enums.hash.sha256,
|
prefer_hash_algorithm: enums.hash.sha256,
|
||||||
encryption_cipher: enums.symmetric.aes256,
|
encryption_cipher: enums.symmetric.aes256,
|
||||||
compression: enums.compression.zip,
|
compression: enums.compression.zip,
|
||||||
|
// use integrity protection for symmetric encryption
|
||||||
integrity_protect: true,
|
integrity_protect: true,
|
||||||
|
// fail on decrypt if message is not integrity protected
|
||||||
|
ignore_mdc_error: false,
|
||||||
rsa_blinding: true,
|
rsa_blinding: true,
|
||||||
useWebCrypto: true,
|
useWebCrypto: true,
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,8 @@
|
||||||
module.exports = SymmetricallyEncrypted;
|
module.exports = SymmetricallyEncrypted;
|
||||||
|
|
||||||
var crypto = require('../crypto'),
|
var crypto = require('../crypto'),
|
||||||
enums = require('../enums.js');
|
enums = require('../enums.js'),
|
||||||
|
config = require('../config');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -42,6 +43,7 @@ function SymmetricallyEncrypted() {
|
||||||
/** Decrypted packets contained within.
|
/** Decrypted packets contained within.
|
||||||
* @type {module:packet/packetlist} */
|
* @type {module:packet/packetlist} */
|
||||||
this.packets = null;
|
this.packets = null;
|
||||||
|
this.ignore_mdc_error = config.ignore_mdc_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
SymmetricallyEncrypted.prototype.read = function (bytes) {
|
SymmetricallyEncrypted.prototype.read = function (bytes) {
|
||||||
|
@ -62,9 +64,14 @@ SymmetricallyEncrypted.prototype.write = function () {
|
||||||
* algorithm
|
* algorithm
|
||||||
*/
|
*/
|
||||||
SymmetricallyEncrypted.prototype.decrypt = function (sessionKeyAlgorithm, key) {
|
SymmetricallyEncrypted.prototype.decrypt = function (sessionKeyAlgorithm, key) {
|
||||||
var decrypted = crypto.cfb.decrypt(
|
var decrypted = crypto.cfb.decrypt(sessionKeyAlgorithm, key, this.encrypted, true);
|
||||||
sessionKeyAlgorithm, key, this.encrypted, true);
|
// for modern cipher (blocklength != 64 bit, except for Twofish) MDC is required
|
||||||
|
if (!this.ignore_mdc_error &&
|
||||||
|
(sessionKeyAlgorithm === 'aes128' ||
|
||||||
|
sessionKeyAlgorithm === 'aes192' ||
|
||||||
|
sessionKeyAlgorithm === 'aes256')) {
|
||||||
|
throw new Error('Decryption failed due to missing MDC in combination with modern cipher.')
|
||||||
|
}
|
||||||
this.packets.read(decrypted.join(''))
|
this.packets.read(decrypted.join(''))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user