From 1b8e662769ab2b3c6c45e480168ac7eb5dfef923 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 7 Jul 2014 11:58:41 +0200 Subject: [PATCH] Use same signatures structure openpgp.js for clearSignedSignatures as detached --- src/lib/openpgp/openpgp.js | 23 +++++++++++++++-------- test/unit/pgp-test.js | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/lib/openpgp/openpgp.js b/src/lib/openpgp/openpgp.js index f0bc872..df7bd9a 100644 --- a/src/lib/openpgp/openpgp.js +++ b/src/lib/openpgp/openpgp.js @@ -92,18 +92,25 @@ CleartextMessage.prototype.verify = function(keys) { var literalDataPacket = new packet.Literal(); // we assume that cleartext signature is generated based on UTF8 cleartext literalDataPacket.setText(this.text); - keys.forEach(function(key) { - for (var i = 0; i < signatureList.length; i++) { - var keyPacket = key.getKeyPacket([signatureList[i].issuerKeyId]); + for (var i = 0; i < signatureList.length; i++) { + var keyPacket = null; + for (var j = 0; j < keys.length; j++) { + keyPacket = keys[j].getKeyPacket([signatureList[i].issuerKeyId]); if (keyPacket) { - var verifiedSig = {}; - verifiedSig.keyid = signatureList[i].issuerKeyId; - verifiedSig.valid = signatureList[i].verify(keyPacket, literalDataPacket); - result.push(verifiedSig); break; } } - }); + + var verifiedSig = {}; + if (keyPacket) { + verifiedSig.keyid = signatureList[i].issuerKeyId; + verifiedSig.valid = signatureList[i].verify(keyPacket, literalDataPacket); + } else { + verifiedSig.keyid = signatureList[i].issuerKeyId; + verifiedSig.valid = null; + } + result.push(verifiedSig); + } return result; }; diff --git a/test/unit/pgp-test.js b/test/unit/pgp-test.js index 0fe19ec..b27244e 100644 --- a/test/unit/pgp-test.js +++ b/test/unit/pgp-test.js @@ -377,7 +377,7 @@ define(function(require) { done(); }); }); - it.skip('should be null for wrong public key', function(done) { + it('should be null for wrong public key', function(done) { pgp.verifyClearSignedMessage(clearsigned, wrongPubkey, function(err, signaturesValid) { expect(err).to.not.exist; expect(signaturesValid).to.be.null;