π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Conv
Manav Rathi4aacd1e47a6c
diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsxindex dc7856b8aa..02dc0e52b4 100644--- a/web/packages/accounts/pages/credentials.tsx+++ b/web/packages/accounts/pages/credentials.tsx@@ -262,7 +262,8 @@ const Page: React.FC = () => {await saveMasterKeyInSessionAndSafeStore(masterKey);await decryptAndStoreToken(keyAttributes, masterKey);try {- let srpAttributes: SRPAttributes | null = getData("srpAttributes");+ let srpAttributes: SRPAttributes | null | undefined =+ getData("srpAttributes");if (!srpAttributes && user) {srpAttributes = await getSRPAttributes(user.email);if (srpAttributes) {diff --git a/web/packages/accounts/services/srp.ts b/web/packages/accounts/services/srp.tsindex d68d4b398f..ff4f91257b 100644--- a/web/packages/accounts/services/srp.ts+++ b/web/packages/accounts/services/srp.ts@@ -184,7 +184,7 @@ export interface SRPAttributes {* the local storage type.*/const SRPAttributes = z.object({- srpUserIDsrpUserID: z.string(),+ srpUserID: z.string(),srpSalt: z.string(),memLimit: z.number(),opsLimit: z.number(),@@ -192,6 +192,30 @@ const SRPAttributes = z.object({isEmailMFAEnabled: z.boolean(),});+/**+ * Fetch the {@link SRPAttributes} from remote for the Ente user with the+ * provided email.+ *+ * Returns `undefined` if either there is no Ente user with the given+ * {@link email}, or if there is a a user but they've not yet completed the SRP+ * setup ceremony.+ *+ * @param email The email of the user whose SRP attributes we're fetching.+ */+export const getSRPAttributes = async (+ email: string,+): Promise<SRPAttributes | undefined> => {+ const res = await fetch(await apiURL("/users/srp/attributes", { email }), {+ headers: publicRequestHeaders(),+ });+ if (res.status == 404) {+ return undefined;+ }+ ensureOk(res);+ return z.object({ attributes: SRPAttributes }).parse(await res.json())+ .attributes;+};+/*** Derive a "password" (which is really an arbitrary binary value, not human* generated) for use as the SRP user password by applying a deterministic KDF@@ -208,10 +232,6 @@ export const deriveSRPPassword = async (kek: string) => {return toB64(kekSubKeyBytes.slice(0, 16));};-interface GetSRPAttributesResponse {- attributes: SRPAttributes;-}-export interface SRPSetupAttributes {srpSalt: string;srpVerifier: string;@@ -440,21 +460,6 @@ export const generateSRPSetupAttributes = async (return result;};-export const getSRPAttributes = async (- email: string,-): Promise<SRPAttributes | null> => {- try {- const resp = await HTTPService.get(- await apiURL("/users/srp/attributes"),- { email },- );- return (resp.data as GetSRPAttributesResponse).attributes;- } catch (e) {- log.error("failed to get SRP attributes", e);- return null;- }-};-export const loginViaSRP = async (srpAttributes: SRPAttributes,kek: string,