Ensure SRP attributes are also present after signup

This commit is contained in:
Manav Rathi
2025-07-04 12:06:46 +05:30
parent d4d29d1957
commit 2ffce031de
6 changed files with 30 additions and 3 deletions

View File

@@ -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) {

View File

@@ -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 (

View File

@@ -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) {

View File

@@ -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.

View File

@@ -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.

View File

@@ -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));