Skip to content

armgit / ente

Public Imported from GitHub
0

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

Move

Manav Rathi1be2286279cd
diff --git a/web/apps/photos/src/components/DeleteAccount.tsx b/web/apps/photos/src/components/DeleteAccount.tsx
index d2fe559707..b7f59e9207 100644
--- a/web/apps/photos/src/components/DeleteAccount.tsx
+++ b/web/apps/photos/src/components/DeleteAccount.tsx
@@ -4,15 +4,13 @@ import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";
import { LoadingButton } from "@/base/components/mui/LoadingButton";
import type { ModalVisibilityProps } from "@/base/components/utils/modal";
import { useBaseContext } from "@/base/context";
-import { sharedCryptoWorker } from "@/base/crypto";
import {
DropdownInput,
type DropdownOption,
} from "@/new/photos/components/DropdownInput";
import { getAccountDeleteChallenge } from "@/new/photos/services/user";
import { initiateEmail } from "@/new/photos/utils/web";
-import { getData, LS_KEYS } from "@ente/shared/storage/localStorage";
-import { getActualKey } from "@ente/shared/user";
+import { decryptDeleteAccountChallenge } from "@ente/shared/crypto/helpers";
import {
Checkbox,
FormControlLabel,
@@ -276,21 +274,3 @@ const ConfirmationCheckboxInput: React.FC<ConfirmationCheckboxInputProps> = ({
/>
</FormGroup>
);
-
-async function decryptDeleteAccountChallenge(encryptedChallenge: string) {
- const cryptoWorker = await sharedCryptoWorker();
- const masterKey = await getActualKey();
- const keyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES);
- const secretKey = await cryptoWorker.decryptB64(
- keyAttributes.encryptedSecretKey,
- keyAttributes.secretKeyDecryptionNonce,
- masterKey,
- );
- const b64DecryptedChallenge = await cryptoWorker.boxSealOpen(
- encryptedChallenge,
- keyAttributes.publicKey,
- secretKey,
- );
- const utf8DecryptedChallenge = atob(b64DecryptedChallenge);
- return utf8DecryptedChallenge;
-}
diff --git a/web/packages/new/photos/services/user.ts b/web/packages/new/photos/services/user.ts
index fa416f6f45..5858a037a8 100644
--- a/web/packages/new/photos/services/user.ts
+++ b/web/packages/new/photos/services/user.ts
@@ -29,8 +29,8 @@ const DeleteChallengeResponse = z.object({
// allowDelete indicates whether the user is allowed to delete their account
// via app (some special-cased accounts might need to contact support).
allowDelete: z.boolean(),
- // An encrypted challenge that the client needs to decrypt before proceeding
- // with account deletion.
+ // An encrypted challenge that the client needs to decrypt and provide in
+ // the actual account deletion request.
encryptedChallenge: z.string().nullable().transform(nullToUndefined),
});
diff --git a/web/packages/shared/crypto/helpers.ts b/web/packages/shared/crypto/helpers.ts
index 15abcad3e1..a5ed61d8c5 100644
--- a/web/packages/shared/crypto/helpers.ts
+++ b/web/packages/shared/crypto/helpers.ts
@@ -180,3 +180,29 @@ async function createNewRecoveryKey() {
return recoveryKey;
}
+
+/**
+ * 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 getActualKey();
+ const keyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES);
+ const secretKey = await cryptoWorker.decryptB64(
+ keyAttributes.encryptedSecretKey,
+ keyAttributes.secretKeyDecryptionNonce,
+ masterKey,
+ );
+ const b64DecryptedChallenge = await cryptoWorker.boxSealOpen(
+ encryptedChallenge,
+ keyAttributes.publicKey,
+ secretKey,
+ );
+ const utf8DecryptedChallenge = atob(b64DecryptedChallenge);
+ return utf8DecryptedChallenge;
+};