Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Inline

Manav Rathid62865f9e563
diff --git a/web/packages/accounts/pages/change-password.tsx b/web/packages/accounts/pages/change-password.tsx
index 871b800fc6..d05da4a044 100644
--- a/web/packages/accounts/pages/change-password.tsx
+++ b/web/packages/accounts/pages/change-password.tsx
@@ -10,7 +10,7 @@ import { appHomeRoute, stashRedirect } from "ente-accounts/services/redirect";
import {
convertBase64ToBuffer,
convertBufferToBase64,
- generateLoginSubKey,
+ deriveSRPPassword,
generateSRPClient,
generateSRPSetupAttributes,
} from "ente-accounts/services/srp";
@@ -78,7 +78,7 @@ const Page: React.FC = () => {
memLimit: kek.memLimit,
};
- const loginSubKey = await generateLoginSubKey(kek.key);
+ const loginSubKey = await deriveSRPPassword(kek.key);
const { srpUserID, srpSalt, srpVerifier } =
await generateSRPSetupAttributes(loginSubKey);
diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx
index e281293f4f..2dc62a5b37 100644
--- a/web/packages/accounts/pages/credentials.tsx
+++ b/web/packages/accounts/pages/credentials.tsx
@@ -23,7 +23,7 @@ import {
import { checkSessionValidity } from "ente-accounts/services/session";
import {
configureSRP,
- generateLoginSubKey,
+ deriveSRPPassword,
generateSRPSetupAttributes,
loginViaSRP,
} from "ente-accounts/services/srp";
@@ -292,7 +292,7 @@ const Page: React.FC = () => {
}
log.debug(() => `userSRPSetupPending ${!srpAttributes}`);
if (!srpAttributes) {
- const loginSubKey = await generateLoginSubKey(kek);
+ const loginSubKey = await deriveSRPPassword(kek);
const srpSetupAttributes =
await generateSRPSetupAttributes(loginSubKey);
await configureSRP(srpSetupAttributes);
diff --git a/web/packages/accounts/services/srp.ts b/web/packages/accounts/services/srp.ts
index db6ab78477..32f2ad2d71 100644
--- a/web/packages/accounts/services/srp.ts
+++ b/web/packages/accounts/services/srp.ts
@@ -16,27 +16,28 @@ import type { UserVerificationResponse } from "./user";
const SRP_PARAMS = SRP.params["4096"];
-const LOGIN_SUB_KEY_LENGTH = 32;
-const LOGIN_SUB_KEY_ID = 1;
-const LOGIN_SUB_KEY_CONTEXT = "loginctx";
-const LOGIN_SUB_KEY_BYTE_LENGTH = 16;
-
-export const generateLoginSubKey = async (kek: string) => {
+/**
+ * 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
+ * (Key Derivation Function) to the provided {@link kek}.
+ *
+ * @param kek The user's kek (key encryption key) as a base64 string.
+ *
+ * @returns A string that can be used as the SRP user password.
+ */
+export const deriveSRPPassword = async (kek: string) => {
const cryptoWorker = await sharedCryptoWorker();
const kekSubKeyString = await cryptoWorker.deriveSubKey(
kek,
- LOGIN_SUB_KEY_LENGTH,
- LOGIN_SUB_KEY_ID,
- LOGIN_SUB_KEY_CONTEXT,
+ 32,
+ 1,
+ "loginctx",
);
const kekSubKey = await cryptoWorker.fromB64(kekSubKeyString);
- // use first 16 bytes of generated kekSubKey as loginSubKey
- const loginSubKey = await cryptoWorker.toB64(
- kekSubKey.slice(0, LOGIN_SUB_KEY_BYTE_LENGTH),
- );
-
- return loginSubKey;
+ // Use the first 16 bytes (128 bits) of the KEK's KDF subkey as the SRP
+ // password (instead of entire 32 bytes).
+ return await cryptoWorker.toB64(kekSubKey.slice(0, 16));
};
export const configureSRP = async ({
@@ -109,7 +110,7 @@ export const loginViaSRP = async (
kek: string,
): Promise<UserVerificationResponse> => {
try {
- const loginSubKey = await generateLoginSubKey(kek);
+ const loginSubKey = await deriveSRPPassword(kek);
const srpClient = await generateSRPClient(
srpAttributes.srpSalt,
srpAttributes.srpUserID,
@@ -214,7 +215,7 @@ export async function generateKeyAndSRPAttributes(
nonce: secretKeyDecryptionNonce,
} = await cryptoWorker.encryptBox(keyPair.privateKey, masterKey);
- const loginSubKey = await generateLoginSubKey(kek.key);
+ const loginSubKey = await deriveSRPPassword(kek.key);
const srpSetupAttributes = await generateSRPSetupAttributes(loginSubKey);
diff --git a/web/packages/shared/crypto/helpers.ts b/web/packages/shared/crypto/helpers.ts
index 5136903e04..a39596309a 100644
--- a/web/packages/shared/crypto/helpers.ts
+++ b/web/packages/shared/crypto/helpers.ts
@@ -4,7 +4,6 @@ import { masterKeyFromSession } from "ente-base/session";
import { getData, setData, setLSUser } from "ente-shared/storage/localStorage";
import { type SessionKey, setKey } from "ente-shared/storage/sessionStorage";
-
export async function decryptAndStoreToken(
keyAttributes: KeyAttributes,
masterKey: string,
@@ -63,7 +62,6 @@ export async function generateAndSaveIntermediateKeyAttributes(
return intermediateKeyAttributes;
}
-
export const saveKeyInSessionStore = async (
keyType: SessionKey,
key: string,