Fix and test dummy key conversion (#1172)
Keys converted using makeDummy() were not serialised correctly as they were treated as unencrypted keys.
This commit is contained in:
parent
929b016948
commit
08fc7b32ca
|
@ -280,11 +280,14 @@ SecretKey.prototype.makeDummy = function () {
|
||||||
throw new Error("Key is not decrypted");
|
throw new Error("Key is not decrypted");
|
||||||
}
|
}
|
||||||
this.clearPrivateParams();
|
this.clearPrivateParams();
|
||||||
|
this.keyMaterial = null;
|
||||||
this.isEncrypted = false;
|
this.isEncrypted = false;
|
||||||
this.s2k = new type_s2k();
|
this.s2k = new type_s2k();
|
||||||
this.s2k.algorithm = 0;
|
this.s2k.algorithm = 0;
|
||||||
this.s2k.c = 0;
|
this.s2k.c = 0;
|
||||||
this.s2k.type = 'gnu-dummy';
|
this.s2k.type = 'gnu-dummy';
|
||||||
|
this.s2k_usage = 254;
|
||||||
|
this.symmetric = 'aes256';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2817,6 +2817,24 @@ describe('Key', function() {
|
||||||
await expect(key.validate()).to.be.rejectedWith('Key is invalid');
|
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 <dummy@alice.com>' });
|
||||||
|
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 <dummy@alice.com>' });
|
||||||
|
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() {
|
it('makeDummy() - the converted key is valid but can no longer sign', async function() {
|
||||||
const { keys: [key] } = await openpgp.key.readArmored(priv_key_rsa);
|
const { keys: [key] } = await openpgp.key.readArmored(priv_key_rsa);
|
||||||
await key.decrypt('hello world');
|
await key.decrypt('hello world');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user