Enable OpenPGP key servers on Android, add keys.eternityproject.fi, allow removing built-in servers
- Android: key-server lookup, publish, add/remove/enable via native HTTP - Built-in servers can be removed; keys.eternityproject.fi (VKS) added as a default - Fix Settings additions (Encryption keys, shortcuts) missing on Android due to async preferences - Fix compose footer so Send is visible on small screens - Bump version to 0.5.22 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+70
-8
@@ -1,4 +1,7 @@
|
||||
import * as openpgp from 'openpgp';
|
||||
import keyServers from '../desktop/pgp-keyservers.cjs';
|
||||
|
||||
const { BUILTIN_SERVER_IDS, MAX_CUSTOM_SERVERS, createKeyServerService, listServers, normalizeCustomServer } = keyServers;
|
||||
|
||||
const MAX_KEY_LENGTH = 200000;
|
||||
const MAX_MESSAGE_BYTES = 25 * 1024 * 1024;
|
||||
@@ -255,8 +258,19 @@ async function signatureStatuses(signatures, verification, sender) {
|
||||
return results;
|
||||
}
|
||||
|
||||
export function createAndroidPgp({ EpMail, getAccount, confirm = globalThis.confirm }) {
|
||||
export function createAndroidPgp({ EpMail, getAccount, confirm = globalThis.confirm, fetchImpl }) {
|
||||
const keyServerService = createKeyServerService({ fetchImpl });
|
||||
let storePromise;
|
||||
function serverSettings(data) {
|
||||
const settings = data.settings || {};
|
||||
const ids = value => Array.isArray(value) ? [...new Set(value.filter(id => typeof id === 'string'))] : [];
|
||||
return { ...settings, customKeyServers: Array.isArray(settings.customKeyServers) ? settings.customKeyServers : [],
|
||||
enabledKeyServers: ids(settings.enabledKeyServers), removedBuiltinKeyServers: ids(settings.removedBuiltinKeyServers) };
|
||||
}
|
||||
function currentServers(data) {
|
||||
const settings = serverSettings(data);
|
||||
return listServers(settings.customKeyServers, settings.enabledKeyServers, settings.removedBuiltinKeyServers);
|
||||
}
|
||||
const passphrases = new Map();
|
||||
let cacheMinutes = 10;
|
||||
|
||||
@@ -310,7 +324,7 @@ export function createAndroidPgp({ EpMail, getAccount, confirm = globalThis.conf
|
||||
}
|
||||
const user = await key.getPrimaryUser();
|
||||
data.contacts.push({ fingerprint, name: user.user.userID?.name || '', emails, trust: 'unknown',
|
||||
source: ['import', 'message', 'paste'].includes(source) ? source : 'import', addedAt: Date.now(), publicKey: key.armor() });
|
||||
source: ['import', 'message', 'paste', 'keyserver'].includes(source) ? source : 'import', addedAt: Date.now(), publicKey: key.armor() });
|
||||
await persist(data);
|
||||
return { contact: { fingerprint, name: user.user.userID?.name || '', emails, trust: 'unknown', source, addedAt: Date.now() }, keyChangedFrom };
|
||||
}
|
||||
@@ -607,12 +621,60 @@ export function createAndroidPgp({ EpMail, getAccount, confirm = globalThis.conf
|
||||
return { cacheMinutes };
|
||||
},
|
||||
async forgetPassphrases() { clear(); return { cleared: true }; },
|
||||
async keyServers() { return []; },
|
||||
async findKey() { throw new Error('Key-server lookup is not included in Android testing. Import a public key directly.'); },
|
||||
async addKeyServer() { throw new Error('Key-server support is not included in Android testing.'); },
|
||||
async removeKeyServer() { throw new Error('Key-server support is not included in Android testing.'); },
|
||||
async setKeyServerEnabled() { throw new Error('Key-server support is not included in Android testing.'); },
|
||||
async publishKey() { throw new Error('Key-server support is not included in Android testing.'); },
|
||||
async keyServers() { return currentServers(await store()); },
|
||||
async findKey({ email } = {}) { return keyServerService.lookupEnabled(currentServers(await store()), email); },
|
||||
async addKeyServer(input) {
|
||||
const candidate = normalizeCustomServer(input);
|
||||
const data = await store();
|
||||
const settings = serverSettings(data);
|
||||
const custom = settings.customKeyServers.map(normalizeCustomServer);
|
||||
if (custom.length >= MAX_CUSTOM_SERVERS) throw new Error(`You can configure up to ${MAX_CUSTOM_SERVERS} custom key servers.`);
|
||||
if (currentServers(data).some(server => server.url === candidate.url && server.protocol === candidate.protocol)) throw new Error('That key server is already configured.');
|
||||
const host = new URL(candidate.url).host;
|
||||
if (!confirm(`Allow ep-mail to contact ${host} for OpenPGP keys?\n\nProtocol: ${candidate.protocol.toUpperCase()}\nThe server may learn which email addresses you search for. Only add a server you trust.`)) return { canceled: true };
|
||||
candidate.id = crypto.randomUUID();
|
||||
data.settings = { ...serverSettings(data), customKeyServers: [...custom, candidate] };
|
||||
await persist(data);
|
||||
return { server: candidate };
|
||||
},
|
||||
async removeKeyServer(serverId) {
|
||||
const id = String(serverId || '');
|
||||
const data = await store();
|
||||
const settings = serverSettings(data);
|
||||
const custom = settings.customKeyServers.filter(server => server.id !== id);
|
||||
const removesBuiltin = BUILTIN_SERVER_IDS.includes(id) && !settings.removedBuiltinKeyServers.includes(id);
|
||||
if (custom.length === settings.customKeyServers.length && !removesBuiltin) throw new Error('That key server was not found.');
|
||||
data.settings = { ...settings, customKeyServers: custom,
|
||||
enabledKeyServers: settings.enabledKeyServers.filter(enabledId => enabledId !== id),
|
||||
removedBuiltinKeyServers: removesBuiltin ? [...settings.removedBuiltinKeyServers, id] : settings.removedBuiltinKeyServers };
|
||||
await persist(data);
|
||||
return { removed: true };
|
||||
},
|
||||
async setKeyServerEnabled(serverId, enabled) {
|
||||
if (typeof enabled !== 'boolean') throw new Error('Choose whether to enable or disable this key server.');
|
||||
const id = String(serverId || '');
|
||||
const data = await store();
|
||||
if (!currentServers(data).some(server => server.id === id)) throw new Error('That key server was not found.');
|
||||
const settings = serverSettings(data);
|
||||
const next = new Set(settings.enabledKeyServers);
|
||||
if (enabled) next.add(id); else next.delete(id);
|
||||
data.settings = { ...settings, enabledKeyServers: [...next] };
|
||||
await persist(data);
|
||||
return { serverId: id, enabled };
|
||||
},
|
||||
async publishKey({ fingerprint, serverId } = {}) {
|
||||
const data = await store();
|
||||
const server = currentServers(data).find(item => item.id === String(serverId || ''));
|
||||
if (!server) throw new Error('Choose a configured key server.');
|
||||
if (!server.enabled) throw new Error('Enable the selected key server before publishing to it.');
|
||||
const entry = data.keys.find(item => item.fingerprint === fingerprint);
|
||||
if (!entry) throw new Error('That key was not found.');
|
||||
if (!entry.email) throw new Error('This key has no email address to publish.');
|
||||
const publicKey = await openpgp.readKey({ armoredKey: entry.publicKey });
|
||||
if (!emailsOf(publicKey).includes(String(entry.email).toLowerCase())) throw new Error('The selected key no longer matches its stored email address.');
|
||||
if (!confirm(`Publish the public key for ${entry.email} to ${server.name}?\n\nFingerprint:\n${fingerprint.match(/.{1,4}/g).join(' ')}\n\nOnly the public key will be sent. This exposes the email address in the key to the server, which may retain it. The server may send a verification email before the key becomes searchable.`)) return { canceled: true };
|
||||
return keyServerService.publish(server, entry.email, entry.publicKey, fingerprint);
|
||||
},
|
||||
clearPassphrases: clear,
|
||||
buildOutgoing
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user