This commit is contained in:
Manav Rathi
2025-06-10 18:30:29 +05:30
parent fc9b2a186b
commit 6ff586c3e9

View File

@@ -258,6 +258,41 @@ export interface SRPSetupAttributes {
loginSubKey: string;
}
/**
*
* @param loginSubKey The user's SRP password (autogenerated, derived
* deterministically from their KEK by {@link deriveSRPPassword}).
*
* @returns
*/
export const generateSRPSetupAttributes = async (
loginSubKey: string,
): Promise<SRPSetupAttributes> => {
const cryptoWorker = await sharedCryptoWorker();
const srpSalt = await cryptoWorker.generateDeriveKeySalt();
// Museum schema requires this to be a UUID.
const srpUserID = uuidv4();
const srpVerifierBuffer = SRP.computeVerifier(
SRP.params["4096"],
convertBase64ToBuffer(srpSalt),
Buffer.from(srpUserID),
convertBase64ToBuffer(loginSubKey),
);
const srpVerifier = convertBufferToBase64(srpVerifierBuffer);
const result = { srpUserID, srpSalt, srpVerifier, loginSubKey };
log.debug(
() => `SRP setup attributes generated: ${JSON.stringify(result)}`,
);
return result;
};
interface SetupSRPRequest {
srpUserID: string;
srpSalt: string;
@@ -444,41 +479,6 @@ export const convertBase64ToBuffer = (base64: string) => {
return Buffer.from(base64, "base64");
};
/**
*
* @param loginSubKey The user's SRP password (autogenerated, derived
* deterministically from their KEK by {@link deriveSRPPassword}).
*
* @returns
*/
export const generateSRPSetupAttributes = async (
loginSubKey: string,
): Promise<SRPSetupAttributes> => {
const cryptoWorker = await sharedCryptoWorker();
const srpSalt = await cryptoWorker.generateDeriveKeySalt();
// Museum schema requires this to be a UUID.
const srpUserID = uuidv4();
const srpVerifierBuffer = SRP.computeVerifier(
SRP.params["4096"],
convertBase64ToBuffer(srpSalt),
Buffer.from(srpUserID),
convertBase64ToBuffer(loginSubKey),
);
const srpVerifier = convertBufferToBase64(srpVerifierBuffer);
const result = { srpUserID, srpSalt, srpVerifier, loginSubKey };
log.debug(
() => `SRP setup attributes generated: ${JSON.stringify(result)}`,
);
return result;
};
export const loginViaSRP = async (
srpAttributes: SRPAttributes,
kek: string,