π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Tweak
Manav Rathi5c0b3795c2e6
diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsxindex 960f01de0b..9547992de3 100644--- a/web/apps/photos/src/pages/_app.tsx+++ b/web/apps/photos/src/pages/_app.tsx@@ -130,7 +130,9 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {if (needsFamilyRedirect && savedPartialLocalUser()?.token)redirectToFamilyPortal();- router.events.on("routeChangeStart", () => {+ router.events.on("routeChangeStart", (url) => {+ if (process.env.NEXT_PUBLIC_ENTE_TRACE) console.log("route", url);+if (needsFamilyRedirect && savedPartialLocalUser()?.token) {redirectToFamilyPortal();diff --git a/web/packages/accounts/components/LoginContents.tsx b/web/packages/accounts/components/LoginContents.tsxindex f0677daa52..a741a235b5 100644--- a/web/packages/accounts/components/LoginContents.tsx+++ b/web/packages/accounts/components/LoginContents.tsx@@ -25,9 +25,10 @@ interface LoginContentsProps {}/**- * Contents of the "login form", maintained as a separate component so that the- * same code can be used both in the standalone /login page, and also within the- * embedded login form shown on the photos index page.+ * A contents of the "login" form.+ *+ * It is used both on the "/login" page, and as the embedded login form on the+ * "/" page where the user can toggle between the signup and login forms inline.*/export const LoginContents: React.FC<LoginContentsProps> = ({onSignUp,diff --git a/web/packages/accounts/components/SignUpContents.tsx b/web/packages/accounts/components/SignUpContents.tsxindex 3a04d6e7e2..bf82767f64 100644--- a/web/packages/accounts/components/SignUpContents.tsx+++ b/web/packages/accounts/components/SignUpContents.tsx@@ -55,6 +55,12 @@ interface SignUpContentsProps {host: string | undefined;}+/**+ * A contents of the "signup" form.+ *+ * It is used both on the "/signup" page itself, and as a subcomponent of the+ * "/" page where the user can toggle between the signup and login forms inline.+ */export const SignUpContents: React.FC<SignUpContentsProps> = ({router,onLogin,diff --git a/web/packages/accounts/components/VerifyMasterPasswordForm.tsx b/web/packages/accounts/components/VerifyMasterPasswordForm.tsxindex 1afb5edd76..c974886508 100644--- a/web/packages/accounts/components/VerifyMasterPasswordForm.tsx+++ b/web/packages/accounts/components/VerifyMasterPasswordForm.tsx@@ -58,6 +58,7 @@ export interface VerifyMasterPasswordFormProps {* exists.*/getKeyAttributes?: (+ srpAttributes: SRPAttributes,kek: string,) => Promise<KeyAttributes | "redirecting-second-factor" | undefined>;/**@@ -168,9 +169,9 @@ export const VerifyMasterPasswordForm: React.FC<}} else throw new Error("Both SRP and key attributes are missing");- if (!keyAttributes && getKeyAttributes) {+ if (!keyAttributes && getKeyAttributes && srpAttributes) {try {- const result = await getKeyAttributes(kek);+ const result = await getKeyAttributes(srpAttributes, kek);if (result == "redirecting-second-factor") {// Two factor enabled, user has been redirected to the// corresponding second factor verification page.diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsxindex 83866b478c..b94dcfcb41 100644--- a/web/packages/accounts/pages/credentials.tsx+++ b/web/packages/accounts/pages/credentials.tsx@@ -223,58 +223,62 @@ const Page: React.FC = () => {}, [router, validateSession, postVerification]);const getKeyAttributes: VerifyMasterPasswordFormProps["getKeyAttributes"] =- async (kek: string) => {- const {- id,- keyAttributes,- token,- encryptedToken,- twoFactorSessionID,- passkeySessionID,- accountsUrl,- } = await userVerificationResultAfterResolvingSecondFactorChoice(- await verifySRP(srpAttributes!, kek),- );-- // If we had to ask remote for the key attributes, it is the initial- // login on this client.- saveIsFirstLogin();-- if (passkeySessionID) {- await stashKeyEncryptionKeyInSessionStore(kek);- updateSavedLocalUser({ passkeySessionID });- stashRedirect("/");- const url = passkeyVerificationRedirectURL(- accountsUrl!,- passkeySessionID,- );- setPasskeyVerificationData({ passkeySessionID, url });- openPasskeyVerificationURL({ passkeySessionID, url });- return "redirecting-second-factor";- } else if (twoFactorSessionID) {- await stashKeyEncryptionKeyInSessionStore(kek);- updateSavedLocalUser({- isTwoFactorEnabled: true,- twoFactorSessionID,- });- void router.push("/two-factor/verify");- return "redirecting-second-factor";- } else {- // In rare cases, if the user hasn't already setup their key- // attributes, we might get the plaintext token from remote.- if (token) await saveAuthToken(token);- updateSavedLocalUser({+ useCallback(+ async (srpAttributes: SRPAttributes, kek: string) => {+ const {id,+ keyAttributes,token,encryptedToken,- isTwoFactorEnabled: undefined,- twoFactorSessionID: undefined,- passkeySessionID: undefined,- });- if (keyAttributes) saveKeyAttributes(keyAttributes);- return keyAttributes;- }- };+ twoFactorSessionID,+ passkeySessionID,+ accountsUrl,+ } =+ await userVerificationResultAfterResolvingSecondFactorChoice(+ await verifySRP(srpAttributes, kek),+ );++ // If we had to ask remote for the key attributes, it is the+ // initial login on this client.+ saveIsFirstLogin();++ if (passkeySessionID) {+ await stashKeyEncryptionKeyInSessionStore(kek);+ updateSavedLocalUser({ passkeySessionID });+ stashRedirect("/");+ const url = passkeyVerificationRedirectURL(+ accountsUrl!,+ passkeySessionID,+ );+ setPasskeyVerificationData({ passkeySessionID, url });+ openPasskeyVerificationURL({ passkeySessionID, url });+ return "redirecting-second-factor";+ } else if (twoFactorSessionID) {+ await stashKeyEncryptionKeyInSessionStore(kek);+ updateSavedLocalUser({+ isTwoFactorEnabled: true,+ twoFactorSessionID,+ });+ void router.push("/two-factor/verify");+ return "redirecting-second-factor";+ } else {+ // In rare cases, if the user hasn't already setup their key+ // attributes, we might get the plaintext token from remote.+ if (token) await saveAuthToken(token);+ updateSavedLocalUser({+ id,+ token,+ encryptedToken,+ isTwoFactorEnabled: undefined,+ twoFactorSessionID: undefined,+ passkeySessionID: undefined,+ });+ if (keyAttributes) saveKeyAttributes(keyAttributes);+ return keyAttributes;+ }+ },+ [userVerificationResultAfterResolvingSecondFactorChoice, router],+ );const handleVerifyMasterPassword: VerifyMasterPasswordFormProps["onVerify"] =useCallback(@@ -341,8 +345,6 @@ const Page: React.FC = () => {);}- // TODO: Handle the case when user is not present, or exclude that- // possibility using types.return (<AccountsPageContents><PasswordHeader caption={userEmail} />diff --git a/web/packages/accounts/pages/login.tsx b/web/packages/accounts/pages/login.tsxindex 2d92a600ee..2d3f37abc5 100644--- a/web/packages/accounts/pages/login.tsx+++ b/web/packages/accounts/pages/login.tsx@@ -40,17 +40,20 @@ import React, { useCallback, useEffect, useState } from "react";* - Redirects to "/" if there is no `email` present in the saved partial* local user.*- * - Redirects to "/credentials" if email verification is not needed, and also- * when email verification completes.+ * - Redirects to "/credentials" if both saved key attributes and a `token`+ * (or `encryptedToken`) in present in the saved partial local user, or if+ * email verification is not needed, or when email verification completes+ * and remote sent us key attributes (which will happen on login).*- * - Redirects to "/two-factor/verify" once email verification is complete if- * the user has setup an additional TOTP second factor that also needs to be- * verified.+ * - Redirects to "/generate" once email verification is complete and the user+ * does not have key attributes (which will happen for new signups).*- * - Redirects to the passkey app once email verification is complete if the- * user has setup an additional passkey that also needs to be verified.- * Before redirecting, it sets the `inflightPasskeySessionID` in session- * storage.+ * - Redirects to "/two-factor/verify" when email verification completes and+ * the user has setup a TOTP second factor that also needs to be verified.+ *+ * - Redirects to the passkey app when email verification completes and the+ * user has setup a passkey that also needs to be verified. Before+ * redirecting, `inflightPasskeySessionID` in saved in session storage.** - "/credentials" - A page that allows the user to enter their password to* authenticate (initial login) or reauthenticate (new web app tab)@@ -59,16 +62,16 @@ import React, { useCallback, useEffect, useState } from "react";* local user.** - Redirects to "/two-factor/verify" if saved key attributes are not present- * once password is verified and the user has setup an additional TOTP- * second factor that also needs to be verified.+ * once password is verified and the user has setup a TOTP second factor+ * that also needs to be verified.** - Redirects to the passkey app once password is verified if saved key- * attributes are not present if the user has setup an additional passkey- * that also needs to be verified. Before redirecting, it sets the- * `inflightPasskeySessionID` in session storage.+ * attributes are not present if the user has setup a passkey that also+ * needs to be verified. Before redirecting, `inflightPasskeySessionID` is+ * saved in session storage.*- * - Redirects to the `appHomeRoute` otherwise (e.g. /gallery). The flow is- * complete.+ * - Redirects to the `appHomeRoute` otherwise (e.g. /gallery). **The flow is+ * complete**.** - "/generate" - A page that allows the user to generate key attributes if* needed, and shows them their recovery key.diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsxindex 9eac4d569d..12c6cfa773 100644--- a/web/packages/accounts/pages/verify.tsx+++ b/web/packages/accounts/pages/verify.tsx@@ -46,7 +46,7 @@ import log from "ente-base/log";import { clearSessionStorage } from "ente-base/session";import { t } from "i18next";import { useRouter } from "next/router";-import { useEffect, useState } from "react";+import { useCallback, useEffect, useState } from "react";import { Trans } from "react-i18next";/**@@ -58,7 +58,9 @@ const Page: React.FC = () => {const { logout, showMiniDialog } = useBaseContext();const [email, setEmail] = useState("");- const [resend, setResend] = useState(0);+ const [resend, setResend] = useState<"enable" | "sending" | "sent">(+ "enable",+ );const [passkeyVerificationData, setPasskeyVerificationData] = useState<{ passkeySessionID: string; url: string } | undefined>();@@ -100,6 +102,7 @@ const Page: React.FC = () => {} = await userVerificationResultAfterResolvingSecondFactorChoice(await verifyEmail(email, ott, cleanedReferral),);+if (passkeySessionID) {updateSavedLocalUser({ passkeySessionID });saveIsFirstLogin();@@ -137,12 +140,11 @@ const Page: React.FC = () => {await unstashAfterUseSRPSetupAttributes(setupSRP);}saveIsFirstLogin();- const redirectURL = unstashRedirect();- if (keyAttributes?.encryptedKey) {+ if (keyAttributes) {clearSessionStorage();- void router.push(redirectURL ?? "/credentials");+ void router.push(unstashRedirect() ?? "/credentials");} else {- void router.push(redirectURL ?? "/generate");+ void router.push(unstashRedirect() ?? "/generate");}}} catch (e) {@@ -157,12 +159,12 @@ const Page: React.FC = () => {}};- const resendEmail = async () => {- setResend(1);+ const resendEmail = useCallback(async () => {+ setResend("sending");await sendOTT(email, undefined);- setResend(2);- setTimeout(() => setResend(0), 3000);- };+ setResend("sent");+ setTimeout(() => setResend("enable"), 3000);+ }, [email]);if (!email) {return <LoadingIndicator />;@@ -225,13 +227,13 @@ const Page: React.FC = () => {/><AccountsPageFooter>- {resend == 0 && (+ {resend == "enable" && (<LinkButton onClick={resendEmail}>{t("resend_code")}</LinkButton>)}- {resend == 1 && <span>{t("status_sending")}</span>}- {resend == 2 && <span>{t("status_sent")}</span>}+ {resend == "sending" && <span>{t("status_sending")}</span>}+ {resend == "sent" && <span>{t("status_sent")}</span>}<LinkButton onClick={logout}>{t("change_email")}</LinkButton></AccountsPageFooter>@@ -256,9 +258,7 @@ const redirectionIfNeededOrEmail = async () => {return "/";}- const keyAttributes = savedKeyAttributes();-- if (keyAttributes?.encryptedKey && (user.token || user.encryptedToken)) {+ if (savedKeyAttributes() && (user.token || user.encryptedToken)) {return "/credentials";}