Skip to content

Commit

Permalink
Fix and test dummy key conversion (#1172)
Browse files Browse the repository at this point in the history
Keys converted using makeDummy() were not serialised correctly as they were
treated as unencrypted keys.
  • Loading branch information
larabr authored Nov 10, 2020
1 parent 929b016 commit 08fc7b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/packet/secret_key.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,14 @@ SecretKey.prototype.makeDummy = function () {
throw new Error("Key is not decrypted");
}
this.clearPrivateParams();
this.keyMaterial = null;
this.isEncrypted = false;
this.s2k = new type_s2k();
this.s2k.algorithm = 0;
this.s2k.c = 0;
this.s2k.type = 'gnu-dummy';
this.s2k_usage = 254;
this.symmetric = 'aes256';
};

/**
Expand Down
18 changes: 18 additions & 0 deletions test/general/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -2817,6 +2817,24 @@ describe('Key', function() {
await expect(key.validate()).to.be.rejectedWith('Key is invalid');
});

it('makeDummy() - the converted key can be parsed', async function() {
const { key: key } = await openpgp.generateKey({ userIds: 'dummy <[email protected]>' });
key.primaryKey.makeDummy();
const parsedKeys = (await openpgp.key.readArmored(key.armor())).keys;
expect(parsedKeys).to.not.be.empty;
});

it('makeDummy() - the converted key can be encrypted and decrypted', async function() {
const { key: key } = await openpgp.generateKey({ userIds: 'dummy <[email protected]>' });
const passphrase = 'passphrase';
key.primaryKey.makeDummy();
expect(key.isDecrypted()).to.be.true;
await key.encrypt(passphrase);
expect(key.isDecrypted()).to.be.false;
await key.decrypt(passphrase);
expect(key.isDecrypted()).to.be.true;
});

it('makeDummy() - the converted key is valid but can no longer sign', async function() {
const { keys: [key] } = await openpgp.key.readArmored(priv_key_rsa);
await key.decrypt('hello world');
Expand Down

0 comments on commit 08fc7b3

Please sign in to comment.