π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
re
Manav Rathi7539a1003c2b
diff --git a/web/packages/accounts/components/VerifyMasterPasswordForm.tsx b/web/packages/accounts/components/VerifyMasterPasswordForm.tsxindex b55859ae0a..73d0b529ba 100644--- a/web/packages/accounts/components/VerifyMasterPasswordForm.tsx+++ b/web/packages/accounts/components/VerifyMasterPasswordForm.tsx@@ -1,5 +1,8 @@import { Input, TextField } from "@mui/material";-import type { SRPAttributes } from "ente-accounts/services/srp";+import {+ srpVerificationUnauthorizedErrorMessage,+ type SRPAttributes,+} from "ente-accounts/services/srp";import type { KeyAttributes, User } from "ente-accounts/services/user";import { LoadingButton } from "ente-base/components/mui/LoadingButton";import { ShowHidePasswordInputAdornment } from "ente-base/components/mui/PasswordInputAdornment";@@ -31,9 +34,10 @@ export interface VerifyMasterPasswordFormProps {* the form that some other form of second factor is enabled and the user* has been redirected to a two factor verification page.*- * This function can throw an `CustomError.INCORRECT_PASSWORD_OR_NO_ACCOUNT`- * to signal that either that the password is incorrect, or no account with- * the provided email exists.+ * @throws A Error with message+ * {@link srpVerificationUnauthorizedErrorMessage} to signal that either+ * that the password is incorrect, or no account with the provided email+ * exists.*/getKeyAttributes?: (kek: string) => Promise<KeyAttributes | undefined>;/**@@ -155,7 +159,7 @@ export const VerifyMasterPasswordForm: React.FC<// the two-factor verification page.return;- case CustomError.INCORRECT_PASSWORD_OR_NO_ACCOUNT:+ case srpVerificationUnauthorizedErrorMessage:log.error("Incorrect password or no account", e);setFieldError(t("incorrect_password_or_no_account"),diff --git a/web/packages/accounts/services/srp.ts b/web/packages/accounts/services/srp.tsindex 22c15d4ae6..a6d6917290 100644--- a/web/packages/accounts/services/srp.ts+++ b/web/packages/accounts/services/srp.ts@@ -1,4 +1,3 @@-import { HttpStatusCode } from "axios";import {deriveSubKeyBytes,generateDeriveKeySalt,@@ -9,14 +8,14 @@ import {ensureOk,publicRequestHeaders,} from "ente-base/http";-import log from "ente-base/log";import { apiURL } from "ente-base/origins";-import { ApiError, CustomError } from "ente-shared/error";-import HTTPService from "ente-shared/network/HTTPService";import { SRP, SrpClient } from "fast-srp-hap";import { v4 as uuidv4 } from "uuid";import { z } from "zod/v4";-import type { UserVerificationResponse } from "./user";+import {+ EmailOrSRPVerificationResponse,+ type UserVerificationResponse,+} from "./user";/*** The SRP attributes for a user.@@ -563,6 +562,16 @@ const updateSRPAndKeys = async (return UpdateSRPAndKeysResponse.parse(await res.json());};+/**+ * The message of the {@link Error} that is thrown by {@link verifySRP} if+ * remote fails SRP verification with a HTTP 401.+ *+ * The API contract allows for a SRP verification 401 both because of incorrect+ * credentials or a non existent account.+ */+export const srpVerificationUnauthorizedErrorMessage =+ "SRP verification failed (HTTP 401 Unauthorized)";+/*** Log the user in to a new device by performing SRP verification.*@@ -575,6 +584,9 @@ const updateSRPAndKeys = async (* @returns If SRP verification is successful, it returns a* {@link UserVerificationResponse} (both email and SRP verification resolve to* this same structure).+ *+ * @throws An Error with {@link srpVerificationUnauthorizedErrorMessage} in case+ * there is no such account, or if the credentials (kek) are incorrect.*/export const verifySRP = async ({ srpUserID, srpSalt }: SRPAttributes,@@ -627,39 +639,30 @@ const createSRPSession = async (return CreateSRPSessionResponse.parse(await res.json());};-export interface SRPVerificationResponse extends UserVerificationResponse {- srpM2: string;-}-interface VerifySRPSessionRequest {sessionID: string;srpUserID: string;srpM1: string;}+const SRPVerificationResponse = z.object({+ ...EmailOrSRPVerificationResponse.shape,+ srpM2: z.string(),+});++type SRPVerificationResponse = z.infer<typeof SRPVerificationResponse>;+const verifySRPSession = async (- VerifySRPSessionRequest: VerifySRPSessionRequest,+ verifySRPSessionRequest: VerifySRPSessionRequest,): Promise<SRPVerificationResponse> => {- const { sessionID, srpUserID, srpM1 } = VerifySRPSessionRequest;- try {- const resp = await HTTPService.post(- await apiURL("/users/srp/verify-session"),- { sessionID, srpUserID, srpM1 },- undefined,- );- return resp.data as SRPVerificationResponse;- } catch (e) {- log.error("verifySRPSession failed", e);- if (- e instanceof ApiError &&- // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison- e.httpStatusCode === HttpStatusCode.Unauthorized- ) {- // The API contract allows for a SRP verification 401 both because- // of incorrect credentials or a non existent account.- throw Error(CustomError.INCORRECT_PASSWORD_OR_NO_ACCOUNT);- } else {- throw e;- }+ const res = await fetch(await apiURL("/users/srp/verify-session"), {+ method: "POST",+ headers: publicRequestHeaders(),+ body: JSON.stringify(verifySRPSessionRequest),+ });+ if (res.status == 401) {+ throw new Error(srpVerificationUnauthorizedErrorMessage);}+ ensureOk(res);+ return SRPVerificationResponse.parse(await res.json());};diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.tsindex 17d92008c0..edaa25f09f 100644--- a/web/packages/accounts/services/user.ts+++ b/web/packages/accounts/services/user.ts@@ -554,18 +554,18 @@ export const verifyEmail = async (//// eslint-disable-next-line @typescript-eslint/ban-ts-comment// @ts-ignore- return EmailOrSRPAuthorizationResponse.parse(await res.json());+ return EmailOrSRPVerificationResponse.parse(await res.json());};/*** Zod schema for response from remote on a successful user verification, either- * via {@link verifyEmail} or {@link verifySRPSession}.+ * via {@link verifyEmail} or {@link verifySRP}.** If a second factor is enabled than one of the two factor session IDs* (`passkeySessionID`, `twoFactorSessionID` / `twoFactorSessionIDV2`) will be* set. Otherwise `keyAttributes` and `encryptedToken` will be set.*/-export const EmailOrSRPAuthorizationResponse = z.object({+export const EmailOrSRPVerificationResponse = z.object({id: z.number(),keyAttributes: RemoteKeyAttributes.nullish().transform(nullToUndefined),encryptedToken: z.string().nullish().transform(nullToUndefined),diff --git a/web/packages/base/crypto/types.ts b/web/packages/base/crypto/types.tsindex ac33b0bcd9..8b82a2aef8 100644--- a/web/packages/base/crypto/types.ts+++ b/web/packages/base/crypto/types.ts@@ -24,9 +24,9 @@ export type SodiumStateAddress = StateAddress;export const streamEncryptionChunkSize = 4 * 1024 * 1024;/**- * The {@link message} of {@link Error} that is thrown by- * {@link deriveSensitiveKey} if we could not find acceptable ops and mem limit- * combinations without exceeded the maximum mem limit.+ * The message of the {@link Error} that is thrown by {@link deriveSensitiveKey}+ * if we could not find acceptable ops and mem limit combinations without+ * exceeded the maximum mem limit.** Generally, this indicates that the current device is not powerful enough to* perform the key derivation. This is rare for computers, but can happen withdiff --git a/web/packages/shared/error/index.ts b/web/packages/shared/error/index.tsindex dd6d7d961c..e787cbc331 100644--- a/web/packages/shared/error/index.ts+++ b/web/packages/shared/error/index.ts@@ -40,7 +40,6 @@ export const CustomError = {BAD_REQUEST: "bad request",SUBSCRIPTION_NEEDED: "subscription not present",NOT_FOUND: "not found ",- INCORRECT_PASSWORD_OR_NO_ACCOUNT: "incorrect password or no such account",UPLOAD_CANCELLED: "upload cancelled",UPDATE_EXPORTED_RECORD_FAILED: "update file exported record failed",EXPORT_STOPPED: "export stopped",