Add test of verification of a clearsign message generated by gpg

This commit is contained in:
Robert Nelson 2013-12-04 19:33:44 -08:00
parent e9b8b0efb9
commit f8d8d471a9
2 changed files with 175 additions and 109 deletions

View File

@ -156,5 +156,58 @@ define(function(require) {
});
describe('Clearsign from gpg verification', function() {
var clearsign_msg = '-----BEGIN PGP SIGNED MESSAGE-----\r\n' +
'Hash: SHA1\r\n' +
'\r\n' +
'This is a test message.\r\n' +
'\r\n' +
'This paragraph is separated form the next by a line of dashes.\r\n' +
'\r\n' +
'- --------------------------------------------------------------------------\r\n' +
'\r\n' +
'The next paragraph has a number of blank lines between this one and it.\r\n' +
'\r\n' +
'\r\n' +
'\r\n' +
'\r\n' +
'\r\n' +
'\r\n' +
'This is the last paragraph.\r\n' +
'\r\n' +
'- --\r\n' +
'\r\n' +
'Joe Test\r\n' +
'-----BEGIN PGP SIGNATURE-----\r\n' +
'Version: GnuPG v1.4.15 (GNU/Linux)\r\n' +
'\r\n' +
'iFwEAQECAAYFAlKf5LcACgkQ9vYOm0LN/0ybVwH8CItdDh4kWKVcyUx3Q3hWZnWd\r\n' +
'zP9CUbIa9uToIPABjV3GOTDM3ZgiP0/SE6Al5vG8hlx+/u2piVojoLovk/4LnA==\r\n' +
'=i6ew\r\n' +
'-----END PGP SIGNATURE-----\r\n';
beforeEach(function(done) {
pgp.importKeys({
passphrase: passphrase,
privateKeyArmored: privkey,
publicKeyArmored: pubkey
}, function(err) {
expect(err).to.not.exist;
done();
});
});
describe('Verify', function() {
it('should work', function(done) {
pgp.verify(clearsign_msg, pubkey, function(err, pt) {
expect(err).to.not.exist;
expect(pt).to.be.true;
done();
});
});
});
});
});
});

View File

@ -174,5 +174,18 @@ define(function(require) {
}
};
/**
* Verify a clearsign message for a single sender
*/
PGP.prototype.verify = function(message, senderKey, callback) {
var publicKey = openpgp.read_publicKey(senderKey)[0];
var pubKeys = [ { armored: senderKey, obj: publicKey, keyId: publicKey.getKeyId() } ];
var msg = openpgp.read_message(message)[0];
var verified = msg.verifySignature(pubKeys);
callback(null, verified);
};
return PGP;
});