Skip to content

armgit / ente

Public Imported from GitHub
0

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

Ensure SRP attributes are also present after signup

Manav Rathi2ffce031de37
diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx
index 6f5b710261..f2fffce221 100644
--- a/web/packages/accounts/pages/credentials.tsx
+++ b/web/packages/accounts/pages/credentials.tsx
@@ -34,6 +34,7 @@ import { checkSessionValidity } from "ente-accounts/services/session";
import type { SRPAttributes } from "ente-accounts/services/srp";
import {
generateSRPSetupAttributes,
+ getAndSaveSRPAttributes,
getSRPAttributes,
setupSRP,
verifySRP,
@@ -146,6 +147,7 @@ const Page: React.FC = () => {
saveSRPAttributes(srpAttributes);
} else {
await setupSRP(await generateSRPSetupAttributes(kek));
+ await getAndSaveSRPAttributes(userEmail);
}
}
} catch (e) {
diff --git a/web/packages/accounts/pages/generate.tsx b/web/packages/accounts/pages/generate.tsx
index d0b900dc45..e60f9085cd 100644
--- a/web/packages/accounts/pages/generate.tsx
+++ b/web/packages/accounts/pages/generate.tsx
@@ -14,6 +14,7 @@ import {
import { appHomeRoute } from "ente-accounts/services/redirect";
import {
generateSRPSetupAttributes,
+ getAndSaveSRPAttributes,
setupSRP,
} from "ente-accounts/services/srp";
import {
@@ -76,6 +77,7 @@ const Page: React.FC = () => {
await generateKeysAndAttributes(password);
await putUserKeyAttributes(keyAttributes);
await setupSRP(await generateSRPSetupAttributes(kek));
+ await getAndSaveSRPAttributes(userEmail);
await generateAndSaveInteractiveKeyAttributes(
password,
keyAttributes,
@@ -94,7 +96,7 @@ const Page: React.FC = () => {
);
}
},
- [],
+ [userEmail],
);
return (
diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsx
index 6a1806c41e..7ffcffa231 100644
--- a/web/packages/accounts/pages/verify.tsx
+++ b/web/packages/accounts/pages/verify.tsx
@@ -28,7 +28,11 @@ import {
stashedRedirect,
unstashRedirect,
} from "ente-accounts/services/redirect";
-import { getSRPAttributes, setupSRP } from "ente-accounts/services/srp";
+import {
+ getAndSaveSRPAttributes,
+ getSRPAttributes,
+ setupSRP,
+} from "ente-accounts/services/srp";
import {
putUserKeyAttributes,
sendOTT,
@@ -135,6 +139,7 @@ const Page: React.FC = () => {
await putUserKeyAttributes(originalKeyAttributes);
}
await unstashAfterUseSRPSetupAttributes(setupSRP);
+ await getAndSaveSRPAttributes(email);
}
saveIsFirstLogin();
if (keyAttributes) {
diff --git a/web/packages/accounts/services/session.ts b/web/packages/accounts/services/session.ts
index 8bfbc856eb..c2e6f76f35 100644
--- a/web/packages/accounts/services/session.ts
+++ b/web/packages/accounts/services/session.ts
@@ -96,7 +96,6 @@ export const checkSessionValidity = async (): Promise<SessionValidity> => {
// We should have these values locally if we reach here.
const email = ensureLocalUser().email;
- // TODO(RE): This is not being set until initial reauthentication.
const localSRPAttributes = savedSRPAttributes()!;
// Fetch the remote SRP attributes.
diff --git a/web/packages/accounts/services/srp.ts b/web/packages/accounts/services/srp.ts
index 7e3c1bf209..07930e5780 100644
--- a/web/packages/accounts/services/srp.ts
+++ b/web/packages/accounts/services/srp.ts
@@ -9,9 +9,11 @@ import {
publicRequestHeaders,
} from "ente-base/http";
import { apiURL } from "ente-base/origins";
+import { ensure } from "ente-utils/ensure";
import { SRP, SrpClient } from "fast-srp-hap";
import { v4 as uuidv4 } from "uuid";
import { z } from "zod/v4";
+import { saveSRPAttributes } from "./accounts-db";
import {
RemoteSRPVerificationResponse,
type EmailOrSRPVerificationResponse,
@@ -440,6 +442,20 @@ const completeSRPSetup = async (
return CompleteSRPSetupResponse.parse(await res.json());
};
+/**
+ * Fetch the SRP attributes from remote and use them to update the SRP
+ * attributes we have saved locally.
+ *
+ * This function is intended to be called after {@link srpSetupOrReconfigure} to
+ * also update our local state to match remote.
+ *
+ * @param userEmail The email of the user whose SRP attributes we want to fetch.
+ * This should be the email address of the logged in user, or the user who is
+ * going through the login / signup sequence currently.
+ */
+export const getAndSaveSRPAttributes = async (userEmail: string) =>
+ saveSRPAttributes(ensure(await getSRPAttributes(userEmail)));
+
/**
* The subset of {@link KeyAttributes} that get updated when the user changes
* their password.
diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.ts
index 91b1f1ea5f..9f66a92f6f 100644
--- a/web/packages/accounts/services/user.ts
+++ b/web/packages/accounts/services/user.ts
@@ -9,6 +9,7 @@ import {
} from "ente-accounts/services/accounts-db";
import {
generateSRPSetupAttributes,
+ getAndSaveSRPAttributes,
getSRPAttributes,
updateSRPAndKeyAttributes,
type UpdatedKeyAttr,
@@ -719,6 +720,8 @@ export const changePassword = async (password: string) => {
);
// Update SRP attributes locally.
+ await getAndSaveSRPAttributes(user.email);
+
const srpAttributes = await getSRPAttributes(user.email);
saveSRPAttributes(ensure(srpAttributes));