Android security implementation Phase 0-3 finalization part 1
This commit is contained in:
+43
-3
@@ -10240,20 +10240,30 @@ Add the new key as an unverified key? Compare fingerprints with the owner before
|
||||
async function unlock(fingerprint, passphrase) {
|
||||
const entry = (await store()).keys.find((item) => item.fingerprint === fingerprint);
|
||||
if (!entry) throw new Error("That key was not found.");
|
||||
const secret = passphrase || await biometricPassphrase(fingerprint);
|
||||
if (!secret) throw Object.assign(new Error(`Enter the passphrase for ${entry.email || "your key"}.`), { code: "PASSPHRASE_REQUIRED" });
|
||||
return unlockWithPassphrase(entry, secret);
|
||||
}
|
||||
async function unlockWithPassphrase(entry, passphrase) {
|
||||
try {
|
||||
return await po({ privateKey: await Wa({ armoredKey: entry.privateKey }), passphrase });
|
||||
} catch {
|
||||
throw new Error("The passphrase is incorrect.");
|
||||
}
|
||||
}
|
||||
async function biometricPassphrase(fingerprint) {
|
||||
if (typeof EpMail2.getPgpBiometricPassphrase !== "function") return null;
|
||||
const result = await EpMail2.getPgpBiometricPassphrase({ fingerprint });
|
||||
return result?.enabled && typeof result.passphrase === "string" ? result.passphrase : null;
|
||||
}
|
||||
async function signerFor(account, passphrase) {
|
||||
const data = await store();
|
||||
const entry = data.keys.find((item) => item.email.toLowerCase() === String(account.email).toLowerCase());
|
||||
if (!entry) throw Object.assign(new Error("Create or import an encryption key for this address first."), { code: "NO_SIGNING_KEY" });
|
||||
const secret = passphrase || cached(entry.fingerprint);
|
||||
const secret = passphrase || cached(entry.fingerprint) || await biometricPassphrase(entry.fingerprint);
|
||||
if (!secret) throw Object.assign(new Error(`Enter the passphrase for ${entry.email} to sign this message.`), { code: "PASSPHRASE_REQUIRED", fingerprint: entry.fingerprint, email: entry.email });
|
||||
try {
|
||||
const key = await unlock(entry.fingerprint, secret);
|
||||
const key = await unlockWithPassphrase(entry, secret);
|
||||
cache(entry.fingerprint, secret);
|
||||
return { key, entry };
|
||||
} catch {
|
||||
@@ -10364,6 +10374,7 @@ ${body}`);
|
||||
selected = candidates.find((entry) => cached(entry.fingerprint)) || selected;
|
||||
secret = cached(selected.fingerprint);
|
||||
}
|
||||
if (!secret) secret = await biometricPassphrase(selected.fingerprint);
|
||||
if (!secret) return { failed: true, code: "PASSPHRASE_REQUIRED", fingerprint: selected.fingerprint, email: selected.email, message: "Enter your key passphrase to read this message." };
|
||||
let privateKey;
|
||||
try {
|
||||
@@ -10536,6 +10547,23 @@ ${body}`);
|
||||
clear(fingerprint);
|
||||
return { removed: true };
|
||||
},
|
||||
async enableBiometricUnlock({ fingerprint, passphrase }) {
|
||||
if (typeof EpMail2.setPgpBiometricUnlock !== "function") throw new Error("Biometric key unlock is not available on this device.");
|
||||
const entry = (await store()).keys.find((item) => item.fingerprint === fingerprint);
|
||||
if (!entry) throw new Error("That key was not found.");
|
||||
if (!passphrase) throw new Error("Enter the key passphrase first.");
|
||||
await unlockWithPassphrase(entry, passphrase);
|
||||
return EpMail2.setPgpBiometricUnlock({ fingerprint, passphrase });
|
||||
},
|
||||
async biometricUnlockEnabled(fingerprint) {
|
||||
if (typeof EpMail2.pgpBiometricUnlockEnabled !== "function") return false;
|
||||
return Boolean((await EpMail2.pgpBiometricUnlockEnabled({ fingerprint }))?.enabled);
|
||||
},
|
||||
async disableBiometricUnlock(fingerprint) {
|
||||
if (typeof EpMail2.removePgpBiometricUnlock !== "function") throw new Error("Biometric key unlock is not available on this device.");
|
||||
clear(fingerprint);
|
||||
return EpMail2.removePgpBiometricUnlock({ fingerprint });
|
||||
},
|
||||
async contacts() {
|
||||
return (await store()).contacts.map(({ fingerprint, name, emails, trust, source, addedAt }) => ({ fingerprint, name, emails, trust, source, addedAt }));
|
||||
},
|
||||
@@ -10575,10 +10603,20 @@ Only continue if you checked this fingerprint with the owner.`)) throw new Error
|
||||
const { keys, missing } = await resolveRecipients(addresses);
|
||||
const account = await getAccount();
|
||||
const entry = sign ? (await store()).keys.find((item) => item.email.toLowerCase() === String(account?.email || "").toLowerCase()) : null;
|
||||
let biometricUnlockEnabled = false;
|
||||
if (entry && typeof EpMail2.pgpBiometricUnlockEnabled === "function") {
|
||||
biometricUnlockEnabled = Boolean((await EpMail2.pgpBiometricUnlockEnabled({ fingerprint: entry.fingerprint }))?.enabled);
|
||||
}
|
||||
return {
|
||||
recipients: keys.map((item) => ({ address: item.address, fingerprint: item.fingerprint, trust: item.trust })),
|
||||
missing,
|
||||
signer: entry ? { fingerprint: entry.fingerprint, email: entry.email, name: entry.name, unlocked: Boolean(cached(entry.fingerprint)) } : null
|
||||
signer: entry ? {
|
||||
fingerprint: entry.fingerprint,
|
||||
email: entry.email,
|
||||
name: entry.name,
|
||||
unlocked: Boolean(cached(entry.fingerprint)),
|
||||
biometricUnlockEnabled
|
||||
} : null
|
||||
};
|
||||
},
|
||||
decryptMessage,
|
||||
@@ -10637,6 +10675,8 @@ Only continue if you checked this fingerprint with the owner.`)) throw new Error
|
||||
setNotificationDetails: (enabled) => EpMail.setNotificationDetails({ enabled }),
|
||||
getAppLockSettings: () => EpMail.getAppLockSettings(),
|
||||
setAppLockEnabled: (enabled) => EpMail.setAppLockEnabled({ enabled }),
|
||||
setAppLockDelay: (seconds) => EpMail.setAppLockDelay({ seconds }),
|
||||
deleteAllLocalData: () => EpMail.deleteAllLocalData(),
|
||||
getAccount: () => EpMail.getAccount(),
|
||||
listAccounts: () => EpMail.listAccounts(),
|
||||
selectAccount: (id) => EpMail.selectAccount({ id }),
|
||||
|
||||
Reference in New Issue
Block a user