π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move and rename
Manav Rathi29ac7b7df960
diff --git a/web/packages/accounts/components/SignUpContents.tsx b/web/packages/accounts/components/SignUpContents.tsxindex cfa44dab7b..6a441c16f6 100644--- a/web/packages/accounts/components/SignUpContents.tsx+++ b/web/packages/accounts/components/SignUpContents.tsx@@ -18,10 +18,11 @@ import {generateSRPSetupAttributes,} from "ente-accounts/services/srp";import {+ generateAndSaveInteractiveKeyAttributes,generateKeysAndAttributes,sendOTT,} from "ente-accounts/services/user";-import { generateAndSaveIntermediateKeyAttributes } from "ente-accounts/utils/helpers";+import { isWeakPassword } from "ente-accounts/utils/password";import { LinkButton } from "ente-base/components/LinkButton";import { LoadingButton } from "ente-base/components/mui/LoadingButton";@@ -111,7 +112,7 @@ export const SignUpContents: React.FC<SignUpContentsProps> = ({setData("originalKeyAttributes", keyAttributes);setData("srpSetupAttributes", srpSetupAttributes);- await generateAndSaveIntermediateKeyAttributes(+ await generateAndSaveInteractiveKeyAttributes(passphrase,keyAttributes,masterKey,diff --git a/web/packages/accounts/pages/change-password.tsx b/web/packages/accounts/pages/change-password.tsxindex 8c1c00ca68..42bded9e74 100644--- a/web/packages/accounts/pages/change-password.tsx+++ b/web/packages/accounts/pages/change-password.tsx@@ -17,10 +17,10 @@ import {} from "ente-accounts/services/srp";import {ensureSavedKeyAttributes,+ generateAndSaveInteractiveKeyAttributes,localUser,type LocalUser,} from "ente-accounts/services/user";-import { generateAndSaveIntermediateKeyAttributes } from "ente-accounts/utils/helpers";import { LinkButton } from "ente-base/components/LinkButton";import { LoadingIndicator } from "ente-base/components/loaders";import { sharedCryptoWorker } from "ente-base/crypto";@@ -122,7 +122,7 @@ const PageContents: React.FC<PageContentsProps> = ({ user }) => {setData("srpAttributes", srpAttributes);}- await generateAndSaveIntermediateKeyAttributes(+ await generateAndSaveInteractiveKeyAttributes(passphrase,{ ...keyAttributes, ...updatedKeyAttr },masterKey,diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsxindex e2a527ef40..99b99127d9 100644--- a/web/packages/accounts/pages/credentials.tsx+++ b/web/packages/accounts/pages/credentials.tsx@@ -21,15 +21,15 @@ import {unstashRedirect,} from "ente-accounts/services/redirect";import { checkSessionValidity } from "ente-accounts/services/session";+import type { SRPAttributes } from "ente-accounts/services/srp";import {configureSRP,deriveSRPPassword,generateSRPSetupAttributes,getSRPAttributes,loginViaSRP,- type SRPAttributes,} from "ente-accounts/services/srp";-import type { KeyAttributes, User } from "ente-accounts/services/user";+import { generateAndSaveInteractiveKeyAttributes, type KeyAttributes, type User } from "ente-accounts/services/user";import {decryptAndStoreToken,generateAndSaveIntermediateKeyAttributes,@@ -243,7 +243,7 @@ const Page: React.FC = () => {(key, kek, keyAttributes, passphrase) => {void (async () => {if (isFirstLogin()) {- await generateAndSaveIntermediateKeyAttributes(+ await generateAndSaveInteractiveKeyAttributes(passphrase,keyAttributes,key,diff --git a/web/packages/accounts/pages/generate.tsx b/web/packages/accounts/pages/generate.tsxindex c5993eb2cb..1b6f0ec2f0 100644--- a/web/packages/accounts/pages/generate.tsx+++ b/web/packages/accounts/pages/generate.tsx@@ -15,10 +15,10 @@ import {} from "ente-accounts/services/srp";import type { KeyAttributes, User } from "ente-accounts/services/user";import {+ generateAndSaveInteractiveKeyAttributes,generateKeysAndAttributes,putUserKeyAttributes,} from "ente-accounts/services/user";-import { generateAndSaveIntermediateKeyAttributes } from "ente-accounts/utils/helpers";import { LinkButton } from "ente-base/components/LinkButton";import { LoadingIndicator } from "ente-base/components/loaders";import { useBaseContext } from "ente-base/context";@@ -80,7 +80,7 @@ const Page: React.FC = () => {await putUserKeyAttributes(keyAttributes);await configureSRP(srpSetupAttributes);- await generateAndSaveIntermediateKeyAttributes(+ await generateAndSaveInteractiveKeyAttributes(passphrase,keyAttributes,masterKey,diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.tsindex 6f86e287e8..fc12947ee8 100644--- a/web/packages/accounts/services/user.ts+++ b/web/packages/accounts/services/user.ts@@ -4,6 +4,7 @@ import {encryptBox,generateKey,generateKeyPair,+ sharedCryptoWorker,} from "ente-base/crypto";import {authenticatedRequestHeaders,@@ -12,7 +13,7 @@ import {} from "ente-base/http";import { apiURL } from "ente-base/origins";import { getAuthToken } from "ente-base/token";-import { getData, setLSUser } from "ente-shared/storage/localStorage";+import { getData, setData, setLSUser } from "ente-shared/storage/localStorage";import { nullToUndefined } from "ente-utils/transform";import { z } from "zod/v4";import { getUserRecoveryKey, recoveryKeyFromMnemonic } from "./recovery-key";@@ -569,6 +570,36 @@ export const remoteLogoutIfNeeded = async () => {ensureOk(res);};+/**+ * Encrypt the user's masterKey with an intermediate kek (key encryption key)+ * derived from the passphrase (with interactive mem and ops limits) to avoid+ * saving it to local storage in plain text.+ *+ * This means that on the web user will always have to enter their passphrase to+ * access their masterKey when repopening the app in a new tab (on desktop we+ * can use OS storage, see [Note: Safe storage and interactive KEK attributes]).+ */+export async function generateAndSaveInteractiveKeyAttributes(+ passphrase: string,+ existingKeyAttributes: KeyAttributes,+ key: string,+): Promise<KeyAttributes> {+ const cryptoWorker = await sharedCryptoWorker();+ const intermediateKek = await cryptoWorker.deriveInteractiveKey(passphrase);+ const { encryptedData: encryptedKey, nonce: keyDecryptionNonce } =+ await cryptoWorker.encryptBox(key, intermediateKek.key);++ const intermediateKeyAttributes = Object.assign(existingKeyAttributes, {+ encryptedKey,+ keyDecryptionNonce,+ kekSalt: intermediateKek.salt,+ opsLimit: intermediateKek.opsLimit,+ memLimit: intermediateKek.memLimit,+ });+ setData("keyAttributes", intermediateKeyAttributes);+ return intermediateKeyAttributes;+}+/*** Change the email associated with the user's account on remote.*diff --git a/web/packages/accounts/utils/helpers.ts b/web/packages/accounts/utils/helpers.tsindex 3220cb0698..b00d1ec663 100644--- a/web/packages/accounts/utils/helpers.ts+++ b/web/packages/accounts/utils/helpers.ts@@ -39,32 +39,3 @@ export async function decryptAndStoreToken(}}-/**- * Encrypt the user's masterKey with an intermediate kek (key encryption key)- * derived from the passphrase (with interactive mem and ops limits) to avoid- * saving it to local storage in plain text.- *- * This means that on the web user will always have to enter their passphrase to- * access their masterKey when repopening the app in a new tab (on desktop we- * can use OS storage, see [Note: Safe storage and interactive KEK attributes]).- */-export async function generateAndSaveIntermediateKeyAttributes(- passphrase: string,- existingKeyAttributes: KeyAttributes,- key: string,-): Promise<KeyAttributes> {- const cryptoWorker = await sharedCryptoWorker();- const intermediateKek = await cryptoWorker.deriveInteractiveKey(passphrase);- const { encryptedData: encryptedKey, nonce: keyDecryptionNonce } =- await cryptoWorker.encryptBox(key, intermediateKek.key);-- const intermediateKeyAttributes = Object.assign(existingKeyAttributes, {- encryptedKey,- keyDecryptionNonce,- kekSalt: intermediateKek.salt,- opsLimit: intermediateKek.opsLimit,- memLimit: intermediateKek.memLimit,- });- setData("keyAttributes", intermediateKeyAttributes);- return intermediateKeyAttributes;-}