diff --git a/src/calendar-app/workerUtils/worker/CalendarWorkerLocator.ts b/src/calendar-app/workerUtils/worker/CalendarWorkerLocator.ts index 3f6ed98f4a0..a38d8879859 100644 --- a/src/calendar-app/workerUtils/worker/CalendarWorkerLocator.ts +++ b/src/calendar-app/workerUtils/worker/CalendarWorkerLocator.ts @@ -309,6 +309,7 @@ export async function initLocator(worker: CalendarWorkerImpl, browserData: Brows async (error: Error) => { await worker.sendError(error) }, + locator.cacheManagement, ) locator.userManagement = lazyMemoized(async () => { diff --git a/src/common/api/worker/facades/LoginFacade.ts b/src/common/api/worker/facades/LoginFacade.ts index b7be188c8b0..6e6e26f84b9 100644 --- a/src/common/api/worker/facades/LoginFacade.ts +++ b/src/common/api/worker/facades/LoginFacade.ts @@ -11,6 +11,7 @@ import { DeferredObject, Hex, hexToUint8Array, + lazyAsync, neverNull, ofClass, uint8ArrayToBase64, @@ -96,6 +97,7 @@ import { Argon2idFacade } from "./Argon2idFacade.js" import { CredentialType } from "../../../misc/credentials/CredentialType.js" import { KeyRotationFacade } from "./KeyRotationFacade.js" import { encryptString } from "../crypto/CryptoWrapper.js" +import { CacheManagementFacade } from "./lazy/CacheManagementFacade.js" assertWorkerOrNode() @@ -198,6 +200,7 @@ export class LoginFacade { private readonly argon2idFacade: Argon2idFacade, private readonly noncachingEntityClient: EntityClient, private readonly sendError: (error: Error) => Promise, + private readonly cacheManagementFacade: lazyAsync, ) {} init(eventBusClient: EventBusClient) { @@ -333,6 +336,11 @@ export class LoginFacade { }) console.log("Migrate KDF from:", user.kdfVersion, "to", targetKdfType) await this.serviceExecutor.post(ChangeKdfService, changeKdfPostIn) + // We reload the user because we experienced a race condition + // were we do not process the User update after doing the argon2 migration from the web client.ยด + // In order do not rework the entity processing and its initialization for new clients we + // replace the cached instances after doing the migration + await (await this.cacheManagementFacade()).reloadUser() this.userFacade.setUserGroupKeyDistributionKey(newUserPassphraseKey) } diff --git a/src/mail-app/workerUtils/worker/WorkerLocator.ts b/src/mail-app/workerUtils/worker/WorkerLocator.ts index 6f5594645ef..e6e8ae9f659 100644 --- a/src/mail-app/workerUtils/worker/WorkerLocator.ts +++ b/src/mail-app/workerUtils/worker/WorkerLocator.ts @@ -347,6 +347,7 @@ export async function initLocator(worker: WorkerImpl, browserData: BrowserData) async (error: Error) => { await worker.sendError(error) }, + locator.cacheManagement, ) locator.search = lazyMemoized(async () => { diff --git a/test/tests/api/worker/facades/LoginFacadeTest.ts b/test/tests/api/worker/facades/LoginFacadeTest.ts index 3f6d849f162..ae8e55cbad0 100644 --- a/test/tests/api/worker/facades/LoginFacadeTest.ts +++ b/test/tests/api/worker/facades/LoginFacadeTest.ts @@ -36,6 +36,7 @@ import { createTestEntity } from "../../../TestUtils.js" import { KeyRotationFacade } from "../../../../../src/common/api/worker/facades/KeyRotationFacade.js" import { CredentialType } from "../../../../../src/common/misc/credentials/CredentialType.js" import { encryptString } from "../../../../../src/common/api/worker/crypto/CryptoWrapper.js" +import { CacheManagementFacade } from "../../../../../src/common/api/worker/facades/lazy/CacheManagementFacade.js" const { anything, argThat } = matchers @@ -97,6 +98,7 @@ o.spec("LoginFacadeTest", function () { let blobAccessTokenFacade: BlobAccessTokenFacade let databaseKeyFactoryMock: DatabaseKeyFactory let argon2idFacade: Argon2idFacade + let cacheManagmentFacadeMock: CacheManagementFacade const timeRangeDays = 42 const login = "born.slippy@tuta.io" @@ -139,6 +141,7 @@ o.spec("LoginFacadeTest", function () { databaseKeyFactoryMock = object() argon2idFacade = object() when(argon2idFacade.generateKeyFromPassphrase(anything(), anything())).thenResolve(PASSWORD_KEY) + cacheManagmentFacadeMock = object() facade = new LoginFacade( restClientMock, @@ -156,6 +159,7 @@ o.spec("LoginFacadeTest", function () { argon2idFacade, entityClientMock, async (error: Error) => {}, + async () => cacheManagmentFacadeMock, ) eventBusClientMock = instance(EventBusClient) @@ -802,6 +806,7 @@ o.spec("LoginFacadeTest", function () { }), ), ) + verify(cacheManagmentFacadeMock.reloadUser()) }) o.afterEach(() => { Const.EXECUTE_KDF_MIGRATION = false