π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Conv
Manav Rathi61d07242ad70
diff --git a/web/packages/accounts/pages/change-password.tsx b/web/packages/accounts/pages/change-password.tsxindex 80638af96e..79db68a1ec 100644--- a/web/packages/accounts/pages/change-password.tsx+++ b/web/packages/accounts/pages/change-password.tsx@@ -10,8 +10,7 @@ import { appHomeRoute, stashRedirect } from "ente-accounts/services/redirect";import {generateSRPSetupAttributes,getSRPAttributes,- srpSetupOrReconfigure,- updateSRPAndKeys,+ updateSRPAndKeyAttributes,type UpdatedKeyAttr,} from "ente-accounts/services/srp";import {@@ -22,7 +21,7 @@ import {} from "ente-accounts/services/user";import { LinkButton } from "ente-base/components/LinkButton";import { LoadingIndicator } from "ente-base/components/loaders";-import { sharedCryptoWorker } from "ente-base/crypto";+import { deriveSensitiveKey, encryptBox } from "ente-base/crypto";import { deriveKeyInsufficientMemoryErrorMessage } from "ente-base/crypto/types";import log from "ente-base/log";import {@@ -62,16 +61,14 @@ interface PageContentsProps {}const PageContents: React.FC<PageContentsProps> = ({ user }) => {- const token = user.token;-const router = useRouter();const onSubmit: SetPasswordFormProps["callback"] = async (- passphrase,+ password,setFieldError,) => {try {- await onSubmit2(passphrase);+ await onSubmit2(password);} catch (e) {log.error("Could not change password", e);setFieldError(@@ -84,18 +81,19 @@ const PageContents: React.FC<PageContentsProps> = ({ user }) => {}};- const onSubmit2 = async (passphrase: string) => {- const cryptoWorker = await sharedCryptoWorker();+ const onSubmit2 = async (password: string) => {const masterKey = await ensureMasterKeyFromSession();const keyAttributes = ensureSavedKeyAttributes();+const {key: kek,salt: kekSalt,opsLimit,memLimit,- } = await cryptoWorker.deriveSensitiveKey(passphrase);+ } = await deriveSensitiveKey(password);+const { encryptedData: encryptedKey, nonce: keyDecryptionNonce } =- await cryptoWorker.encryptBox(masterKey, kek);+ await encryptBox(masterKey, kek);const updatedKeyAttr: UpdatedKeyAttr = {encryptedKey,keyDecryptionNonce,@@ -104,10 +102,9 @@ const PageContents: React.FC<PageContentsProps> = ({ user }) => {memLimit,};- await srpSetupOrReconfigure(+ await updateSRPAndKeyAttributes(await generateSRPSetupAttributes(kek),- ({ setupID, srpM1 }) =>- updateSRPAndKeys(token, { setupID, srpM1, updatedKeyAttr }),+ updatedKeyAttr,);// Update the SRP attributes that are stored locally.@@ -117,7 +114,7 @@ const PageContents: React.FC<PageContentsProps> = ({ user }) => {}await generateAndSaveInteractiveKeyAttributes(- passphrase,+ password,{ ...keyAttributes, ...updatedKeyAttr },masterKey,);diff --git a/web/packages/accounts/services/srp.ts b/web/packages/accounts/services/srp.tsindex 80d734f42a..e1a13d05c4 100644--- a/web/packages/accounts/services/srp.ts+++ b/web/packages/accounts/services/srp.ts@@ -13,6 +13,7 @@ import log from "ente-base/log";import { apiURL } from "ente-base/origins";import { ApiError, CustomError } from "ente-shared/error";import HTTPService from "ente-shared/network/HTTPService";+import { getToken } from "ente-shared/storage/localStorage/helpers";import { SRP, SrpClient } from "fast-srp-hap";import { v4 as uuidv4 } from "uuid";import { z } from "zod/v4";@@ -391,7 +392,7 @@ type SRPSetupOrReconfigureExchangeCallback = ({** @param srpSetupAttributes SRP setup attributes.*/-export const srpSetupOrReconfigure = async (+const srpSetupOrReconfigure = async ({ srpSalt, srpUserID, srpVerifier, loginSubKey }: SRPSetupAttributes,exchangeCB: SRPSetupOrReconfigureExchangeCallback,) => {@@ -495,6 +496,10 @@ const completeSRPSetup = async (return CompleteSRPSetupResponse.parse(await res.json());};+/**+ * The subset of {@link KeyAttributes} that get updated when the user changes+ * their password.+ */export interface UpdatedKeyAttr {kekSalt: string;encryptedKey: string;@@ -503,6 +508,26 @@ export interface UpdatedKeyAttr {memLimit: number;}+/**+ * Update the user's affected key and SRP attributes when they change their+ * password.+ *+ * The flow on changing password is similar to the flow on initial SRP setup,+ * with some differences at the tail end of the flow. See: [Note: SRP setup].+ *+ * @param srpSetupAttributes Attributes for the user's updated SRP setup.+ *+ * @param updatedKeyAttr The subset of the user's key attributes which need to+ * be updated to reflect their changed password.+ */+export const updateSRPAndKeyAttributes = (+ srpSetupAttributes: SRPSetupAttributes,+ updatedKeyAttr: UpdatedKeyAttr,+) =>+ srpSetupOrReconfigure(srpSetupAttributes, ({ setupID, srpM1 }) =>+ updateSRPAndKeys({ setupID, srpM1, updatedKeyAttr }),+ );+export interface UpdateSRPAndKeysRequest {srpM1: string;setupID: string;@@ -520,7 +545,6 @@ export interface UpdateSRPAndKeysResponse {}export const updateSRPAndKeys = async (- token: string,updateSRPAndKeyRequest: UpdateSRPAndKeysRequest,): Promise<UpdateSRPAndKeysResponse> => {try {@@ -528,7 +552,7 @@ export const updateSRPAndKeys = async (await apiURL("/users/srp/update"),updateSRPAndKeyRequest,undefined,- { "X-Auth-Token": token },+ { "X-Auth-Token": getToken() },);return resp.data as UpdateSRPAndKeysResponse;} catch (e) {diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.tsindex ad75316b0d..b11cb3f9a8 100644--- a/web/packages/accounts/services/user.ts+++ b/web/packages/accounts/services/user.ts@@ -157,6 +157,15 @@ export const ensureExpectedLoggedInValue = <T>(t: T | undefined): T => {** The various "key" attributes are base64 encoded representations of the* underlying binary data.+ *+ * [Note: Key attribute mutability]+ *+ * The key attributes contain two subsets:+ *+ * - Attributes that changes when the user changes their password. These are the+ * {@link UpdatedKeyAttr}.+ *+ * - All other attributes never change after initial setup.*/export interface KeyAttributes {/**