Add ANDROID_SECURITY_PLAN.md to project
This commit is contained in:
+3
-1
@@ -5,7 +5,7 @@ function registerDavIpcHandlers({
|
||||
davPublicConfig,
|
||||
openDavClient,
|
||||
activeDavConfig,
|
||||
ICAL,
|
||||
getICAL,
|
||||
makeCalendarData,
|
||||
makeVcard,
|
||||
randomUUID,
|
||||
@@ -88,6 +88,7 @@ function registerDavIpcHandlers({
|
||||
if (!config) throw new Error(`Connect a ${type === 'caldav' ? 'CalDAV' : 'CardDAV'} server first.`);
|
||||
const client = await openDavClient(config, type);
|
||||
if (type === 'caldav') {
|
||||
const { default: ICAL } = await getICAL();
|
||||
const calendars = await client.fetchCalendars();
|
||||
const result = [];
|
||||
for (const calendar of calendars) {
|
||||
@@ -116,6 +117,7 @@ function registerDavIpcHandlers({
|
||||
}
|
||||
return { items: result, account: davPublicConfig(config) };
|
||||
}
|
||||
const { default: ICAL } = await getICAL();
|
||||
const books = await client.fetchAddressBooks();
|
||||
const result = [];
|
||||
for (const book of books) {
|
||||
|
||||
@@ -35,7 +35,7 @@ function registerMailIpcHandlers(dependencies) {
|
||||
mailOutbox,
|
||||
pgpMail,
|
||||
PgpError,
|
||||
simpleParser,
|
||||
getMailparser,
|
||||
folderPath,
|
||||
sendMailNow,
|
||||
pgpFailure
|
||||
@@ -270,6 +270,7 @@ registerIpcHandler('mail:update-message', async (_event, input) => {
|
||||
|
||||
// Encrypted messages keep their attachments inside the encrypted payload.
|
||||
async function parseForAttachments(source) {
|
||||
const { simpleParser } = await getMailparser();
|
||||
const parsed = await simpleParser(source);
|
||||
const kind = pgpMail.detect(parsed);
|
||||
if (kind !== 'encrypted-mime' && kind !== 'encrypted-inline') return parsed;
|
||||
|
||||
+5
-3
@@ -14,6 +14,7 @@ function registerPgpIpcHandlers({
|
||||
BrowserWindow,
|
||||
dialog,
|
||||
fs,
|
||||
getOpenPGP,
|
||||
openpgp,
|
||||
pgpKeys,
|
||||
pgpCache,
|
||||
@@ -27,7 +28,7 @@ function registerPgpIpcHandlers({
|
||||
readAccount,
|
||||
imapClient,
|
||||
folderPath,
|
||||
simpleParser,
|
||||
getMailparser,
|
||||
extractMailContent
|
||||
}) {
|
||||
async function fetchMessageSource(account, folder, uid) {
|
||||
@@ -108,6 +109,7 @@ function registerPgpIpcHandlers({
|
||||
const account = await readAccount();
|
||||
if (!account) throw new Error('Add a mail account before opening messages.');
|
||||
const source = await fetchMessageSource(account, String(input?.folder || 'Inbox'), Number(input?.uid));
|
||||
const { simpleParser } = await getMailparser();
|
||||
const outer = await simpleParser(source);
|
||||
try {
|
||||
const result = await pgpMail.decrypt(outer, { passphrase: typeof input?.passphrase === 'string' && input.passphrase ? input.passphrase : null });
|
||||
@@ -143,7 +145,7 @@ function registerPgpIpcHandlers({
|
||||
if ((await fs.stat(result.filePaths[0])).size > 200000) throw new Error('That key file is too large.');
|
||||
armoredKey = await fs.readFile(result.filePaths[0], 'utf8');
|
||||
}
|
||||
const key = await openpgp.readKey({ armoredKey }).catch(() => {
|
||||
const key = await (getOpenPGP ? (await getOpenPGP()).readKey({ armoredKey }) : openpgp.readKey({ armoredKey })).catch(() => {
|
||||
throw new Error('That is not a valid OpenPGP public key.');
|
||||
});
|
||||
const fingerprint = key.getFingerprint().toUpperCase();
|
||||
@@ -277,7 +279,7 @@ function registerPgpIpcHandlers({
|
||||
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 armoredKey = await pgpKeys.exportPublic(fingerprint);
|
||||
const publicKey = await openpgp.readKey({ armoredKey });
|
||||
const publicKey = await (getOpenPGP ? (await getOpenPGP()).readKey({ armoredKey }) : openpgp.readKey({ armoredKey }));
|
||||
const emails = [...new Set(publicKey.getUserIDs()
|
||||
.map(userId => (/<([^>]+)>/.exec(userId)?.[1] || (userId.includes('@') ? userId : '')).trim().toLowerCase())
|
||||
.filter(Boolean))];
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
function createMailConnections({ ImapFlow, createTransport, oauthTokenManager }) {
|
||||
function createMailConnections({ ImapFlow, createTransport, getImapFlow, getNodemailer, oauthTokenManager }) {
|
||||
let ImapFlowModule = ImapFlow;
|
||||
let nodemailerModule = createTransport ? { createTransport } : null;
|
||||
|
||||
async function imapClient(account, options = {}) {
|
||||
if (!ImapFlowModule) {
|
||||
const module = await getImapFlow();
|
||||
ImapFlowModule = module.ImapFlow || module.default || module;
|
||||
}
|
||||
const isOAuth = account.authMethod === 'oauth2';
|
||||
const auth = isOAuth
|
||||
? { user: account.email, accessToken: await oauthTokenManager.getAccessToken(account) }
|
||||
: { user: account.email, pass: account.password };
|
||||
return new ImapFlow({
|
||||
return new ImapFlowModule({
|
||||
host: account.imapHost,
|
||||
port: account.imapPort,
|
||||
secure: Boolean(account.imapSecure),
|
||||
@@ -20,6 +27,9 @@ function createMailConnections({ ImapFlow, createTransport, oauthTokenManager })
|
||||
}
|
||||
|
||||
async function smtpTransport(account) {
|
||||
if (!nodemailerModule) {
|
||||
nodemailerModule = await getNodemailer();
|
||||
}
|
||||
const isOAuth = account.authMethod === 'oauth2';
|
||||
const auth = isOAuth
|
||||
? {
|
||||
@@ -30,7 +40,7 @@ function createMailConnections({ ImapFlow, createTransport, oauthTokenManager })
|
||||
}
|
||||
: { user: account.email, pass: account.password };
|
||||
const secure = Boolean(account.smtpSecure);
|
||||
return createTransport({
|
||||
return nodemailerModule.createTransport({
|
||||
host: account.smtpHost,
|
||||
port: account.smtpPort,
|
||||
secure,
|
||||
|
||||
+49
-12
@@ -1,3 +1,5 @@
|
||||
require('v8-compile-cache');
|
||||
|
||||
const startupTraceEnabled = process.env.EP_MAIL_STARTUP_TRACE === '1';
|
||||
const startupTraceStartedAt = process.hrtime.bigint();
|
||||
function traceStartup(message) {
|
||||
@@ -11,13 +13,44 @@ const { app, BrowserWindow, shell, ipcMain, safeStorage, dialog, Notification, p
|
||||
const fsSync = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const fs = require('node:fs/promises');
|
||||
const { ImapFlow } = require('imapflow');
|
||||
const nodemailer = require('nodemailer');
|
||||
const { simpleParser } = require('mailparser');
|
||||
const { randomUUID } = require('node:crypto');
|
||||
const { createDAVClient } = require('tsdav');
|
||||
const ICAL = require('ical.js');
|
||||
const openpgp = require('openpgp');
|
||||
|
||||
let tsdavPromise = null;
|
||||
function getTsdav() {
|
||||
if (!tsdavPromise) tsdavPromise = import('tsdav');
|
||||
return tsdavPromise;
|
||||
}
|
||||
|
||||
let icalPromise = null;
|
||||
function getICAL() {
|
||||
if (!icalPromise) icalPromise = import('ical.js');
|
||||
return icalPromise;
|
||||
}
|
||||
|
||||
let openpgpPromise = null;
|
||||
function getOpenPGP() {
|
||||
if (!openpgpPromise) openpgpPromise = import('openpgp');
|
||||
return openpgpPromise;
|
||||
}
|
||||
|
||||
let imapFlowPromise = null;
|
||||
function getImapFlow() {
|
||||
if (!imapFlowPromise) imapFlowPromise = import('imapflow');
|
||||
return imapFlowPromise;
|
||||
}
|
||||
|
||||
let nodemailerPromise = null;
|
||||
function getNodemailer() {
|
||||
if (!nodemailerPromise) nodemailerPromise = import('nodemailer');
|
||||
return nodemailerPromise;
|
||||
}
|
||||
|
||||
let mailparserPromise = null;
|
||||
function getMailparser() {
|
||||
if (!mailparserPromise) mailparserPromise = import('mailparser');
|
||||
return mailparserPromise;
|
||||
}
|
||||
|
||||
const { createKeyServerService, listServers, MAX_CUSTOM_SERVERS, normalizeCustomServer } = require('./pgp-keyservers.cjs');
|
||||
const { normalizeOutgoingAttachments, serializeOutgoingAttachments } = require('./mail-attachments.cjs');
|
||||
const {
|
||||
@@ -52,6 +85,8 @@ const { pgpFailure, registerPgpIpcHandlers } = require('./ipc/pgp.cjs');
|
||||
const { registerDavIpcHandlers } = require('./ipc/dav.cjs');
|
||||
const { registerMailIpcHandlers } = require('./ipc/mail.cjs');
|
||||
|
||||
traceStartup('all requires complete');
|
||||
|
||||
const credentialsPath = () => path.join(app.getPath('userData'), 'mail-account.enc');
|
||||
const davCredentialsPath = () => path.join(app.getPath('userData'), 'dav-accounts.enc');
|
||||
const pgpKeysPath = () => path.join(app.getPath('userData'), 'pgp-keys.enc');
|
||||
@@ -204,6 +239,7 @@ function davPublicConfig(config) {
|
||||
}
|
||||
|
||||
async function openDavClient(config, type) {
|
||||
const { createDAVClient } = await getTsdav();
|
||||
return createDAVClient({ serverUrl: config.serverUrl, credentials: { username: config.username, password: config.password }, authMethod: 'Basic', defaultAccountType: type });
|
||||
}
|
||||
|
||||
@@ -214,8 +250,8 @@ function activeDavConfig(store, type, id = null) {
|
||||
}
|
||||
|
||||
const { imapClient, smtpTransport } = createMailConnections({
|
||||
ImapFlow,
|
||||
createTransport: nodemailer.createTransport,
|
||||
getImapFlow,
|
||||
getNodemailer,
|
||||
oauthTokenManager
|
||||
});
|
||||
|
||||
@@ -290,6 +326,7 @@ function cachedMailbox(account, folder, offset = 0, limit = 20, filters = {}) {
|
||||
}
|
||||
|
||||
async function toUiMessage(item, folder) {
|
||||
const { simpleParser } = await getMailparser();
|
||||
const parsed = await simpleParser(item.source);
|
||||
const sender = parsed.from?.value?.[0];
|
||||
const pgpKind = pgpMail.detect(parsed);
|
||||
@@ -410,7 +447,7 @@ registerPgpIpcHandlers({
|
||||
BrowserWindow,
|
||||
dialog,
|
||||
fs,
|
||||
openpgp,
|
||||
getOpenPGP,
|
||||
pgpKeys,
|
||||
pgpCache,
|
||||
pgpMail,
|
||||
@@ -423,7 +460,7 @@ registerPgpIpcHandlers({
|
||||
readAccount,
|
||||
imapClient,
|
||||
folderPath,
|
||||
simpleParser,
|
||||
getMailparser,
|
||||
extractMailContent
|
||||
});
|
||||
const { sendMailNow } = createMailSender({ smtpTransport, imapClient, findSentMailbox });
|
||||
@@ -500,7 +537,7 @@ registerMailIpcHandlers({
|
||||
mailOutbox,
|
||||
pgpMail,
|
||||
PgpError,
|
||||
simpleParser,
|
||||
getMailparser,
|
||||
folderPath,
|
||||
sendMailNow,
|
||||
pgpFailure
|
||||
@@ -513,7 +550,7 @@ registerDavIpcHandlers({
|
||||
davPublicConfig,
|
||||
openDavClient,
|
||||
activeDavConfig,
|
||||
ICAL,
|
||||
getICAL,
|
||||
makeCalendarData,
|
||||
makeVcard,
|
||||
randomUUID,
|
||||
|
||||
Reference in New Issue
Block a user