Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix Space passkey login session persistence

Anand Baburajane7716e043e79
diff --git a/web/apps/space/src/services/spaceLogin.ts b/web/apps/space/src/services/spaceLogin.ts
index fc7494e5e9..1180ed0927 100644
--- a/web/apps/space/src/services/spaceLogin.ts
+++ b/web/apps/space/src/services/spaceLogin.ts
@@ -18,6 +18,10 @@ import {
clearInflightPasskeySessionID,
passkeySessionExpiredErrorMessage,
} from "ente-accounts-rs/services/passkey";
+import {
+ stashKeyEncryptionKeyInSessionStore,
+ unstashKeyEncryptionKeyFromSession,
+} from "ente-accounts-rs/services/session-storage";
import {
getSRPAttributes,
srpVerificationUnauthorizedErrorMessage,
@@ -40,10 +44,6 @@ import {
createSpaceBrowserSession,
getOrCreateSpaceRootKey,
} from "services/spacePersistentSession";
-import {
- stashSpaceKeyEncryptionKeyInSessionStore,
- unstashSpaceKeyEncryptionKeyFromSession,
-} from "services/spaceSecureSessionStorage";
import { z } from "zod";
export interface SpaceLoginInput {
@@ -253,7 +253,7 @@ const finishSpaceLoginVerification = async ({
if (!accountsUrl) {
throw new Error("Passkey verification URL is missing.");
}
- if (kek) stashSpaceKeyEncryptionKeyInSessionStore(kek);
+ if (kek) await stashKeyEncryptionKeyInSessionStore(kek);
updateSavedLocalUser({
passkeySessionID,
twoFactorSessionID: secondFactorSessionID,
@@ -273,7 +273,7 @@ const finishSpaceLoginVerification = async ({
}
if (secondFactorSessionID) {
- if (kek) stashSpaceKeyEncryptionKeyInSessionStore(kek);
+ if (kek) await stashKeyEncryptionKeyInSessionStore(kek);
updateSavedLocalUser({
passkeySessionID: undefined,
twoFactorSessionID: secondFactorSessionID,
@@ -368,8 +368,10 @@ const finishSpaceLoginAuthorization = async ({
id,
keyAttributes,
}: TwoFactorAuthorizationResponse): Promise<SpaceLoginResult> => {
- const stashedKEK = unstashSpaceKeyEncryptionKeyFromSession();
- const pendingCredentials = await savedPendingSpaceLoginCredentials();
+ const [stashedKEK, pendingCredentials] = await Promise.all([
+ unstashKeyEncryptionKeyFromSession(),
+ savedPendingSpaceLoginCredentials(),
+ ]);
const kek =
stashedKEK ??
(pendingCredentials
diff --git a/web/apps/space/src/services/spaceSecureSessionStorage.ts b/web/apps/space/src/services/spaceSecureSessionStorage.ts
index 9e07c334c9..6f32d2499e 100644
--- a/web/apps/space/src/services/spaceSecureSessionStorage.ts
+++ b/web/apps/space/src/services/spaceSecureSessionStorage.ts
@@ -2,11 +2,10 @@ import { z } from "zod";
const windowNamePrefix = "ente-space-secure-session:";
const sessionStorageKey = "enteSpaceSecureSession";
-const legacyAccountsSessionKeys = ["encryptionKey", "keyEncryptionKey"];
+const legacyAccountsSessionKeys = ["encryptionKey"];
const SecureSessionState = z.object({
authMasterKey: z.string().optional(),
- keyEncryptionKey: z.string().optional(),
spaceRootKey: z.string().optional(),
});
@@ -38,9 +37,7 @@ const base64ToBytes = (value: string) => {
};
const hasSecret = (state: SecureSessionState) =>
- state.authMasterKey !== undefined ||
- state.keyEncryptionKey !== undefined ||
- state.spaceRootKey !== undefined;
+ state.authMasterKey !== undefined || state.spaceRootKey !== undefined;
const clearLegacyAccountsSessionKeys = () => {
for (const key of legacyAccountsSessionKeys) sessionStorage.removeItem(key);
@@ -152,15 +149,3 @@ export const spaceRootKeyFromSpaceSession = () =>
export const saveSpaceRootKeyInSpaceSession = (spaceRootKey: string) => {
saveSecureSessionState({ ...secureSessionState(), spaceRootKey });
};
-
-export const stashSpaceKeyEncryptionKeyInSessionStore = (kek: string) => {
- saveSecureSessionState({ ...secureSessionState(), keyEncryptionKey: kek });
-};
-
-export const unstashSpaceKeyEncryptionKeyFromSession = () => {
- const state = secureSessionState();
- const kek = state.keyEncryptionKey;
- if (kek === undefined) return undefined;
- saveSecureSessionState({ ...state, keyEncryptionKey: undefined });
- return kek;
-};