diff --git a/ENCRYPTION_PLAN.md b/ENCRYPTION_PLAN.md index e5c4f05..4f19114 100644 --- a/ENCRYPTION_PLAN.md +++ b/ENCRYPTION_PLAN.md @@ -25,7 +25,7 @@ Decision: OpenPGP only for v1; S/MIME may follow later. - Android: wrap with a hardware-backed Android Keystore key; optional biometric unlock (Phase 4). - The passphrase is cached only in memory for a configurable time, then wiped (Phase 4). It is never written to disk. - Export as ASCII-armored files; a revocation certificate is generated when a key is created and can be exported after unlocking. -- Deleting or exporting a private key requires the passphrase. +- Deleting or exporting a private key requires the passphrase. Desktop users can change a key's passphrase by verifying the current one and entering the new one twice; the public key and revocation certificate are preserved. **Public keys** - Per-account contact keyring: address, fingerprint, trust level, source. diff --git a/TODO.md b/TODO.md index 4fcdd2c..08ad6de 100644 --- a/TODO.md +++ b/TODO.md @@ -70,4 +70,4 @@ - [x] Add desktop public key server support for finding and publishing OpenPGP keys: keys.openpgp.org (VKS), keys.mailvelope.com (HKP over HTTPS), and user-defined HTTPS HKP/VKS servers. Servers are disabled until selected; lookup checks all enabled servers, and publishing requires one explicitly selected destination. Discovered keys remain unverified until fingerprint verification. - [ ] Add the ability to attach files to outgoing mails. - [x] Fix security review findings: confirm key replacement in the main process, enforce the plaintext-send check in the main process, and handle the Linux safeStorage basic_text backend. See SECURITY_REVIEW.md. -- [ ] Add the ability to change the passphrase of an encryption key. +- [x] Add the ability to change the passphrase of an encryption key on desktop. diff --git a/desktop/main.cjs b/desktop/main.cjs index b903f92..f0b54bb 100644 --- a/desktop/main.cjs +++ b/desktop/main.cjs @@ -1319,6 +1319,12 @@ ipcMain.handle('pgp:export-private', async (event, fingerprint, passphrase) => { const id = pgpFingerprint(fingerprint); return saveKeyFile(event, `ep-mail-private-${id.slice(-16)}.asc`, await pgpKeys.exportPrivate(id, passphrase)); }); +ipcMain.handle('pgp:change-passphrase', async (_event, input) => { + const id = pgpFingerprint(input?.fingerprint); + const result = await pgpKeys.changePassphrase(id, input?.currentPassphrase, input?.newPassphrase); + pgpCache.clear(id); + return result; +}); ipcMain.handle('pgp:export-revocation', async (event, fingerprint, passphrase) => { const id = pgpFingerprint(fingerprint); return saveKeyFile(event, `ep-mail-revocation-${id.slice(-16)}.asc`, await pgpKeys.exportRevocation(id, passphrase)); diff --git a/desktop/pgp-keystore.cjs b/desktop/pgp-keystore.cjs index d748276..ce39dd1 100644 --- a/desktop/pgp-keystore.cjs +++ b/desktop/pgp-keystore.cjs @@ -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.'); diff --git a/desktop/preload.cjs b/desktop/preload.cjs index d51ddf6..522bc22 100644 --- a/desktop/preload.cjs +++ b/desktop/preload.cjs @@ -29,6 +29,7 @@ contextBridge.exposeInMainWorld('daybreakMail', { importKey: details => ipcRenderer.invoke('pgp:import', details), exportPublic: fingerprint => ipcRenderer.invoke('pgp:export-public', fingerprint), exportPrivate: (fingerprint, passphrase) => ipcRenderer.invoke('pgp:export-private', fingerprint, passphrase), + changePassphrase: details => ipcRenderer.invoke('pgp:change-passphrase', details), exportRevocation: (fingerprint, passphrase) => ipcRenderer.invoke('pgp:export-revocation', fingerprint, passphrase), remove: (fingerprint, passphrase) => ipcRenderer.invoke('pgp:delete', fingerprint, passphrase), decryptMessage: details => ipcRenderer.invoke('pgp:decrypt-message', details), diff --git a/pgp-ui.js b/pgp-ui.js index da93cff..443d464 100644 --- a/pgp-ui.js +++ b/pgp-ui.js @@ -7,6 +7,11 @@ function openEncryptionKeys() { root.innerHTML = `