Fix bug in message.decryptSessionKey where it would return this (msg obj)
Cleanup message code
This commit is contained in:
parent
55110c3409
commit
8d82a18c19
|
@ -91,7 +91,10 @@ Message.prototype.getSigningKeyIds = function() {
|
||||||
*/
|
*/
|
||||||
Message.prototype.decrypt = function(privateKey) {
|
Message.prototype.decrypt = function(privateKey) {
|
||||||
var keyObj = this.decryptSessionKey(privateKey);
|
var keyObj = this.decryptSessionKey(privateKey);
|
||||||
if (keyObj) {
|
if (!keyObj) {
|
||||||
|
// nothing to decrypt return unmodified message
|
||||||
|
return this;
|
||||||
|
}
|
||||||
var symEncryptedPacketlist = this.packets.filterByTag(enums.packet.symmetricallyEncrypted, enums.packet.symEncryptedIntegrityProtected);
|
var symEncryptedPacketlist = this.packets.filterByTag(enums.packet.symmetricallyEncrypted, enums.packet.symEncryptedIntegrityProtected);
|
||||||
if (symEncryptedPacketlist.length !== 0) {
|
if (symEncryptedPacketlist.length !== 0) {
|
||||||
var symEncryptedPacket = symEncryptedPacketlist[0];
|
var symEncryptedPacket = symEncryptedPacketlist[0];
|
||||||
|
@ -101,7 +104,6 @@ Message.prototype.decrypt = function(privateKey) {
|
||||||
symEncryptedPacket.packets = new packet.List();
|
symEncryptedPacket.packets = new packet.List();
|
||||||
return resultMsg;
|
return resultMsg;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,16 +128,15 @@ Message.prototype.decryptSessionKey = function(privateKey) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!keyPacket) {
|
if (!keyPacket) {
|
||||||
throw new Error('No symmetrically encrypted session key packet found.');
|
throw new Error('No symmetrically encrypted session key packet found.');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
} else {
|
||||||
var encryptionKeyIds = this.getEncryptionKeyIds();
|
var encryptionKeyIds = this.getEncryptionKeyIds();
|
||||||
if (!encryptionKeyIds.length) {
|
if (!encryptionKeyIds.length) {
|
||||||
// nothing to decrypt return unmodified message
|
// nothing to decrypt
|
||||||
return this;
|
return;
|
||||||
}
|
}
|
||||||
var privateKeyPacket = privateKey.getKeyPacket(encryptionKeyIds);
|
var privateKeyPacket = privateKey.getKeyPacket(encryptionKeyIds);
|
||||||
if (!privateKeyPacket.isDecrypted) {
|
if (!privateKeyPacket.isDecrypted) {
|
||||||
|
@ -199,11 +200,9 @@ Message.prototype.encrypt = function(keys, passwords) {
|
||||||
var symAlgo;
|
var symAlgo;
|
||||||
if (keys) {
|
if (keys) {
|
||||||
symAlgo = keyModule.getPreferredSymAlgo(keys);
|
symAlgo = keyModule.getPreferredSymAlgo(keys);
|
||||||
}
|
} else if (passwords) {
|
||||||
else if(passwords) {
|
|
||||||
symAlgo = config.encryption_cipher;
|
symAlgo = config.encryption_cipher;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new Error('No keys or passwords');
|
throw new Error('No keys or passwords');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user