π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move
Manav Rathi146db578b610
diff --git a/web/packages/new/photos/components/DeleteAccount.tsx b/web/packages/new/photos/components/DeleteAccount.tsxindex 9812f63c18..958685312a 100644--- a/web/packages/new/photos/components/DeleteAccount.tsx+++ b/web/packages/new/photos/components/DeleteAccount.tsx@@ -17,11 +17,11 @@ import {type DropdownOption,} from "ente-new/photos/components/DropdownInput";import {+ decryptDeleteAccountChallenge,deleteAccount,getAccountDeleteChallenge,} from "ente-new/photos/services/user";import { initiateEmail } from "ente-new/photos/utils/web";-import { decryptDeleteAccountChallenge } from "ente-shared/crypto/helpers";import { useFormik } from "formik";import { t } from "i18next";import React, { useState } from "react";diff --git a/web/packages/new/photos/services/user.ts b/web/packages/new/photos/services/user.tsindex d84bc2ae38..2f63f0ea53 100644--- a/web/packages/new/photos/services/user.ts+++ b/web/packages/new/photos/services/user.ts@@ -1,5 +1,8 @@+import { ensureSavedKeyAttributes } from "ente-accounts/services/user";+import { sharedCryptoWorker } from "ente-base/crypto";import { authenticatedRequestHeaders, ensureOk } from "ente-base/http";import { apiURL } from "ente-base/origins";+import { ensureMasterKeyFromSession } from "ente-base/session";import { nullToUndefined } from "ente-utils/transform";import { z } from "zod/v4";@@ -51,6 +54,20 @@ const DeleteChallengeResponse = z.object({encryptedChallenge: z.string().nullish().transform(nullToUndefined),});+/**+ * Initiate an account deletion by obtaining a delete challenge from remote.+ *+ * Account deletion is a three step process:+ *+ * 1. Client obtains a encrypted challenge from remote by using+ * {@link getAccountDeleteChallenge}.+ *+ * 2. Client asks the user to reverify their password to solve the challenge and+ * obtain the decrypted challenge ({@link decryptDeleteAccountChallenge}).+ *+ * 3. Client performs the account deletion using the solved challenge+ * ({@link deleteAccount}).+ */export const getAccountDeleteChallenge = async () => {const res = await fetch(await apiURL("/users/delete-challenge"), {headers: await authenticatedRequestHeaders(),@@ -59,6 +76,34 @@ export const getAccountDeleteChallenge = async () => {return DeleteChallengeResponse.parse(await res.json());};+/**+ * Decrypt the {@link encryptedChallenge} sent by remote during the delete+ * account flow ({@link getAccountDeleteChallenge}), returning a value that can+ * then directly be passed to the actual delete account request+ * ({@link deleteAccount}).+ */+export const decryptDeleteAccountChallenge = async (+ encryptedChallenge: string,+) => {+ const cryptoWorker = await sharedCryptoWorker();+ const masterKey = await ensureMasterKeyFromSession();+ const keyAttributes = ensureSavedKeyAttributes();+ const secretKey = await cryptoWorker.decryptBox(+ {+ encryptedData: keyAttributes.encryptedSecretKey,+ nonce: keyAttributes.secretKeyDecryptionNonce,+ },+ masterKey,+ );+ const b64DecryptedChallenge = await cryptoWorker.boxSealOpen(+ encryptedChallenge,+ keyAttributes.publicKey,+ secretKey,+ );+ const utf8DecryptedChallenge = atob(b64DecryptedChallenge);+ return utf8DecryptedChallenge;+};+/*** Delete the logged in user's account on remote.*diff --git a/web/packages/shared/crypto/helpers.ts b/web/packages/shared/crypto/helpers.tsindex 330cb91bf5..18685c0845 100644--- a/web/packages/shared/crypto/helpers.ts+++ b/web/packages/shared/crypto/helpers.ts@@ -1,9 +1,5 @@-import {- ensureSavedKeyAttributes,- type KeyAttributes,-} from "ente-accounts/services/user";+import { type KeyAttributes } from "ente-accounts/services/user";import { sharedCryptoWorker } from "ente-base/crypto";-import { ensureMasterKeyFromSession } from "ente-base/session";import { getData, setData, setLSUser } from "ente-shared/storage/localStorage";import { setKey, type SessionKey } from "ente-shared/storage/sessionStorage";@@ -79,31 +75,3 @@ export const saveKeyInSessionStore = async (electron.saveMasterKeyB64(key);}};--/**- * Decrypt the {@link encryptedChallenge} sent by remote during the delete- * account flow ({@link getAccountDeleteChallenge}), returning a value that can- * then directly be passed to the actual delete account request- * ({@link deleteAccount}).- */-export const decryptDeleteAccountChallenge = async (- encryptedChallenge: string,-) => {- const cryptoWorker = await sharedCryptoWorker();- const masterKey = await ensureMasterKeyFromSession();- const keyAttributes = ensureSavedKeyAttributes();- const secretKey = await cryptoWorker.decryptBox(- {- encryptedData: keyAttributes.encryptedSecretKey,- nonce: keyAttributes.secretKeyDecryptionNonce,- },- masterKey,- );- const b64DecryptedChallenge = await cryptoWorker.boxSealOpen(- encryptedChallenge,- keyAttributes.publicKey,- secretKey,- );- const utf8DecryptedChallenge = atob(b64DecryptedChallenge);- return utf8DecryptedChallenge;-};