Add OpenPGP key passphrase changes
Allow desktop users to re-encrypt an existing key after verifying its current passphrase. Preserve key identity and revocation data, clear its cached passphrase, and document the feature. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -305,6 +305,24 @@ function createKeyStore(storage) {
|
||||
return entry.privateKey;
|
||||
},
|
||||
|
||||
async changePassphrase(fingerprint, currentPassphrase, newPassphrase) {
|
||||
requirePassphrase(newPassphrase);
|
||||
const data = await read();
|
||||
const keyIndex = data.keys.findIndex(key => key.fingerprint === fingerprint);
|
||||
if (keyIndex < 0) throw new Error('That key was not found.');
|
||||
const entry = data.keys[keyIndex];
|
||||
const privateKey = await unlock(entry.privateKey, currentPassphrase);
|
||||
const protectedKey = await openpgp.encryptKey({ privateKey, passphrase: newPassphrase });
|
||||
const updated = {
|
||||
...data,
|
||||
keys: data.keys.map((key, index) => index === keyIndex
|
||||
? { ...key, privateKey: protectedKey.armor() }
|
||||
: key)
|
||||
};
|
||||
await storage.save(updated);
|
||||
return { changed: true };
|
||||
},
|
||||
|
||||
async exportRevocation(fingerprint, passphrase) {
|
||||
const entry = (await read()).keys.find(key => key.fingerprint === fingerprint);
|
||||
if (!entry) throw new Error('That key was not found.');
|
||||
|
||||
Reference in New Issue
Block a user