π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Document and move
Manav Rathid65424cef21c
diff --git a/web/apps/photos/src/components/AuthenticateUser.tsx b/web/apps/photos/src/components/AuthenticateUser.tsxindex 2c02479bef..2425422d22 100644--- a/web/apps/photos/src/components/AuthenticateUser.tsx+++ b/web/apps/photos/src/components/AuthenticateUser.tsx@@ -1,3 +1,4 @@+import { VerifyMasterPasswordForm } from "ente-accounts/components/VerifyMasterPasswordForm";import { checkSessionValidity } from "ente-accounts/services/session";import {TitledMiniDialog,@@ -6,9 +7,6 @@ import {import type { ModalVisibilityProps } from "ente-base/components/utils/modal";import { useBaseContext } from "ente-base/context";import log from "ente-base/log";-import VerifyMasterPasswordForm, {- type VerifyMasterPasswordFormProps,-} from "ente-shared/components/VerifyMasterPasswordForm";import { getData } from "ente-shared/storage/localStorage";import type { KeyAttributes, User } from "ente-shared/user/types";import { t } from "i18next";@@ -90,12 +88,6 @@ export const AuthenticateUser: React.FC<AuthenticateUserProps> = ({if (open) void validateSession();}, [open]);- const useMasterPassword: VerifyMasterPasswordFormProps["callback"] =- async () => {- onClose();- onAuthenticate();- };-return (<TitledMiniDialogopen={open}@@ -104,11 +96,13 @@ export const AuthenticateUser: React.FC<AuthenticateUserProps> = ({title={t("password")}><VerifyMasterPasswordForm- buttonText={t("authenticate")}- callback={useMasterPassword}user={user}keyAttributes={keyAttributes}- submitButtonProps={{ sx: { mb: 0 } }}+ submitButtonTitle={t("authenticate")}+ onSubmit={() => {+ onClose();+ onAuthenticate();+ }}/></TitledMiniDialog>);diff --git a/web/packages/shared/components/VerifyMasterPasswordForm.tsx b/web/packages/accounts/components/VerifyMasterPasswordForm.tsxsimilarity index 86%rename from web/packages/shared/components/VerifyMasterPasswordForm.tsxrename to web/packages/accounts/components/VerifyMasterPasswordForm.tsxindex 619c668912..19fd416470 100644--- a/web/packages/shared/components/VerifyMasterPasswordForm.tsx+++ b/web/packages/accounts/components/VerifyMasterPasswordForm.tsx@@ -1,4 +1,4 @@-import { Input, TextField, type ButtonProps } from "@mui/material";+import { Input, TextField } from "@mui/material";import type { SRPAttributes } from "ente-accounts/services/srp-remote";import { LoadingButton } from "ente-base/components/mui/LoadingButton";import { ShowHidePasswordInputAdornment } from "ente-base/components/mui/PasswordInputAdornment";@@ -7,18 +7,14 @@ import log from "ente-base/log";import { useFormik } from "formik";import { t } from "i18next";import { useCallback, useState } from "react";-import { CustomError } from "../error";-import type { KeyAttributes, User } from "../user/types";+import { CustomError } from "ente-shared/error"+import type { KeyAttributes, User } from "ente-shared/user/types";export interface VerifyMasterPasswordFormProps {+ /**+ * The user whose password we're trying to verify.+ */user: User | undefined;- callback: (- key: string,- kek: string,- keyAttributes: KeyAttributes,- passphrase?: string,- ) => void;- buttonText: string;keyAttributes: KeyAttributes | undefined;/*** A callback invoked when the form wants to get {@link KeyAttributes}.@@ -38,18 +34,41 @@ export interface VerifyMasterPasswordFormProps {*/getKeyAttributes?: (kek: string) => Promise<KeyAttributes | undefined>;srpAttributes?: SRPAttributes;- submitButtonProps?: ButtonProps;+ /**+ * The title of the submit button no the form.+ */+ submitButtonTitle: string;+ /**+ * The callback invoked with the verified password, and all the other+ * auxillary information that was ascertained when verifying it.+ *+ * @param key The user's master key+ * @param kek+ * @param keyAttributes+ * @param passphrase The plaintext password+ */+ onSubmit: (+ key: string,+ kek: string,+ keyAttributes: KeyAttributes,+ passphrase?: string,+ ) => void;}-export default function VerifyMasterPasswordForm({+/**+ * A form with a text field that can be used to ask the user to verify their+ * password.+ */+export const VerifyMasterPasswordForm: React.FC<+ VerifyMasterPasswordFormProps+> = ({user,keyAttributes,srpAttributes,- callback,- buttonText,- submitButtonProps,getKeyAttributes,-}: VerifyMasterPasswordFormProps) {+ onSubmit,+ submitButtonTitle,+}) => {const [showPassword, setShowPassword] = useState(false);const handleToggleShowHidePassword = useCallback(@@ -112,7 +131,7 @@ export default function VerifyMasterPasswordForm({keyAttributes.keyDecryptionNonce,kek,);- callback(key, kek, keyAttributes, passphrase);+ onSubmit(key, kek, keyAttributes, passphrase);} catch (e) {log.error("user entered a wrong password", e);throw Error(CustomError.INCORRECT_PASSWORD);@@ -180,10 +199,9 @@ export default function VerifyMasterPasswordForm({type="submit"loading={formik.isSubmitting}color={"accent"}- {...submitButtonProps}>- {buttonText}+ {submitButtonTitle}</LoadingButton></form>);-}+};diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsxindex c0f9013394..90a741418e 100644--- a/web/packages/accounts/pages/credentials.tsx+++ b/web/packages/accounts/pages/credentials.tsx@@ -7,6 +7,10 @@ import {import { SecondFactorChoice } from "ente-accounts/components/SecondFactorChoice";import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";import { useSecondFactorChoiceIfNeeded } from "ente-accounts/components/utils/second-factor-choice";+import {+ VerifyMasterPasswordForm,+ type VerifyMasterPasswordFormProps,+} from "ente-accounts/components/VerifyMasterPasswordForm";import {openPasskeyVerificationURL,passkeyVerificationRedirectURL,@@ -31,9 +35,6 @@ import { sharedCryptoWorker } from "ente-base/crypto";import type { B64EncryptionResult } from "ente-base/crypto/libsodium";import { clearLocalStorage } from "ente-base/local-storage";import log from "ente-base/log";-import VerifyMasterPasswordForm, {- type VerifyMasterPasswordFormProps,-} from "ente-shared/components/VerifyMasterPasswordForm";import {decryptAndStoreToken,generateAndSaveIntermediateKeyAttributes,@@ -258,7 +259,7 @@ const Page: React.FC = () => {};// eslint-disable-next-line @typescript-eslint/no-misused-promises- const useMasterPassword: VerifyMasterPasswordFormProps["callback"] = async (+ const useMasterPassword: VerifyMasterPasswordFormProps["onSubmit"] = async (key,kek,keyAttributes,@@ -334,16 +335,14 @@ const Page: React.FC = () => {return (<AccountsPageContents><PasswordHeader>{user?.email ?? ""}</PasswordHeader>-<VerifyMasterPasswordForm- buttonText={t("sign_in")}- callback={useMasterPassword}user={user}keyAttributes={keyAttributes}getKeyAttributes={getKeyAttributes}srpAttributes={srpAttributes}+ submitButtonTitle={t("sign_in")}+ onSubmit={useMasterPassword}/>-<AccountsPageFooterWithHost><LinkButton onClick={() => router.push("/recover")}>{t("forgot_password")}