Skip to content

armgit / ente

Public Imported from GitHub
0

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

Read ss

Manav Rathidffe364c51cc
diff --git a/web/packages/base/session-store.ts b/web/packages/base/session-store.ts
new file mode 100644
index 0000000000..81b162d3ba
--- /dev/null
+++ b/web/packages/base/session-store.ts
@@ -0,0 +1,31 @@
+import { sharedCryptoWorker } from "@/base/crypto";
+import { z } from "zod";
+
+/**
+ * Return the user's encryption key from session storage.
+ *
+ * Precondition: The user should be logged in.
+ */
+export const userEncryptionKey = 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.",
+ );
+ }
+
+ const { encryptedData, key, nonce } = EncryptionKeyAttributes.parse(
+ JSON.parse(value),
+ );
+
+ const cryptoWorker = await sharedCryptoWorker();
+ return cryptoWorker.decryptB64(encryptedData, nonce, key);
+};
+
+// TODO: Same as B64EncryptionResult. Revisit.
+const EncryptionKeyAttributes = z.object({
+ encryptedData: z.string(),
+ key: z.string(),
+ nonce: z.string(),
+});
diff --git a/web/packages/new/photos/services/user-entity.ts b/web/packages/new/photos/services/user-entity.ts
index 0c4764d6c3..8b1734f096 100644
--- a/web/packages/new/photos/services/user-entity.ts
+++ b/web/packages/new/photos/services/user-entity.ts
@@ -165,24 +165,24 @@ export const userEntityDiff = async (
* 3. Otherwise we'll create a new one, save it locally and put it to remote.
*/
const entityKey = (type: EntityType) => {
-
+ const masterKey = await getActualKey();
};
-const savedRemoteUserEntityKeyKey = (type: EntityType) => `entityKey/${type}`;
+const savedRemoteEntityKeyKey = (type: EntityType) => `entityKey/${type}`;
/**
* Return the locally persisted value for the entity key to use for decrypting
* the contents of entities of the given {@link type}.
*/
const savedRemoteUserEntityKey = (type: EntityType) =>
- getKV(savedRemoteUserEntityKeyKey(type));
+ getKV(savedRemoteEntityKeyKey(type));
/**
* Setter for {@link entityKey}.
*/
const setSavedRemoteUserEntityKey = (type: EntityType, value: string) =>
- setKV(savedRemoteUserEntityKeyKey(type), value);
+ setKV(savedRemoteEntityKeyKey(type), value);
/**
* Fetch the latest encryption key for the given user entity {@link} type from