Refactor
This commit is contained in:
@@ -8,13 +8,10 @@ import SetPasswordForm, {
|
||||
} from "ente-accounts/components/SetPasswordForm";
|
||||
import { appHomeRoute, stashRedirect } from "ente-accounts/services/redirect";
|
||||
import {
|
||||
convertBase64ToBuffer,
|
||||
convertBufferToBase64,
|
||||
deriveSRPPassword,
|
||||
generateSRPClient,
|
||||
generateSRPSetupAttributes,
|
||||
getSRPAttributes,
|
||||
startSRPSetup,
|
||||
srpSetupOrReconfigure,
|
||||
updateSRPAndKeys,
|
||||
type UpdatedKeyAttr,
|
||||
} from "ente-accounts/services/srp";
|
||||
@@ -113,27 +110,12 @@ const PageContents: React.FC<PageContentsProps> = ({ user }) => {
|
||||
const { srpUserID, srpSalt, srpVerifier } =
|
||||
await generateSRPSetupAttributes(loginSubKey);
|
||||
|
||||
const srpClient = await generateSRPClient(
|
||||
srpSalt,
|
||||
srpUserID,
|
||||
loginSubKey,
|
||||
await srpSetupOrReconfigure(
|
||||
{ srpSalt, srpUserID, srpVerifier, loginSubKey },
|
||||
({ setupID, srpM1 }) =>
|
||||
updateSRPAndKeys(token, { setupID, srpM1, updatedKeyAttr }),
|
||||
);
|
||||
|
||||
const srpA = convertBufferToBase64(srpClient.computeA());
|
||||
|
||||
const { setupID, srpB } = await startSRPSetup(token, {
|
||||
srpUserID,
|
||||
srpSalt,
|
||||
srpVerifier,
|
||||
srpA,
|
||||
});
|
||||
|
||||
srpClient.setB(convertBase64ToBuffer(srpB));
|
||||
|
||||
const srpM1 = convertBufferToBase64(srpClient.computeM1());
|
||||
|
||||
await updateSRPAndKeys(token, { setupID, srpM1, updatedKeyAttr });
|
||||
|
||||
// Update the SRP attributes that are stored locally.
|
||||
const srpAttributes = await getSRPAttributes(user.email);
|
||||
if (srpAttributes) {
|
||||
|
||||
@@ -171,41 +171,40 @@ export const updateSRPAndKeys = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const configureSRP = async ({
|
||||
srpSalt,
|
||||
srpUserID,
|
||||
srpVerifier,
|
||||
loginSubKey,
|
||||
}: SRPSetupAttributes) => {
|
||||
try {
|
||||
const srpClient = await generateSRPClient(
|
||||
srpSalt,
|
||||
srpUserID,
|
||||
loginSubKey,
|
||||
);
|
||||
export const configureSRP = async (attr: SRPSetupAttributes) =>
|
||||
srpSetupOrReconfigure(attr, (cbAttr) =>
|
||||
completeSRPSetup(getToken(), cbAttr),
|
||||
);
|
||||
|
||||
const srpA = convertBufferToBase64(srpClient.computeA());
|
||||
export const srpSetupOrReconfigure = async (
|
||||
{ srpSalt, srpUserID, srpVerifier, loginSubKey }: SRPSetupAttributes,
|
||||
cb: ({
|
||||
setupID,
|
||||
srpM1,
|
||||
}: {
|
||||
setupID: string;
|
||||
srpM1: string;
|
||||
}) => Promise<{ srpM2: string }>,
|
||||
) => {
|
||||
const srpClient = await generateSRPClient(srpSalt, srpUserID, loginSubKey);
|
||||
|
||||
log.debug(() => `srp a: ${srpA}`);
|
||||
const token = getToken();
|
||||
const { setupID, srpB } = await startSRPSetup(token, {
|
||||
srpA,
|
||||
srpUserID,
|
||||
srpSalt,
|
||||
srpVerifier,
|
||||
});
|
||||
const srpA = convertBufferToBase64(srpClient.computeA());
|
||||
|
||||
srpClient.setB(convertBase64ToBuffer(srpB));
|
||||
const token = getToken();
|
||||
const { setupID, srpB } = await startSRPSetup(token, {
|
||||
srpA,
|
||||
srpUserID,
|
||||
srpSalt,
|
||||
srpVerifier,
|
||||
});
|
||||
|
||||
const srpM1 = convertBufferToBase64(srpClient.computeM1());
|
||||
srpClient.setB(convertBase64ToBuffer(srpB));
|
||||
|
||||
const { srpM2 } = await completeSRPSetup(token, { srpM1, setupID });
|
||||
const srpM1 = convertBufferToBase64(srpClient.computeM1());
|
||||
|
||||
srpClient.checkM2(convertBase64ToBuffer(srpM2));
|
||||
} catch (e) {
|
||||
log.error("Failed to configure SRP", e);
|
||||
throw e;
|
||||
}
|
||||
const { srpM2 } = await cb({ srpM1, setupID });
|
||||
|
||||
srpClient.checkM2(convertBase64ToBuffer(srpM2));
|
||||
};
|
||||
|
||||
export const generateSRPClient = async (
|
||||
|
||||
Reference in New Issue
Block a user