Skip to content

armgit / ente

Public Imported from GitHub
0

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

tweak

Manav Rathia244140348da
diff --git a/web/apps/photos/src/components/AuthenticateUser.tsx b/web/apps/photos/src/components/AuthenticateUser.tsx
index 2425422d22..6ecc64af71 100644
--- a/web/apps/photos/src/components/AuthenticateUser.tsx
+++ b/web/apps/photos/src/components/AuthenticateUser.tsx
@@ -99,7 +99,7 @@ export const AuthenticateUser: React.FC<AuthenticateUserProps> = ({
user={user}
keyAttributes={keyAttributes}
submitButtonTitle={t("authenticate")}
- onSubmit={() => {
+ onVerify={() => {
onClose();
onAuthenticate();
}}
diff --git a/web/packages/accounts/components/VerifyMasterPasswordForm.tsx b/web/packages/accounts/components/VerifyMasterPasswordForm.tsx
index 19fd416470..62b4c7c9aa 100644
--- a/web/packages/accounts/components/VerifyMasterPasswordForm.tsx
+++ b/web/packages/accounts/components/VerifyMasterPasswordForm.tsx
@@ -4,11 +4,11 @@ import { LoadingButton } from "ente-base/components/mui/LoadingButton";
import { ShowHidePasswordInputAdornment } from "ente-base/components/mui/PasswordInputAdornment";
import { sharedCryptoWorker } from "ente-base/crypto";
import log from "ente-base/log";
+import { CustomError } from "ente-shared/error";
+import type { KeyAttributes, User } from "ente-shared/user/types";
import { useFormik } from "formik";
import { t } from "i18next";
import { useCallback, useState } from "react";
-import { CustomError } from "ente-shared/error"
-import type { KeyAttributes, User } from "ente-shared/user/types";
export interface VerifyMasterPasswordFormProps {
/**
@@ -42,16 +42,22 @@ export interface VerifyMasterPasswordFormProps {
* 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 key The user's master key obtained after decrypting it from their
+ * passphrase.
+ *
* @param kek
+ *
* @param keyAttributes
- * @param passphrase The plaintext password
+ *
+ * @param passphrase The plaintext passphrase. This can be used during login
+ * to derive another encrypted key using interactive mem/ops limits for
+ * faster reauthentication after the initial login.
*/
- onSubmit: (
+ onVerify: (
key: string,
kek: string,
keyAttributes: KeyAttributes,
- passphrase?: string,
+ passphrase: string,
) => void;
}
@@ -66,7 +72,7 @@ export const VerifyMasterPasswordForm: React.FC<
keyAttributes,
srpAttributes,
getKeyAttributes,
- onSubmit,
+ onVerify,
submitButtonTitle,
}) => {
const [showPassword, setShowPassword] = useState(false);
@@ -131,7 +137,7 @@ export const VerifyMasterPasswordForm: React.FC<
keyAttributes.keyDecryptionNonce,
kek,
);
- onSubmit(key, kek, keyAttributes, passphrase);
+ onVerify(key, kek, keyAttributes, passphrase);
} catch (e) {
log.error("user entered a wrong password", e);
throw Error(CustomError.INCORRECT_PASSWORD);
diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx
index ccd36cbdd5..77f4c1feec 100644
--- a/web/packages/accounts/pages/credentials.tsx
+++ b/web/packages/accounts/pages/credentials.tsx
@@ -150,8 +150,7 @@ const Page: React.FC = () => {
keyAttributes.keyDecryptionNonce,
kek,
);
- // eslint-disable-next-line react-hooks/rules-of-hooks
- useMasterPassword(key, kek, keyAttributes);
+ void postVerification(key, kek, keyAttributes);
return;
}
if (keyAttributes) {
@@ -258,46 +257,46 @@ const Page: React.FC = () => {
}
};
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
- const useMasterPassword: VerifyMasterPasswordFormProps["onSubmit"] = async (
- key,
- kek,
- keyAttributes,
- passphrase,
+ const handleVerifyMasterPassword: VerifyMasterPasswordFormProps["onVerify"] =
+ (key, kek, keyAttributes, passphrase) => {
+ void (async () => {
+ if (isFirstLogin()) {
+ await generateAndSaveIntermediateKeyAttributes(
+ passphrase,
+ keyAttributes,
+ key,
+ );
+ }
+ await postVerification(key, kek, keyAttributes);
+ })();
+ };
+
+ const postVerification = async (
+ key: string,
+ kek: string,
+ keyAttributes: KeyAttributes,
) => {
+ await saveKeyInSessionStore("encryptionKey", key);
+ await decryptAndStoreToken(keyAttributes, key);
try {
- if (isFirstLogin() && passphrase) {
- await generateAndSaveIntermediateKeyAttributes(
- passphrase,
- keyAttributes,
- key,
- );
- }
- await saveKeyInSessionStore("encryptionKey", key);
- await decryptAndStoreToken(keyAttributes, key);
- try {
- let srpAttributes: SRPAttributes | null =
- getData("srpAttributes");
- if (!srpAttributes && user) {
- srpAttributes = await getSRPAttributes(user.email);
- if (srpAttributes) {
- setData("srpAttributes", srpAttributes);
- }
- }
- log.debug(() => `userSRPSetupPending ${!srpAttributes}`);
- if (!srpAttributes) {
- const loginSubKey = await generateLoginSubKey(kek);
- const srpSetupAttributes =
- await generateSRPSetupAttributes(loginSubKey);
- await configureSRP(srpSetupAttributes);
+ let srpAttributes: SRPAttributes | null = getData("srpAttributes");
+ if (!srpAttributes && user) {
+ srpAttributes = await getSRPAttributes(user.email);
+ if (srpAttributes) {
+ setData("srpAttributes", srpAttributes);
}
- } catch (e) {
- log.error("migrate to srp failed", e);
}
- void router.push(unstashRedirect() ?? appHomeRoute);
+ log.debug(() => `userSRPSetupPending ${!srpAttributes}`);
+ if (!srpAttributes) {
+ const loginSubKey = await generateLoginSubKey(kek);
+ const srpSetupAttributes =
+ await generateSRPSetupAttributes(loginSubKey);
+ await configureSRP(srpSetupAttributes);
+ }
} catch (e) {
- log.error("useMasterPassword failed", e);
+ log.error("migrate to srp failed", e);
}
+ void router.push(unstashRedirect() ?? appHomeRoute);
};
if (!keyAttributes && !srpAttributes) {
@@ -341,7 +340,7 @@ const Page: React.FC = () => {
getKeyAttributes={getKeyAttributes}
srpAttributes={srpAttributes}
submitButtonTitle={t("sign_in")}
- onSubmit={useMasterPassword}
+ onVerify={handleVerifyMasterPassword}
/>
<AccountsPageFooterWithHost>
<LinkButton onClick={() => router.push("/recover")}>