Ensure SRP attributes are also present after signup
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user