Merge pull request #529 from openpgpjs/init_publicKeys
Initialize public key array during decryption
This commit is contained in:
commit
a4c75772e9
|
@ -244,6 +244,9 @@ export function decrypt({ message, privateKey, publicKeys, sessionKey, password,
|
||||||
|
|
||||||
const result = parseMessage(message, format);
|
const result = parseMessage(message, format);
|
||||||
if (result.data) { // verify
|
if (result.data) { // verify
|
||||||
|
if (!publicKeys) {
|
||||||
|
publicKeys = [];
|
||||||
|
}
|
||||||
if (signature) {
|
if (signature) {
|
||||||
//detached signature
|
//detached signature
|
||||||
result.signatures = message.verifyDetached(signature, publicKeys);
|
result.signatures = message.verifyDetached(signature, publicKeys);
|
||||||
|
|
|
@ -711,6 +711,27 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should successfully decrypt signed message without public keys to verify', function(done) {
|
||||||
|
var encOpt = {
|
||||||
|
data: plaintext,
|
||||||
|
publicKeys: publicKey.keys,
|
||||||
|
privateKeys: privateKey.keys
|
||||||
|
};
|
||||||
|
var decOpt = {
|
||||||
|
privateKey: privateKey.keys[0],
|
||||||
|
};
|
||||||
|
openpgp.encrypt(encOpt).then(function(encrypted) {
|
||||||
|
decOpt.message = openpgp.message.readArmored(encrypted.data);
|
||||||
|
return openpgp.decrypt(decOpt);
|
||||||
|
}).then(function(decrypted) {
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should fail to verify decrypted data with wrong public pgp key with detached signatures', function(done) {
|
it('should fail to verify decrypted data with wrong public pgp key with detached signatures', function(done) {
|
||||||
var encOpt = {
|
var encOpt = {
|
||||||
data: plaintext,
|
data: plaintext,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user