diff --git a/src/message.js b/src/message.js index 387e0b59..ee5248b2 100644 --- a/src/message.js +++ b/src/message.js @@ -32,7 +32,7 @@ import enums from './enums.js'; import armor from './encoding/armor.js'; import config from './config'; import crypto from './crypto'; -import signature from './signature.js'; +import * as sigModule from './signature.js'; import * as keyModule from './key.js'; /** @@ -376,7 +376,7 @@ Message.prototype.signDetached = function(privateKeys) { packetlist.push(signaturePacket); } - return new signature.Signature(packetlist); + return new sigModule.Signature(packetlist); }; diff --git a/test/general/signature.js b/test/general/signature.js index 15c72784..6f58375a 100644 --- a/test/general/signature.js +++ b/test/general/signature.js @@ -595,7 +595,7 @@ describe("Signature", function() { expect(pubKey.users[0].selfCertifications).to.eql(pubKey2.users[0].selfCertifications); }); - it('Verify a detached signature', function() { + it('Verify a detached signature using readSignedContent', function() { var detachedSig = ['-----BEGIN PGP SIGNATURE-----', 'Version: GnuPG v1.4.13 (Darwin)', 'Comment: GPGTools - https://gpgtools.org', @@ -641,6 +641,30 @@ describe("Signature", function() { expect(result[0].valid).to.be.true; }); + it('Detached signature signing and verification cleartext', function () { + var msg = openpgp.message.fromText('hello'); + var pubKey2 = openpgp.key.readArmored(pub_key_arm2).keys[0]; + var privKey2 = openpgp.key.readArmored(priv_key_arm2).keys[0]; + privKey2.decrypt('hello world'); + + var detachedSig = msg.signDetached([privKey2]); + + var result = msg.verifyDetached(detachedSig, [pubKey2]); + expect(result[0].valid).to.be.true; + }); + + it('Detached signature signing and verification encrypted', function () { + var msg = openpgp.message.fromText('hello'); + var pubKey2 = openpgp.key.readArmored(pub_key_arm2).keys[0]; + var privKey2 = openpgp.key.readArmored(priv_key_arm2).keys[0]; + privKey2.decrypt('hello world'); + msg.encrypt({keys: [pubKey2] }); + + var detachedSig = msg.signDetached([privKey2]); + var result = msg.verifyDetached(detachedSig, [pubKey2]); + expect(result[0].valid).to.be.true; + }); + it('Sign message with key without password', function(done) { var opt = {numBits: 512, userIds: { name:'test', email:'a@b.com' }, passphrase: null}; if (openpgp.util.getWebCryptoAll()) { opt.numBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys