π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Doc and cleanup
Manav Rathi4dc424464e13
diff --git a/web/docs/webauthn-passkeys.md b/web/docs/webauthn-passkeys.mdindex 39cc57ad53..b994fc98e4 100644--- a/web/docs/webauthn-passkeys.md+++ b/web/docs/webauthn-passkeys.md@@ -293,8 +293,7 @@ const {// ...twoFactorSessionID,passkeySessionID,-} = await loginViaSRP(srpAttributes, kek);-setIsFirstLogin(true);+} = await verifySRP(srpAttributes, kek);if (passkeySessionID) {// ...}diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsxindex 6706825697..c03b269ae0 100644--- a/web/packages/accounts/pages/credentials.tsx+++ b/web/packages/accounts/pages/credentials.tsx@@ -25,8 +25,8 @@ import type { SRPAttributes } from "ente-accounts/services/srp";import {generateSRPSetupAttributes,getSRPAttributes,- loginViaSRP,setupSRP,+ verifySRP,} from "ente-accounts/services/srp";import {generateAndSaveInteractiveKeyAttributes,@@ -185,7 +185,7 @@ const Page: React.FC = () => {accountsUrl,} =await userVerificationResultAfterResolvingSecondFactorChoice(- await loginViaSRP(srpAttributes!, kek),+ await verifySRP(srpAttributes!, kek),);setIsFirstLogin(true);diff --git a/web/packages/accounts/services/srp.ts b/web/packages/accounts/services/srp.tsindex 7ba34c4390..22c15d4ae6 100644--- a/web/packages/accounts/services/srp.ts+++ b/web/packages/accounts/services/srp.ts@@ -563,69 +563,84 @@ const updateSRPAndKeys = async (return UpdateSRPAndKeysResponse.parse(await res.json());};-export const loginViaSRP = async (- srpAttributes: SRPAttributes,+/**+ * Log the user in to a new device by performing SRP verification.+ *+ * This function implements the flow described in [Note: SRP verification].+ *+ * @param srpAttributes The user's SRP attributes.+ *+ * @param kek The user's key encryption key as a base64 string.+ *+ * @returns If SRP verification is successful, it returns a+ * {@link UserVerificationResponse} (both email and SRP verification resolve to+ * this same structure).+ */+export const verifySRP = async (+ { srpUserID, srpSalt }: SRPAttributes,kek: string,): Promise<UserVerificationResponse> => {- try {- const loginSubKey = await deriveSRPLoginSubKey(kek);- const srpClient = await generateSRPClient(- srpAttributes.srpSalt,- srpAttributes.srpUserID,- loginSubKey,- );- const srpA = srpClient.computeA();- const { srpB, sessionID } = await createSRPSession(- srpAttributes.srpUserID,- bufferToB64(srpA),- );- srpClient.setB(b64ToBuffer(srpB));-- const m1 = srpClient.computeM1();- log.debug(() => `srp m1: ${bufferToB64(m1)}`);- const { srpM2, ...rest } = await verifySRPSession(- sessionID,- srpAttributes.srpUserID,- bufferToB64(m1),- );- log.debug(() => `srp verify session successful,srpM2: ${srpM2}`);+ const loginSubKey = await deriveSRPLoginSubKey(kek);+ const srpClient = await generateSRPClient(srpSalt, srpUserID, loginSubKey);- srpClient.checkM2(b64ToBuffer(srpM2));+ // Send A, obtain B.+ const { srpB, sessionID } = await createSRPSession({+ srpUserID,+ srpA: bufferToB64(srpClient.computeA()),+ });- log.debug(() => `srp server verify successful`);- return rest;- } catch (e) {- log.error("srp verify failed", e);- throw e;- }+ srpClient.setB(b64ToBuffer(srpB));++ // Send M1, obtain M2.+ const { srpM2, ...rest } = await verifySRPSession({+ sessionID,+ srpUserID,+ srpM1: bufferToB64(srpClient.computeM1()),+ });++ srpClient.checkM2(b64ToBuffer(srpM2));++ return rest;};-interface CreateSRPSessionResponse {- sessionID: string;- srpB: string;+interface CreateSRPSessionRequest {+ srpUserID: string;+ srpA: string;}-const createSRPSession = async (srpUserID: string, srpA: string) => {+const CreateSRPSessionResponse = z.object({+ sessionID: z.string(),+ srpB: z.string(),+});++type CreateSRPSessionResponse = z.infer<typeof CreateSRPSessionResponse>;++const createSRPSession = async (+ createSRPSessionRequest: CreateSRPSessionRequest,+): Promise<CreateSRPSessionResponse> => {const res = await fetch(await apiURL("/users/srp/create-session"), {method: "POST",headers: publicRequestHeaders(),- body: JSON.stringify({ srpUserID, srpA }),+ body: JSON.stringify(createSRPSessionRequest),});ensureOk(res);- const data = await res.json();- // TODO: Use zod- return data as CreateSRPSessionResponse;+ return CreateSRPSessionResponse.parse(await res.json());};export interface SRPVerificationResponse extends UserVerificationResponse {srpM2: string;}+interface VerifySRPSessionRequest {+ sessionID: string;+ srpUserID: string;+ srpM1: string;+}+const verifySRPSession = async (- sessionID: string,- srpUserID: string,- srpM1: string,-) => {+ VerifySRPSessionRequest: VerifySRPSessionRequest,+): Promise<SRPVerificationResponse> => {+ const { sessionID, srpUserID, srpM1 } = VerifySRPSessionRequest;try {const resp = await HTTPService.post(await apiURL("/users/srp/verify-session"),