Skip to content

Commit 0815c3f

Browse files
Merge pull request #24 from internxt/return_keys
[PB-5714] Return email keys when generating keystores
2 parents 559e3d2 + 8cad56e commit 0815c3f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/email-search/indexedDB.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const encryptAndStoreEmail = async (
9090
esDB: MailDB,
9191
): Promise<void> => {
9292
try {
93-
const aux = getAux(newEmailToStore.params);
93+
const aux = getAux(newEmailToStore.params, false);
9494
const enc = await encryptEmailContentSymmetricallyWithKey(newEmailToStore.body, indexKey, aux, newEmailToStore.id);
9595
const encryptedEmail: StoredEmail = { enc, params: newEmailToStore.params, id: newEmailToStore.id };
9696
await esDB.put(DB_LABEL, encryptedEmail);
@@ -114,7 +114,7 @@ export const encryptAndStoreManyEmail = async (
114114
try {
115115
const encryptedEmails = await Promise.all(
116116
newEmailsToStore.map(async (email: Email) => {
117-
const aux = getAux(email.params);
117+
const aux = getAux(email.params, false);
118118
const enc = await encryptEmailContentSymmetricallyWithKey(email.body, indexKey, aux, email.id);
119119

120120
return { enc, params: email.params, id: email.id };
@@ -137,7 +137,7 @@ export const encryptAndStoreManyEmail = async (
137137
*/
138138
const decryptEmail = async (indexKey: CryptoKey, encryptedEmail: StoredEmail): Promise<Email> => {
139139
try {
140-
const aux = getAux(encryptedEmail.params);
140+
const aux = getAux(encryptedEmail.params, false);
141141
const email = await decryptEmailSymmetrically(indexKey, aux, encryptedEmail.enc);
142142
return { body: email, params: encryptedEmail.params, id: encryptedEmail.id };
143143
} catch (error) {
@@ -178,7 +178,7 @@ export const getAndDecryptAllEmails = async (indexKey: CryptoKey, esDB: MailDB):
178178

179179
const decryptedEmails = await Promise.all(
180180
encryptedEmails.map(async (encEmail) => {
181-
const aux = getAux(encEmail.params);
181+
const aux = getAux(encEmail.params, false);
182182
const body = await decryptEmailSymmetrically(indexKey, aux, encEmail.enc);
183183
return { body, params: encEmail.params, id: encEmail.id };
184184
}),

src/keystore-crypto/emailEncryptionKey.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { generateEmailKeys } from '../email-crypto';
88
* The main keystore encryption key is derived from the base key (stored in session storage)
99
* The recovery keystore encryption key is derived from the recovery codes
1010
*
11-
* @returns The encryption and recovery keystores
11+
* @returns The encryption and recovery keystores, recovery codes and email keys
1212
*/
1313
export async function createEncryptionAndRecoveryKeystores(
1414
userEmail: string,
@@ -17,6 +17,7 @@ export async function createEncryptionAndRecoveryKeystores(
1717
encryptionKeystore: EncryptedKeystore;
1818
recoveryKeystore: EncryptedKeystore;
1919
recoveryCodes: string;
20+
keys: EmailKeys;
2021
}> {
2122
try {
2223
const keys = await generateEmailKeys();
@@ -28,7 +29,7 @@ export async function createEncryptionAndRecoveryKeystores(
2829
const recoveryKey = await deriveRecoveryKey(recoveryCodes);
2930
const recoveryKeystore = await encryptKeystoreContent(recoveryKey, keys, userEmail, KeystoreType.RECOVERY);
3031

31-
return { encryptionKeystore, recoveryKeystore, recoveryCodes };
32+
return { encryptionKeystore, recoveryKeystore, recoveryCodes, keys };
3233
} catch (error) {
3334
throw new Error('Failed to create encryption and recovery keystores', { cause: error });
3435
}

0 commit comments

Comments
 (0)