Phase 02 OpenPGP implementation
This commit is contained in:
@@ -6,12 +6,36 @@ const selectAllPgpKeyUi = pgpKeyMailUi.selectAll;
|
||||
const escapePgpKeyUi = pgpKeyMailUi.escapeHtml;
|
||||
const toastPgpKeyUi = pgpKeyMailUi.toast;
|
||||
function pgpAvailable() { return Boolean(window.daybreakMail?.pgp); }
|
||||
async function saveAndroidPgpExport(label, value) {
|
||||
if (window.daybreakMail?.pgp?.platform !== 'android' || typeof value !== 'string') return value;
|
||||
const warning = /private|revocation/i.test(label) ? ' This contains secret key material; keep it private.' : '';
|
||||
if (!confirm(`Copy this ${label.toLowerCase()} to the clipboard?${warning}`)) return { canceled: true };
|
||||
if (navigator.clipboard?.writeText) await navigator.clipboard.writeText(value);
|
||||
else if (prompt(`Copy this ${label.toLowerCase()}:`, value) === null) return { canceled: true };
|
||||
return { saved: true };
|
||||
}
|
||||
|
||||
function openEncryptionKeys() {
|
||||
const root = selectPgpKeyUi('#modal-root');
|
||||
const root = selectPgpKeyUi('#modal-root');
|
||||
const account = window.epMailFeatures.mail.connectedAccount || {};
|
||||
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>
|
||||
const androidPgp = window.daybreakMail?.pgp?.platform === 'android';
|
||||
const serverSettings = androidPgp
|
||||
? '<h3 class="pgp-heading">Public key servers</h3><p class="account-note">Key-server lookup and publication are disabled in Android testing. Import a public key directly and compare its fingerprint with the owner.</p><div hidden><div id="pgp-server-list"></div><input id="pgp-search-email"><button id="pgp-find-key"></button><div id="pgp-found-keys"></div><select id="pgp-publish-server"></select><input id="pgp-server-name"><input id="pgp-server-url"><select id="pgp-server-protocol"></select><button id="pgp-add-server"></button></div>'
|
||||
: `<h3 class="pgp-heading">Public key servers</h3>
|
||||
<p class="account-note">Servers are disabled by default. Enable the servers you want to use; searching checks every enabled server, which can learn which email address you searched for. Discovered keys remain unverified until you check their fingerprints independently.</p>
|
||||
<div id="pgp-server-list" class="attachment-list">Loading key servers…</div>
|
||||
<label class="compose-line"><span>Email address</span><input id="pgp-search-email" type="email" value="${escapePgpKeyUi(account.email || '')}"></label>
|
||||
<div class="pgp-actions"><button class="discard" id="pgp-find-key">Search all enabled servers</button></div>
|
||||
<div id="pgp-found-keys" class="attachment-list"></div>
|
||||
<label class="compose-line"><span>Publish to one server</span><select id="pgp-publish-server"></select></label>
|
||||
<p class="account-note">Publishing targets only the selected enabled server. ep-mail names the destination and asks for native confirmation before uploading.</p>
|
||||
<h4 class="pgp-heading">Add a custom HTTPS server</h4>
|
||||
<label class="compose-line"><span>Name</span><input id="pgp-server-name" maxlength="60" placeholder="My key server"></label>
|
||||
<label class="compose-line"><span>HTTPS base URL</span><input id="pgp-server-url" type="url" placeholder="https://keys.example.org"></label>
|
||||
<label class="compose-line"><span>Protocol</span><select id="pgp-server-protocol"><option value="hkp">HKP</option><option value="vks">VKS</option></select></label>
|
||||
<div class="pgp-actions"><button class="discard" id="pgp-add-server">Add custom server…</button></div>`;
|
||||
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">${androidPgp ? 'EXPERIMENTAL ANDROID TESTING — not independently security reviewed. Private keys remain passphrase-protected inside the encrypted Android vault. Back up your private key and revocation certificate: without them, encrypted mail cannot be recovered.' : '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>
|
||||
@@ -21,19 +45,7 @@ function openEncryptionKeys() {
|
||||
<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>
|
||||
<h3 class="pgp-heading">Public key servers</h3>
|
||||
<p class="account-note">Servers are disabled by default. Enable the servers you want to use; searching checks every enabled server, which can learn which email address you searched for. Discovered keys remain unverified until you check their fingerprints independently.</p>
|
||||
<div id="pgp-server-list" class="attachment-list">Loading key servers…</div>
|
||||
<label class="compose-line"><span>Email address</span><input id="pgp-search-email" type="email" value="${escapePgpKeyUi(account.email || '')}"></label>
|
||||
<div class="pgp-actions"><button class="discard" id="pgp-find-key">Search all enabled servers</button></div>
|
||||
<div id="pgp-found-keys" class="attachment-list"></div>
|
||||
<label class="compose-line"><span>Publish to one server</span><select id="pgp-publish-server"></select></label>
|
||||
<p class="account-note">Publishing targets only the selected enabled server. ep-mail names the destination and asks for native confirmation before uploading.</p>
|
||||
<h4 class="pgp-heading">Add a custom HTTPS server</h4>
|
||||
<label class="compose-line"><span>Name</span><input id="pgp-server-name" maxlength="60" placeholder="My key server"></label>
|
||||
<label class="compose-line"><span>HTTPS base URL</span><input id="pgp-server-url" type="url" placeholder="https://keys.example.org"></label>
|
||||
<label class="compose-line"><span>Protocol</span><select id="pgp-server-protocol"><option value="hkp">HKP</option><option value="vks">VKS</option></select></label>
|
||||
<div class="pgp-actions"><button class="discard" id="pgp-add-server">Add custom server…</button></div>
|
||||
${serverSettings}
|
||||
<h3 class="pgp-heading">Passphrase memory</h3>
|
||||
<label class="compose-line"><span>Minutes</span><input id="pgp-cache-minutes" type="number" min="0" max="1440" step="1"></label>
|
||||
<div class="pgp-actions"><button class="discard" id="pgp-save-cache">Save</button><button class="discard" id="pgp-forget">Forget passphrases now</button></div>
|
||||
@@ -140,7 +152,7 @@ function openEncryptionKeys() {
|
||||
button.onclick = async () => {
|
||||
if (secret && !passphraseField().value) { needPassphrase(); return; }
|
||||
try {
|
||||
const result = await run();
|
||||
const result = await saveAndroidPgpExport(label, await run());
|
||||
status(result?.saved ? 'File saved.' : result?.deleted ? 'Key deleted.' : '');
|
||||
} catch (error) { status(error.message || 'That action failed.'); }
|
||||
};
|
||||
@@ -188,7 +200,7 @@ function openEncryptionKeys() {
|
||||
if (!passphrase) return;
|
||||
try {
|
||||
const result = await window.daybreakMail.pgp.importKey({ passphrase, accountId: account.id || null });
|
||||
status(result.canceled ? '' : 'Key imported.');
|
||||
status(result.canceled ? '' : result.keyChangedFrom?.length ? 'Key imported. You already have a different key for this address; compare fingerprints before trusting either key.' : 'Key imported.');
|
||||
await render();
|
||||
} catch (error) { status(error.message || 'Could not import the key.'); }
|
||||
};
|
||||
@@ -241,7 +253,7 @@ function openEncryptionKeys() {
|
||||
button.className = 'discard';
|
||||
button.textContent = label;
|
||||
button.onclick = async () => {
|
||||
try { const result = await run(); status(result?.saved ? 'File saved.' : result?.deleted ? 'Contact key removed.' : ''); }
|
||||
try { const result = await saveAndroidPgpExport(label, await run()); status(result?.saved ? 'Copied to clipboard.' : result?.deleted ? 'Contact key removed.' : ''); }
|
||||
catch (error) { status(error.message || 'That action failed.'); }
|
||||
};
|
||||
row.append(button);
|
||||
@@ -403,7 +415,7 @@ function openEncryptionKeys() {
|
||||
catch (error) { status(error.message || 'Could not save the setting.'); }
|
||||
};
|
||||
selectPgpKeyUi('#pgp-forget').onclick = async () => { await window.daybreakMail.pgp.forgetPassphrases(); status('Remembered passphrases were cleared.'); };
|
||||
void renderKeyServers();
|
||||
if (!androidPgp) void renderKeyServers();
|
||||
void renderContacts();
|
||||
void render();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user