Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use same nomenclature as the architecture document

Manav Rathi3962f3a13322
diff --git a/web/packages/base/session-store.ts b/web/packages/base/session-store.ts
index 6e37bac534..f2a4ebd86c 100644
--- a/web/packages/base/session-store.ts
+++ b/web/packages/base/session-store.ts
@@ -2,16 +2,16 @@ import { sharedCryptoWorker } from "@/base/crypto";
import { z } from "zod";
/**
- * Return the base64 encoded user's encryption key from session storage.
+ * Return the user's master key (as a base64 string) from session storage.
*
* Precondition: The user should be logged in.
*/
-export const usersEncryptionKeyB64 = async () => {
+export const masterKeyB64FromSession = async () => {
// TODO: Same value as the deprecated SESSION_KEYS.ENCRYPTION_KEY.
const value = sessionStorage.getItem("encryptionKey");
if (!value) {
throw new Error(
- "The user's encryption key was not found in session storage. Likely they are not logged in.",
+ "The user's master key was not found in session storage. Likely they are not logged in.",
);
}
diff --git a/web/packages/new/photos/services/user-entity.ts b/web/packages/new/photos/services/user-entity.ts
index 312bd22f55..4c92364e72 100644
--- a/web/packages/new/photos/services/user-entity.ts
+++ b/web/packages/new/photos/services/user-entity.ts
@@ -3,7 +3,7 @@ import { decryptAssociatedDataB64 } from "@/base/crypto/ente";
import { authenticatedRequestHeaders, ensureOk, HTTPError } from "@/base/http";
import { getKV, getKVN, setKV } from "@/base/kv";
import { apiURL } from "@/base/origins";
-import { usersEncryptionKeyB64 } from "@/base/session-store";
+import { masterKeyB64FromSession } from "@/base/session-store";
import { ensure } from "@/utils/ensure";
import { nullToUndefined } from "@/utils/transform";
import { z } from "zod";
@@ -172,19 +172,21 @@ const userEntityDiff = async (
* Return the entity key that can be used to decrypt the encrypted contents of
* user entities of the given {@link type}.
*
- * 1. We'll see if we have the (encrypted) entity key present locally. If so,
- * we'll decrypt it using the user's master key and return it.
+ * 1. See if we have the encrypted entity key present locally. If so, return
+ * the entity key by decrypting it using with the user's master key.
*
- * 2. Otherwise we'll fetch the entity key for that type from remote. If found,
- * we'll decrypte it using the user's master key and return it, also saving
- * it locally for future use.
+ * 2. Otherwise fetch the encrypted entity key for that type from remote. If we
+ * get one, obtain the entity key by decrypt the encrypted one using the
+ * user's master key, save it locally for future use, and return it.
*
- * 3. Otherwise we'll create a new one, save it locally and put it to remote.
+ * 3. Otherwise generate a new entity key, encrypt it using the user's master
+ * key, putting the encrypted one to remote and also saving it locally, and
+ * return it.
*
* See also, [Note: User entity keys].
*/
const getOrCreateEntityKeyB64 = async (type: EntityType) => {
- const encryptionKeyB64 = await usersEncryptionKeyB64();
+ const encryptionKeyB64 = await masterKeyB64FromSession();
const worker = await sharedCryptoWorker();
const decrypt = async ({ encryptedKey, header }: RemoteUserEntityKey) => {
@@ -244,10 +246,10 @@ const saveRemoteUserEntityKey = (
*
* [Note: User entity keys]
*
- * There is one encryption key (itself encrypted with the user's encryption key)
- * for each user entity type. If the key doesn't exist on remote, then the
- * client is expected to create one on the user's behalf. Remote will disallow
- * attempts to multiple keys for the same user entity type.
+ * There is one encryption key (itself encrypted with the user's master key) for
+ * each user entity type. If the key doesn't exist on remote, then the client is
+ * expected to create one on the user's behalf. Remote will disallow attempts to
+ * multiple keys for the same user entity type.
*/
const getUserEntityKey = async (
type: EntityType,