π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
conv
Manav Rathibad4ae47a4a0
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 2292d68320..b6dfd7a15c 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -78,11 +78,7 @@ import {setIsFirstLogin,setJustSignedUp,} from "@ente/shared/storage/localStorage/helpers";-import {- SESSION_KEYS,- clearKeys,- getKey,-} from "@ente/shared/storage/sessionStorage";+import { clearKeys, getKey } from "@ente/shared/storage/sessionStorage";import ArrowBackIcon from "@mui/icons-material/ArrowBack";import FileUploadOutlinedIcon from "@mui/icons-material/FileUploadOutlined";import MenuIcon from "@mui/icons-material/Menu";@@ -302,7 +298,7 @@ const Page: React.FC = () => {};useEffect(() => {- const key = getKey(SESSION_KEYS.ENCRYPTION_KEY);+ const key = getKey("encryptionKey");const token = getToken();if (!key || !token) {stashRedirect("/gallery");@@ -404,7 +400,7 @@ const Page: React.FC = () => {}, [activeCollectionID, router.isReady]);useEffect(() => {- if (router.isReady && getKey(SESSION_KEYS.ENCRYPTION_KEY)) {+ if (router.isReady && getKey("encryptionKey")) {handleSubscriptionCompletionRedirectIfNeeded(showMiniDialog,showLoadingBar,diff --git a/web/apps/photos/src/pages/index.tsx b/web/apps/photos/src/pages/index.tsxindex 8ed6000daf..587dcab881 100644--- a/web/apps/photos/src/pages/index.tsx+++ b/web/apps/photos/src/pages/index.tsx@@ -12,7 +12,7 @@ import { saveKeyInSessionStore } from "@ente/shared/crypto/helpers";import localForage from "@ente/shared/storage/localForage";import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";import { getToken } from "@ente/shared/storage/localStorage/helpers";-import { SESSION_KEYS, getKey } from "@ente/shared/storage/sessionStorage";+import { getKey } from "@ente/shared/storage/sessionStorage";import { Box, Stack, Typography, styled } from "@mui/material";import { t } from "i18next";import { useRouter } from "next/router";@@ -61,7 +61,7 @@ const Page: React.FC = () => {const handleNormalRedirect = async () => {const user = getData(LS_KEYS.USER);- let key = getKey(SESSION_KEYS.ENCRYPTION_KEY);+ let key = getKey("encryptionKey");const electron = globalThis.electron;if (!key && electron) {try {@@ -70,11 +70,7 @@ const Page: React.FC = () => {log.error("Failed to read master key from safe storage", e);}if (key) {- await saveKeyInSessionStore(- SESSION_KEYS.ENCRYPTION_KEY,- key,- true,- );+ await saveKeyInSessionStore("encryptionKey", key, true);}}const token = getToken();diff --git a/web/packages/accounts/components/SignUpContents.tsx b/web/packages/accounts/components/SignUpContents.tsxindex 8dfedd6dd0..dabc08c7f3 100644--- a/web/packages/accounts/components/SignUpContents.tsx+++ b/web/packages/accounts/components/SignUpContents.tsx@@ -17,7 +17,6 @@ import {setJustSignedUp,setLocalReferralSource,} from "@ente/shared/storage/localStorage/helpers";-import { SESSION_KEYS } from "@ente/shared/storage/sessionStorage";import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";import {Box,@@ -116,10 +115,7 @@ export const SignUpContents: React.FC<SignUpContentsProps> = ({masterKey,);- await saveKeyInSessionStore(- SESSION_KEYS.ENCRYPTION_KEY,- masterKey,- );+ await saveKeyInSessionStore("encryptionKey", masterKey);setJustSignedUp(true);void router.push("/verify");} catch (e) {diff --git a/web/packages/accounts/pages/change-password.tsx b/web/packages/accounts/pages/change-password.tsxindex b11180211d..2f8ce9ff25 100644--- a/web/packages/accounts/pages/change-password.tsx+++ b/web/packages/accounts/pages/change-password.tsx@@ -27,7 +27,6 @@ import {saveKeyInSessionStore,} from "@ente/shared/crypto/helpers";import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";-import { SESSION_KEYS } from "@ente/shared/storage/sessionStorage";import { getActualKey } from "@ente/shared/user";import type { KEK, KeyAttributes, User } from "@ente/shared/user/types";import { t } from "i18next";@@ -123,7 +122,7 @@ const Page: React.FC = () => {key,);- await saveKeyInSessionStore(SESSION_KEYS.ENCRYPTION_KEY, key);+ await saveKeyInSessionStore("encryptionKey", key);redirectToAppHome();};diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsxindex d4a44f3b03..838aab96f5 100644--- a/web/packages/accounts/pages/credentials.tsx+++ b/web/packages/accounts/pages/credentials.tsx@@ -52,12 +52,7 @@ import {isFirstLogin,setIsFirstLogin,} from "@ente/shared/storage/localStorage/helpers";-import {- SESSION_KEYS,- getKey,- removeKey,- setKey,-} from "@ente/shared/storage/sessionStorage";+import { getKey, removeKey, setKey } from "@ente/shared/storage/sessionStorage";import type { KeyAttributes, User } from "@ente/shared/user/types";import { t } from "i18next";import { useRouter } from "next/router";@@ -126,7 +121,7 @@ const Page: React.FC = () => {return;}setUser(user);- let key = getKey(SESSION_KEYS.ENCRYPTION_KEY);+ let key = getKey("encryptionKey");const electron = globalThis.electron;if (!key && electron) {try {@@ -135,11 +130,7 @@ const Page: React.FC = () => {log.error("Failed to read master key from safe storage", e);}if (key) {- await saveKeyInSessionStore(- SESSION_KEYS.ENCRYPTION_KEY,- key,- true,- );+ await saveKeyInSessionStore("encryptionKey", key, true);}}const token = getToken();@@ -147,9 +138,8 @@ const Page: React.FC = () => {void router.push(appHomeRoute);return;}- const kekEncryptedAttributes: B64EncryptionResult = getKey(- SESSION_KEYS.KEY_ENCRYPTION_KEY,- );+ const kekEncryptedAttributes: B64EncryptionResult =+ getKey("keyEncryptionKey");const keyAttributes: KeyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES,);@@ -162,7 +152,7 @@ const Page: React.FC = () => {}if (kekEncryptedAttributes && keyAttributes) {- removeKey(SESSION_KEYS.KEY_ENCRYPTION_KEY);+ removeKey("keyEncryptionKey");const cryptoWorker = await sharedCryptoWorker();const kek = await cryptoWorker.decryptB64(kekEncryptedAttributes.encryptedData,@@ -231,10 +221,7 @@ const Page: React.FC = () => {if (passkeySessionID) {const sessionKeyAttributes =await cryptoWorker.generateKeyAndEncryptToB64(kek);- setKey(- SESSION_KEYS.KEY_ENCRYPTION_KEY,- sessionKeyAttributes,- );+ setKey("keyEncryptionKey", sessionKeyAttributes);const user = getData(LS_KEYS.USER);await setLSUser({...user,@@ -253,10 +240,7 @@ const Page: React.FC = () => {} else if (twoFactorSessionID) {const sessionKeyAttributes =await cryptoWorker.generateKeyAndEncryptToB64(kek);- setKey(- SESSION_KEYS.KEY_ENCRYPTION_KEY,- sessionKeyAttributes,- );+ setKey("keyEncryptionKey", sessionKeyAttributes);const user = getData(LS_KEYS.USER);await setLSUser({...user,@@ -304,7 +288,7 @@ const Page: React.FC = () => {key,);}- await saveKeyInSessionStore(SESSION_KEYS.ENCRYPTION_KEY, key);+ await saveKeyInSessionStore("encryptionKey", key);await decryptAndStoreToken(keyAttributes, key);try {let srpAttributes: SRPAttributes | null = getData(diff --git a/web/packages/accounts/pages/generate.tsx b/web/packages/accounts/pages/generate.tsxindex 3348ef9e55..5eea641c01 100644--- a/web/packages/accounts/pages/generate.tsx+++ b/web/packages/accounts/pages/generate.tsx@@ -26,7 +26,7 @@ import {justSignedUp,setJustSignedUp,} from "@ente/shared/storage/localStorage/helpers";-import { SESSION_KEYS, getKey } from "@ente/shared/storage/sessionStorage";+import { getKey } from "@ente/shared/storage/sessionStorage";import type { KeyAttributes, User } from "@ente/shared/user/types";import { t } from "i18next";import { useRouter } from "next/router";@@ -43,7 +43,7 @@ const Page: React.FC = () => {const router = useRouter();useEffect(() => {- const key: string = getKey(SESSION_KEYS.ENCRYPTION_KEY);+ const key: string = getKey("encryptionKey");const keyAttributes: KeyAttributes = getData(LS_KEYS.ORIGINAL_KEY_ATTRIBUTES,);@@ -82,7 +82,7 @@ const Page: React.FC = () => {keyAttributes,masterKey,);- await saveKeyInSessionStore(SESSION_KEYS.ENCRYPTION_KEY, masterKey);+ await saveKeyInSessionStore("encryptionKey", masterKey);setJustSignedUp(true);setOpenRecoveryKey(true);} catch (e) {diff --git a/web/packages/accounts/pages/recover.tsx b/web/packages/accounts/pages/recover.tsxindex 1777262908..a89a576366 100644--- a/web/packages/accounts/pages/recover.tsx+++ b/web/packages/accounts/pages/recover.tsx@@ -17,7 +17,7 @@ import {saveKeyInSessionStore,} from "@ente/shared/crypto/helpers";import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";-import { SESSION_KEYS, getKey } from "@ente/shared/storage/sessionStorage";+import { getKey } from "@ente/shared/storage/sessionStorage";import type { KeyAttributes, User } from "@ente/shared/user/types";import { t } from "i18next";import { useRouter } from "next/router";@@ -40,7 +40,7 @@ const Page: React.FC = () => {useEffect(() => {const user: User = getData(LS_KEYS.USER);const keyAttributes: KeyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES);- const key = getKey(SESSION_KEYS.ENCRYPTION_KEY);+ const key = getKey("encryptionKey");if (!user?.email) {void router.push("/");return;@@ -85,7 +85,7 @@ const Page: React.FC = () => {keyAttr.masterKeyDecryptionNonce!,await cryptoWorker.fromHex(recoveryKey),);- await saveKeyInSessionStore(SESSION_KEYS.ENCRYPTION_KEY, masterKey);+ await saveKeyInSessionStore("encryptionKey", masterKey);await decryptAndStoreToken(keyAttr, masterKey);setData(LS_KEYS.SHOW_BACK_BUTTON, { value: false });diff --git a/web/packages/base/session.ts b/web/packages/base/session.tsindex b3c2e7fd82..b416b8ed9a 100644--- a/web/packages/base/session.ts+++ b/web/packages/base/session.ts@@ -33,7 +33,7 @@ export const haveCredentialsInSession = () =>* logged in, otherwise return `undefined`.*/export const masterKeyFromSessionIfLoggedIn = async () => {- // TODO: Same value as the deprecated SESSION_KEYS.ENCRYPTION_KEY.+ // TODO: Same value as the deprecated getKey("encryptionKey")const value = sessionStorage.getItem("encryptionKey");if (!value) return undefined;diff --git a/web/packages/shared/crypto/helpers.ts b/web/packages/shared/crypto/helpers.tsindex 024f1ac0c2..f3c8df607e 100644--- a/web/packages/shared/crypto/helpers.ts+++ b/web/packages/shared/crypto/helpers.ts@@ -9,7 +9,7 @@ import {setLSUser,} from "@ente/shared/storage/localStorage";import { getToken } from "@ente/shared/storage/localStorage/helpers";-import { SESSION_KEYS, setKey } from "@ente/shared/storage/sessionStorage";+import { SessionKey, setKey } from "@ente/shared/storage/sessionStorage";import { getActualKey } from "@ente/shared/user";import type { KeyAttributes } from "@ente/shared/user/types";@@ -99,7 +99,7 @@ export const generateLoginSubKey = async (kek: string) => {};export const saveKeyInSessionStore = async (- keyType: SESSION_KEYS,+ keyType: SessionKey,key: string,fromDesktop?: boolean,) => {@@ -108,7 +108,7 @@ export const saveKeyInSessionStore = async (await cryptoWorker.generateKeyAndEncryptToB64(key);setKey(keyType, sessionKeyAttributes);const electron = globalThis.electron;- if (electron && !fromDesktop && keyType === SESSION_KEYS.ENCRYPTION_KEY) {+ if (electron && !fromDesktop && keyType == "encryptionKey") {electron.saveMasterKeyB64(key);}};diff --git a/web/packages/shared/storage/sessionStorage/index.ts b/web/packages/shared/storage/sessionStorage/index.tsindex b3de32d69a..7fbef7381a 100644--- a/web/packages/shared/storage/sessionStorage/index.ts+++ b/web/packages/shared/storage/sessionStorage/index.ts@@ -1,16 +1,13 @@-export enum SESSION_KEYS {- ENCRYPTION_KEY = "encryptionKey",- KEY_ENCRYPTION_KEY = "keyEncryptionKey",-}+export type SessionKey = "encryptionKey" | "keyEncryptionKey";-export const setKey = (key: SESSION_KEYS, value: object) =>+export const setKey = (key: SessionKey, value: object) =>sessionStorage.setItem(key, JSON.stringify(value));-export const getKey = (key: SESSION_KEYS) => {+export const getKey = (key: SessionKey) => {const value = sessionStorage.getItem(key);return value && JSON.parse(value);};-export const removeKey = (key: SESSION_KEYS) => sessionStorage.removeItem(key);+export const removeKey = (key: SessionKey) => sessionStorage.removeItem(key);export const clearKeys = () => sessionStorage.clear();diff --git a/web/packages/shared/user/index.ts b/web/packages/shared/user/index.tsindex a5a4a79070..572f90db7f 100644--- a/web/packages/shared/user/index.ts+++ b/web/packages/shared/user/index.ts@@ -1,13 +1,12 @@import { sharedCryptoWorker } from "@/base/crypto";import type { B64EncryptionResult } from "@/base/crypto/libsodium";import { CustomError } from "@ente/shared/error";-import { getKey, SESSION_KEYS } from "@ente/shared/storage/sessionStorage";+import { getKey } from "@ente/shared/storage/sessionStorage";export const getActualKey = async () => {try {- const encryptionKeyAttributes: B64EncryptionResult = getKey(- SESSION_KEYS.ENCRYPTION_KEY,- );+ const encryptionKeyAttributes: B64EncryptionResult =+ getKey("encryptionKey");const cryptoWorker = await sharedCryptoWorker();const key = await cryptoWorker.decryptB64(