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:
@@ -7,6 +7,11 @@ function openEncryptionKeys() {
|
||||
root.innerHTML = `<div class="modal-overlay"><div class="compose-modal attachments-modal"><div class="modal-head"><span>Encryption keys</span><button class="modal-close" aria-label="Close">×</button></div><div class="compose-fields">
|
||||
<p class="account-note">OpenPGP keys are protected by a passphrase and stored encrypted by your operating system. Back up your private key and revocation certificate: without them, encrypted mail cannot be recovered. Contact keys below are used to encrypt mail to your correspondents and to check signatures.</p>
|
||||
<div id="pgp-key-list" class="attachment-list">Loading keys…</div>
|
||||
<h3 class="pgp-heading">Change a key passphrase</h3>
|
||||
<label class="compose-line"><span>Current passphrase</span><input id="pgp-change-current-passphrase" type="password" autocomplete="current-password"></label>
|
||||
<label class="compose-line"><span>New passphrase</span><input id="pgp-new-passphrase" type="password" autocomplete="new-password" placeholder="At least 8 characters"></label>
|
||||
<label class="compose-line"><span>Confirm new passphrase</span><input id="pgp-confirm-passphrase" type="password" autocomplete="new-password" placeholder="Enter the new passphrase again"></label>
|
||||
<p class="account-note">Select Change passphrase on a key below. Its public key and revocation certificate will not change.</p>
|
||||
<h3 class="pgp-heading">Contact public keys</h3>
|
||||
<div id="pgp-contact-list" class="attachment-list">Loading contacts…</div>
|
||||
<div class="pgp-actions"><button class="discard" id="pgp-add-contact">Import public key…</button></div>
|
||||
@@ -77,6 +82,44 @@ function openEncryptionKeys() {
|
||||
['Export public', () => window.daybreakMail.pgp.exportPublic(key.fingerprint), false],
|
||||
['Export private', () => window.daybreakMail.pgp.exportPrivate(key.fingerprint, needPassphrase()), true]
|
||||
];
|
||||
const changePassphrase = document.createElement('button');
|
||||
changePassphrase.className = 'discard';
|
||||
changePassphrase.textContent = 'Change passphrase…';
|
||||
changePassphrase.onclick = async () => {
|
||||
const currentPassphrase = $('#pgp-change-current-passphrase').value;
|
||||
if (!currentPassphrase) {
|
||||
status('Enter the current passphrase for this key.');
|
||||
$('#pgp-change-current-passphrase').focus();
|
||||
return;
|
||||
}
|
||||
const newPassphrase = $('#pgp-new-passphrase').value;
|
||||
if (newPassphrase.length < 8) {
|
||||
status('Use a new passphrase of at least 8 characters.');
|
||||
$('#pgp-new-passphrase').focus();
|
||||
return;
|
||||
}
|
||||
if (newPassphrase !== $('#pgp-confirm-passphrase').value) {
|
||||
status('The new passphrases do not match.');
|
||||
$('#pgp-confirm-passphrase').focus();
|
||||
return;
|
||||
}
|
||||
changePassphrase.disabled = true;
|
||||
try {
|
||||
await window.daybreakMail.pgp.changePassphrase({
|
||||
fingerprint: key.fingerprint,
|
||||
currentPassphrase,
|
||||
newPassphrase
|
||||
});
|
||||
$('#pgp-change-current-passphrase').value = '';
|
||||
status(`Passphrase changed for ${key.email || key.fingerprint}.`);
|
||||
} catch (error) { status(error.message || 'Could not change the key passphrase.'); }
|
||||
finally {
|
||||
$('#pgp-new-passphrase').value = '';
|
||||
$('#pgp-confirm-passphrase').value = '';
|
||||
changePassphrase.disabled = false;
|
||||
}
|
||||
};
|
||||
row.append(changePassphrase);
|
||||
if (key.hasRevocationCertificate) actions.push(['Revocation cert.', () => window.daybreakMail.pgp.exportRevocation(key.fingerprint, needPassphrase()), true]);
|
||||
actions.push(['Delete', async () => {
|
||||
if (!confirm('Delete this key? Encrypted mail that needs it can no longer be read unless you have a backup.')) return { canceled: true };
|
||||
|
||||
Reference in New Issue
Block a user