return signature object inside verification object

This commit is contained in:
Sanjana Rajan 2017-03-10 10:38:59 -08:00
parent da9e3c6264
commit 4ec07672a7
7 changed files with 46 additions and 5 deletions

View File

@ -136,6 +136,8 @@ CleartextMessage.prototype.verifyDetached = function(signature, keys) {
verifiedSig.keyid = signatureList[i].issuerKeyId;
verifiedSig.valid = null;
}
verifiedSig.signature = new sigModule.Signature([signatureList[i]]);
result.push(verifiedSig);
}
return result;

View File

@ -431,12 +431,15 @@ function createVerificationObjects(signatureList, literalDataList, keys) {
var verifiedSig = {};
if (keyPacket) {
//found a key packet that matches keyId of signature
verifiedSig.keyid = signatureList[i].issuerKeyId;
verifiedSig.valid = signatureList[i].verify(keyPacket, literalDataList[0]);
} else {
verifiedSig.keyid = signatureList[i].issuerKeyId;
verifiedSig.valid = null;
}
verifiedSig.signature = new sigModule.Signature([signatureList[i]]);
result.push(verifiedSig);
}
return result;

View File

@ -243,7 +243,7 @@ export function decrypt({ message, privateKey, publicKeys, sessionKey, password,
return message.decrypt(privateKey, sessionKey, password).then(message => {
const result = parseMessage(message, format);
if (publicKeys && result.data) { // verify only if publicKeys are specified
if (result.data) { // verify
if (signature) {
//detached signature
result.signatures = message.verifyDetached(signature, publicKeys);

View File

@ -67,9 +67,16 @@ export function clonePackets(options) {
if (options.signature && (options.signature instanceof signature.Signature)) {
options.signature = options.signature.packets;
}
if (options.signatures) {
options.signatures = options.signatures.map(sig => verificationObjectToClone(sig));
}
return options;
}
function verificationObjectToClone(verObject) {
verObject.signature = verObject.signature.packets;
return verObject;
}
//////////////////////////////
// //
@ -129,6 +136,7 @@ function packetlistCloneToCleartextMessage(clone) {
//verification objects
function packetlistCloneToSignatures(clone) {
clone.keyid = type_keyid.fromClone(clone.keyid);
clone.signature = new signature.Signature(clone.signature);
return clone;
}

View File

@ -33,9 +33,7 @@ import armor from './encoding/armor.js';
/**
* @class
* @classdesc Class that represents an OpenPGP signature.
* Can be an encrypted message, signed message, compressed message or literal message
* @param {module:packet/packetlist} packetlist The packets that form this message
* See {@link http://tools.ietf.org/html/rfc4880#section-11.3}
* @param {module:packet/packetlist} packetlist The signature packets
*/
export function Signature(packetlist) {

View File

@ -637,7 +637,8 @@ describe('OpenPGP.js public api tests', function() {
return openpgp.decrypt(decOpt);
}).then(function(decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures).to.not.exist;
expect(decrypted.signatures).to.exist;
expect(decrypted.signatures.length).to.equal(0);
done();
});
});
@ -659,6 +660,7 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.true;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -682,6 +684,7 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.true;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -703,6 +706,7 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.null;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -726,6 +730,7 @@ describe('OpenPGP.js public api tests', function() {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures[0].valid).to.be.null;
expect(decrypted.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -746,6 +751,7 @@ describe('OpenPGP.js public api tests', function() {
expect(verified.data).to.equal(plaintext);
expect(verified.signatures[0].valid).to.be.true;
expect(verified.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -767,6 +773,7 @@ describe('OpenPGP.js public api tests', function() {
expect(verified.data).to.equal(plaintext);
expect(verified.signatures[0].valid).to.be.true;
expect(verified.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -786,6 +793,7 @@ describe('OpenPGP.js public api tests', function() {
expect(verified.data).to.equal(plaintext);
expect(verified.signatures[0].valid).to.be.null;
expect(verified.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -807,6 +815,7 @@ describe('OpenPGP.js public api tests', function() {
expect(verified.data).to.equal(plaintext);
expect(verified.signatures[0].valid).to.be.null;
expect(verified.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -827,6 +836,7 @@ describe('OpenPGP.js public api tests', function() {
expect(verified.data).to.equal(plaintext);
expect(verified.signatures[0].valid).to.be.true;
expect(verified.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -849,6 +859,7 @@ describe('OpenPGP.js public api tests', function() {
expect(verified.data).to.equal(plaintext);
expect(verified.signatures[0].valid).to.be.true;
expect(verified.signatures[0].keyid.toHex()).to.equal(privateKey.keys[0].getSigningKeyPacket().getKeyId().toHex());
expect(verified.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -872,6 +883,9 @@ describe('OpenPGP.js public api tests', function() {
}).then(function(encrypted) {
expect(encrypted.data).to.exist;
expect(encrypted.data).to.equal(plaintext);
expect(encrypted.signatures[0].valid).to.be.true;
expect(encrypted.signatures[0].keyid.toHex()).to.equal(privKeyDE.getSigningKeyPacket().getKeyId().toHex());
expect(encrypted.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -938,6 +952,7 @@ describe('OpenPGP.js public api tests', function() {
openpgp.decrypt({ privateKey:privKey, message:message }).then(function(decrypted) {
expect(decrypted.data).to.equal('hello 3des\n');
expect(decrypted.signatures.length).to.equal(0);
done();
});
});
@ -957,6 +972,7 @@ describe('OpenPGP.js public api tests', function() {
return openpgp.decrypt(decOpt);
}).then(function(decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures.length).to.equal(0);
done();
});
});
@ -974,6 +990,7 @@ describe('OpenPGP.js public api tests', function() {
return openpgp.decrypt(decOpt);
}).then(function(decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures.length).to.equal(0);
done();
});
});
@ -992,6 +1009,7 @@ describe('OpenPGP.js public api tests', function() {
return openpgp.decrypt(decOpt);
}).then(function(decrypted) {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures.length).to.equal(0);
done();
});
});
@ -1015,6 +1033,7 @@ describe('OpenPGP.js public api tests', function() {
expect(encOpt.data.byteLength).to.equal(0); // transfered buffer should be empty
}
expect(decrypted.data).to.deep.equal(new Uint8Array([0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01]));
expect(decrypted.signatures.length).to.equal(0);
done();
});
});

View File

@ -265,6 +265,7 @@ describe("Signature", function() {
openpgp.decrypt({ privateKey: priv_key, publicKeys:[pub_key], message:msg }).then(function(decrypted) {
expect(decrypted.data).to.exist;
expect(decrypted.signatures[0].valid).to.be.true;
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -309,6 +310,7 @@ describe("Signature", function() {
expect(verified).to.exist;
expect(verified).to.have.length(1);
expect(verified[0].valid).to.be.true;
expect(verified[0].signature.packets.length).to.equal(1);
done();
});
});
@ -333,6 +335,7 @@ describe("Signature", function() {
expect(verified).to.exist;
expect(verified).to.have.length(1);
expect(verified[0].valid).to.be.true;
expect(verified[0].signature.packets.length).to.equal(1);
done();
});
@ -356,6 +359,7 @@ describe("Signature", function() {
expect(verified).to.exist;
expect(verified).to.have.length(1);
expect(verified[0].valid).to.be.true;
expect(verified[0].signature.packets.length).to.equal(1);
done();
});
@ -390,6 +394,7 @@ describe("Signature", function() {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures).to.have.length(1);
expect(decrypted.signatures[0].valid).to.be.true;
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
done();
});
});
@ -426,6 +431,7 @@ describe("Signature", function() {
expect(decrypted.data).to.equal(plaintext);
expect(decrypted.signatures).to.have.length(1);
expect(decrypted.signatures[0].valid).to.be.true;
expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
done();
});
@ -469,6 +475,8 @@ describe("Signature", function() {
expect(verifiedSig).to.have.length(2);
expect(verifiedSig[0].valid).to.be.true;
expect(verifiedSig[1].valid).to.be.true;
expect(verifiedSig[0].signature.packets.length).to.equal(1);
expect(verifiedSig[1].signature.packets.length).to.equal(1);
done();
});
@ -513,6 +521,8 @@ describe("Signature", function() {
expect(cleartextSig.signatures).to.have.length(2);
expect(cleartextSig.signatures[0].valid).to.be.true;
expect(cleartextSig.signatures[1].valid).to.be.true;
expect(cleartextSig.signatures[0].signature.packets.length).to.equal(1);
expect(cleartextSig.signatures[1].signature.packets.length).to.equal(1);
done();
});
});
@ -533,6 +543,7 @@ describe("Signature", function() {
expect(cleartextSig.data).to.equal(plaintext.replace(/\r/g,''));
expect(cleartextSig.signatures).to.have.length(1);
expect(cleartextSig.signatures[0].valid).to.be.true;
expect(cleartextSig.signatures[0].signature.packets.length).to.equal(1);
done();
});