Skip to content

armgit / ente

Public Imported from GitHub
0

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

Switch

Manav Rathi5e9e8bd76b0d
diff --git a/web/packages/new/photos/services/ml/cluster.ts b/web/packages/new/photos/services/ml/cluster.ts
index 7189c2642e..e4cf11c0e5 100644
--- a/web/packages/new/photos/services/ml/cluster.ts
+++ b/web/packages/new/photos/services/ml/cluster.ts
@@ -360,13 +360,13 @@ const clusterBatchLinear = async (
* Use the output of the clustering phase to (a) update any remote cgroups that
* have changed, and (b) update our locally persisted clusters.
*
- * @param masterKey The user's master key, required for updating the cgroups on
- * remote if needed.
+ * @param masterKey The user's master key (as a base64 string), required for
+ * updating the cgroups on remote if needed.
*/
export const reconcileClusters = async (
clusters: FaceCluster[],
modifiedClusterIDs: Set<string>,
- masterKey: Uint8Array,
+ masterKey: string,
) => {
// Index clusters by their ID for fast lookup.
const clusterByID = new Map(clusters.map((c) => [c.id, c]));
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index f02078a99b..2469d01b55 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -7,7 +7,7 @@ import { isDesktop } from "ente-base/app";
import { blobCache } from "ente-base/blob-cache";
import { ensureElectron } from "ente-base/electron";
import log from "ente-base/log";
-import { masterKeyFromSession } from "ente-base/session";
+import { masterKeyB64FromSession } from "ente-base/session";
import { ComlinkWorker } from "ente-base/worker/comlink-worker";
import { type ProcessableUploadItem } from "ente-gallery/services/upload";
import { createUtilityProcess } from "ente-gallery/utils/native-worker";
@@ -360,7 +360,7 @@ export const mlSync = async () => {
};
const updateClustersAndPeople = async () => {
- const masterKey = await masterKeyFromSession();
+ const masterKey = await masterKeyB64FromSession();
// Fetch existing cgroups from remote.
await pullUserEntities("cgroup", masterKey);
@@ -748,11 +748,10 @@ const regenerateFaceCropsIfNeeded = async (file: EnteFile) => {
* @returns The entity ID of the newly created cgroup.
*/
export const addCGroup = async (name: string, cluster: FaceCluster) => {
- const masterKey = await masterKeyFromSession();
const id = await addUserEntity(
"cgroup",
{ name, assigned: [cluster], isHidden: false },
- masterKey,
+ await masterKeyB64FromSession(),
);
await mlSync();
return id;
@@ -780,11 +779,10 @@ export const addClusterToCGroup = async (
(id) => !clusterFaceIDs.has(id),
);
- const masterKey = await masterKeyFromSession();
await updateOrCreateUserEntities(
"cgroup",
[{ ...cgroup, data: { ...cgroup.data, assigned, rejectedFaceIDs } }],
- masterKey,
+ await masterKeyB64FromSession(),
);
return mlSync();
};
@@ -798,11 +796,10 @@ export const addClusterToCGroup = async (
* user entity that will get updated.
*/
export const renameCGroup = async (cgroup: CGroup, name: string) => {
- const masterKey = await masterKeyFromSession();
await updateOrCreateUserEntities(
"cgroup",
[{ ...cgroup, data: { ...cgroup.data, name } }],
- masterKey,
+ await masterKeyB64FromSession(),
);
return mlSync();
};
@@ -834,8 +831,11 @@ export const applyPersonSuggestionUpdates = async (
cgroup: CGroup,
updates: PersonSuggestionUpdates,
) => {
- const masterKey = await masterKeyFromSession();
- await _applyPersonSuggestionUpdates(cgroup, updates, masterKey);
+ await _applyPersonSuggestionUpdates(
+ cgroup,
+ updates,
+ await masterKeyB64FromSession(),
+ );
return mlSync();
};
@@ -848,11 +848,10 @@ export const applyPersonSuggestionUpdates = async (
* @param cluster The {@link FaceCluster} to hide.
*/
export const ignoreCluster = async (cluster: FaceCluster) => {
- const masterKey = await masterKeyFromSession();
await addUserEntity(
"cgroup",
{ name: "", assigned: [cluster], isHidden: true },
- masterKey,
+ await masterKeyB64FromSession(),
);
return mlSync();
};
diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.ts
index b37994bc6a..6e5cba343b 100644
--- a/web/packages/new/photos/services/ml/people.ts
+++ b/web/packages/new/photos/services/ml/people.ts
@@ -615,13 +615,13 @@ export type PersonSuggestionUpdates = Map<
*
* @param updates The changes to make. See {@link PersonSuggestionUpdates}.
*
- * @param masterKey The user's masterKey, which is is used to encrypt and
- * decrypt the entity key associated with cgroups.
+ * @param masterKey The user's masterKey (as a base64 string), which is is used
+ * to encrypt and decrypt the entity key associated with cgroups.
*/
export const _applyPersonSuggestionUpdates = async (
cgroup: CGroup,
updates: PersonSuggestionUpdates,
- masterKey: Uint8Array,
+ masterKey: string,
) => {
const localClusters = await savedFaceClusters();
diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.ts
index 28ecbd09a8..c3fb908879 100644
--- a/web/packages/new/photos/services/ml/worker.ts
+++ b/web/packages/new/photos/services/ml/worker.ts
@@ -317,10 +317,10 @@ export class MLWorker {
* after we have fetched the latest cgroups from remote (so that we do no
* overwrite any remote updates).
*
- * @param masterKey The user's master key, required for updating remote
- * cgroups if needed.
+ * @param masterKey The user's master key (as a base64 string), required for
+ * updating remote cgroups if needed.
*/
- async clusterFaces(masterKey: Uint8Array) {
+ async clusterFaces(masterKey: string) {
const { clusters, modifiedClusterIDs } = await _clusterFaces(
await savedFaceIndexes(),
await getAllLocalFiles(),
diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.ts
index ff09d6b64d..3d9f0d5854 100644
--- a/web/packages/new/photos/services/search/index.ts
+++ b/web/packages/new/photos/services/search/index.ts
@@ -1,5 +1,5 @@
import log from "ente-base/log";
-import { masterKeyFromSession } from "ente-base/session";
+import { masterKeyB64FromSession } from "ente-base/session";
import { ComlinkWorker } from "ente-base/worker/comlink-worker";
import { FileType } from "ente-media/file-type";
import i18n, { t } from "i18next";
@@ -50,7 +50,7 @@ export const logoutSearch = () => {
* Fetch any data that would be needed if the user were to search.
*/
export const searchDataSync = () =>
- worker().then((w) => masterKeyFromSession().then((k) => w.sync(k)));
+ worker().then((w) => masterKeyB64FromSession().then((k) => w.sync(k)));
/**
* Set the collections and files over which we should search.
diff --git a/web/packages/new/photos/services/search/worker.ts b/web/packages/new/photos/services/search/worker.ts
index 02a206faf2..e12aa4bb80 100644
--- a/web/packages/new/photos/services/search/worker.ts
+++ b/web/packages/new/photos/services/search/worker.ts
@@ -46,10 +46,11 @@ export class SearchWorker {
/**
* Fetch any state we might need when the actual search happens.
*
- * @param masterKey The user's master key. Web workers do not have access to
- * session storage so this key needs to be passed to us explicitly.
+ * @param masterKey The user's master key (as a base64 string). Web workers
+ * do not have access to session storage so this key needs to be passed to
+ * us explicitly.
*/
- async sync(masterKey: Uint8Array) {
+ async sync(masterKey: string) {
// Let the cities fetch complete async. And do it only once per app
// startup (this list is static and doesn't change).
if (this.cities.length == 0) {
diff --git a/web/packages/new/photos/services/user-entity/index.ts b/web/packages/new/photos/services/user-entity/index.ts
index 9f5ae9a41b..3d0ecf813c 100644
--- a/web/packages/new/photos/services/user-entity/index.ts
+++ b/web/packages/new/photos/services/user-entity/index.ts
@@ -123,13 +123,10 @@ export const savedCGroups = (): Promise<CGroup[]> =>
* It uses local state to remember the latest entry the last time it did a pull,
* so each subsequent pull is a lightweight diff.
*
- * @param masterKey The user's masterKey, which is is used to encrypt and
- * decrypt the entity key.
+ * @param masterKey The user's masterKey (as a base64 string), which is is used
+ * to encrypt and decrypt the entity key.
*/
-export const pullUserEntities = async (
- type: EntityType,
- masterKey: Uint8Array,
-) => {
+export const pullUserEntities = async (type: EntityType, masterKey: string) => {
const entityKeyB64 = await getOrCreateEntityKeyB64(type, masterKey);
let sinceTime = (await savedLatestUpdatedAt(type)) ?? 0;
@@ -176,17 +173,17 @@ const isGzipped = (type: EntityType) => type == "cgroup";
export const addUserEntity = async (
type: EntityType,
data: unknown,
- masterKey: Uint8Array,
+ masterKey: string,
) =>
await postUserEntity(
type,
await encryptedUserEntityData(type, data, masterKey),
);
-export const encryptedUserEntityData = async (
+const encryptedUserEntityData = async (
type: EntityType,
data: unknown,
- masterKey: Uint8Array,
+ masterKey: string,
) => {
const entityKeyB64 = await getOrCreateEntityKeyB64(type, masterKey);
@@ -201,13 +198,13 @@ export const encryptedUserEntityData = async (
* Update the given user entities (both on remote and locally), creating them if
* they don't exist.
*
- * @param masterKey The user's masterKey, which is is used to encrypt and
- * decrypt the entity key.
+ * @param masterKey The user's masterKey (as a base64 string), which is is used
+ * to encrypt and decrypt the entity key.
*/
export const updateOrCreateUserEntities = async (
type: EntityType,
entities: LocalUserEntity[],
- masterKey: Uint8Array,
+ masterKey: string,
) =>
await Promise.all(
entities.map(({ id, data }) =>
@@ -234,10 +231,7 @@ export const updateOrCreateUserEntities = async (
*
* See also, [Note: User entity keys].
*/
-const getOrCreateEntityKeyB64 = async (
- type: EntityType,
- masterKey: Uint8Array,
-) => {
+const getOrCreateEntityKeyB64 = async (type: EntityType, masterKey: string) => {
// See if we already have it locally.
const saved = await savedRemoteUserEntityKey(type);
if (saved) return decryptEntityKey(saved, masterKey);
@@ -264,7 +258,7 @@ const getOrCreateEntityKeyB64 = async (
return result;
};
-const generateEncryptedEntityKey = async (masterKey: Uint8Array) => {
+const generateEncryptedEntityKey = async (masterKey: string) => {
const { encryptedData, nonce } = await encryptBox(
await generateBlobOrStreamKey(),
masterKey,
@@ -278,7 +272,7 @@ const generateEncryptedEntityKey = async (masterKey: Uint8Array) => {
*/
const decryptEntityKey = async (
remote: RemoteUserEntityKey,
- masterKey: Uint8Array,
+ masterKey: string,
) =>
decryptBox(
{