Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update browser extension email routing (#2159)
Leendert de Borstfc1fab282bd0
diff --git a/apps/browser-extension/src/utils/EmailRouting.ts b/apps/browser-extension/src/utils/EmailRouting.tsindex fd65a6731..b39666ca7 100644Binary files a/apps/browser-extension/src/utils/EmailRouting.ts and b/apps/browser-extension/src/utils/EmailRouting.ts differdiff --git a/apps/browser-extension/src/utils/EncryptionUtility.ts b/apps/browser-extension/src/utils/EncryptionUtility.tsindex 563e50ba9..70efe6155 100644--- a/apps/browser-extension/src/utils/EncryptionUtility.ts+++ b/apps/browser-extension/src/utils/EncryptionUtility.ts@@ -4,7 +4,7 @@ import argon2 from 'argon2-browser/dist/argon2-bundled.min.js';import { devWarn } from '@/utils/devLogger/DevLogger';import type { EncryptionKey } from '@/utils/dist/core/models/vault';-import type { Email, MailboxEmail } from '@/utils/dist/core/models/webapi';+import type { Email, EmailKeyWrap, MailboxEmail } from '@/utils/dist/core/models/webapi';/*** Utility class for encryption operations including:@@ -360,6 +360,21 @@ export class EncryptionUtility {return await privateKey;}+ /**+ * Finds the wrap of an email's symmetric key that one of the locally held keypairs can open. An email carries+ * one wrap per manifest keypair the caller holds.+ */+ private static resolveEmailWrap(email: { wraps: EmailKeyWrap[] },encryptionKeys: EncryptionKey[]): { encryptionKey: EncryptionKey, encryptedSymmetricKey: string } {+ for (const wrap of email.wraps) {+ const key = encryptionKeys.find(k => k.PublicKey === wrap.publicKey);+ if (key) {+ return { encryptionKey: key, encryptedSymmetricKey: wrap.encryptedSymmetricKey };+ }+ }++ throw new Error('Encryption key not found');+ }+/*** Decrypts an individual email based on the provided public/private key pairs.*/@@ -368,16 +383,12 @@ export class EncryptionUtility {encryptionKeys: EncryptionKey[]): Promise<Email> {try {- const encryptionKey = encryptionKeys.find(key => key.PublicKey === email.encryptionKey);-- if (!encryptionKey) {- throw new Error('Encryption key not found');- }+ const wrap = EncryptionUtility.resolveEmailWrap(email, encryptionKeys);// Decrypt symmetric key with asymmetric private key- const privateKey = await EncryptionUtility.getPrivateKeyObject(encryptionKey);+ const privateKey = await EncryptionUtility.getPrivateKeyObject(wrap.encryptionKey);const symmetricKey = await EncryptionUtility.decryptWithPrivateKeyObject(- email.encryptedSymmetricKey,+ wrap.encryptedSymmetricKey,privateKey);const symmetricKeyBase64 = Buffer.from(symmetricKey).toString('base64');@@ -420,16 +431,12 @@ export class EncryptionUtility {): Promise<MailboxEmail[]> {const results = await Promise.all(emails.map(async email => {try {- const encryptionKey = encryptionKeys.find(key => key.PublicKey === email.encryptionKey);-- if (!encryptionKey) {- throw new Error('Encryption key not found');- }+ const wrap = EncryptionUtility.resolveEmailWrap(email, encryptionKeys);// Decrypt symmetric key with asymmetric private key- const privateKey = await EncryptionUtility.getPrivateKeyObject(encryptionKey);+ const privateKey = await EncryptionUtility.getPrivateKeyObject(wrap.encryptionKey);const symmetricKey = await EncryptionUtility.decryptWithPrivateKeyObject(- email.encryptedSymmetricKey,+ wrap.encryptedSymmetricKey,privateKey);const symmetricKeyBase64 = Buffer.from(symmetricKey).toString('base64');@@ -466,16 +473,12 @@ export class EncryptionUtility {encryptionKeys: EncryptionKey[]): Promise<Uint8Array> {try {- const encryptionKey = encryptionKeys.find(key => key.PublicKey === email.encryptionKey);-- if (!encryptionKey) {- throw new Error('Encryption key not found');- }+ const wrap = EncryptionUtility.resolveEmailWrap(email, encryptionKeys);// Decrypt the symmetric key using private key (returns raw bytes)- const privateKey = await EncryptionUtility.getPrivateKeyObject(encryptionKey);+ const privateKey = await EncryptionUtility.getPrivateKeyObject(wrap.encryptionKey);const symmetricKey = await EncryptionUtility.decryptWithPrivateKeyObject(- email.encryptedSymmetricKey,+ wrap.encryptedSymmetricKey,privateKey);diff --git a/apps/browser-extension/src/utils/VaultSyncService.ts b/apps/browser-extension/src/utils/VaultSyncService.tsindex 1f181a7a6..0e735dc6c 100644--- a/apps/browser-extension/src/utils/VaultSyncService.ts+++ b/apps/browser-extension/src/utils/VaultSyncService.ts@@ -835,7 +835,7 @@ export class VaultSyncService {// Personal manifest first by construction (see `resolveManifestRecords`), which is also the order canonicalize requires.const [personalRecord, ...sharedRecords] = manifestRecords;const privateEmailDomains = (await getStorageItem<string[]>(StorageKeys.PRIVATE_EMAIL_DOMAINS)) ?? [];- const emailRouting = buildEmailRouting(canonicalized.manifests.map(m => m.manifest), personalRecord.manifestId, privateEmailDomains);+ const emailRouting = buildEmailRouting(canonicalized.manifests.map(m => m.manifest), privateEmailDomains);/** Debug: manifest-set summary + full unencrypted manifests + data buckets, inspectable in the console.diff --git a/apps/browser-extension/src/utils/types/EmailRoutingPush.ts b/apps/browser-extension/src/utils/types/EmailRoutingPush.tsindex b5fd86c57..097fd78c3 100644--- a/apps/browser-extension/src/utils/types/EmailRoutingPush.ts+++ b/apps/browser-extension/src/utils/types/EmailRoutingPush.ts@@ -1,6 +1,7 @@/**- * The email-routing set sent on a vault push: every alias the server should route, each carrying the manifest- * that owns it.+ * The email-routing set sent on a vault push: one entry per (address, manifest) pair. An address claimed by+ * several manifests (personal + shared during family sharing) appears once per manifest; the server links the+ * claim to each so incoming mail is key-wrapped per linked manifest.*/export type EmailRoutingPush = {emailAddressList: Array<{ address: string; manifestId: string }>;