π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Make space for new format
Manav Rathi63ff5ac5732b
diff --git a/web/packages/new/photos/services/ml/embedding.ts b/web/packages/new/photos/services/ml/embedding.tsindex 24a8db9ced..50af433d69 100644--- a/web/packages/new/photos/services/ml/embedding.ts+++ b/web/packages/new/photos/services/ml/embedding.ts@@ -4,8 +4,8 @@ import {} from "@/new/photos/services/files";import type { EnteFile } from "@/new/photos/types/file";import {- decryptFileMetadata,- encryptFileMetadata,+ decryptFileMetadataString,+ encryptFileMetadataString,} from "@/new/shared/crypto/ente";import { authenticatedRequestHeaders, ensureOk } from "@/next/http";import { getKV, setKV } from "@/next/kv";@@ -173,7 +173,7 @@ const pullEmbeddings = async (const file = localFilesByID.get(remoteEmbedding.fileID);if (!file) continue;await save(- await decryptFileMetadata(+ await decryptFileMetadataString(remoteEmbedding.encryptedEmbedding,remoteEmbedding.decryptionHeader,file.key,@@ -297,7 +297,7 @@ export const putEmbedding = async (log.debug(() => ["Uploading embedding", { model, embedding }]);const { encryptedMetadataB64, decryptionHeaderB64 } =- await encryptFileMetadata(embedding, enteFile.key);+ await encryptFileMetadataString(embedding, enteFile.key);const res = await fetch(await apiURL("/embeddings"), {method: "PUT",@@ -312,6 +312,29 @@ export const putEmbedding = async (ensureOk(res);};+// MARK: - Combined++/**+ * Update the combined derived data stored for given {@link enteFile} on remote.+ * This allows other clients to directly pull the derived data instead of+ * needing to re-index.+ *+ * The data on remote will be replaced unconditionally, and it is up to the+ * client (us) to ensure that we preserve the parts of the pre-existing derived+ * data (if any) that we did not understand or touch.+ */+export const putDerivedData = async (+ enteFile: EnteFile,+ faceIndex: FaceIndex,+ clipIndex: CLIPIndex,+) => {+ const combined = {+ face: faceIndex,+ clip: clipIndex,+ };+ return putEmbedding(enteFile, "combined", JSON.stringify(combined));+};+// MARK: - Face/**diff --git a/web/packages/new/shared/crypto/ente.ts b/web/packages/new/shared/crypto/ente.tsindex 5e95e77627..7aaf282c44 100644--- a/web/packages/new/shared/crypto/ente.ts+++ b/web/packages/new/shared/crypto/ente.ts@@ -9,9 +9,9 @@import * as libsodium from "@ente/shared/crypto/internal/libsodium";/**- * Encrypt arbitrary metadata associated with a file using its key.+ * Encrypt arbitrary metadata associated with a file using the file's key.*- * @param metadata The metadata (string) to encrypt.+ * @param metadata The metadata (bytes) to encrypt.** @param keyB64 Base64 encoded string containing the encryption key (this'll* generally be the file's key).@@ -20,16 +20,10 @@ import * as libsodium from "@ente/shared/crypto/internal/libsodium";* decryption header.*/export const encryptFileMetadata = async (- metadata: string,+ metadata: Uint8Array,keyB64: string,-): Promise<{ encryptedMetadataB64: string; decryptionHeaderB64: string }> => {- const encoder = new TextEncoder();- const encodedMetadata = encoder.encode(metadata);-- const { file } = await libsodium.encryptChaChaOneShot(- encodedMetadata,- keyB64,- );+) => {+ const { file } = await libsodium.encryptChaChaOneShot(metadata, keyB64);return {encryptedMetadataB64: await libsodium.toB64(file.encryptedData),decryptionHeaderB64: file.decryptionHeader,@@ -37,7 +31,17 @@ export const encryptFileMetadata = async (};/**- * Decrypt arbitrary metadata associated with a file using the its key.+ * Encrypt arbitrary string metadata associated with a file using the file's+ * key. This is a variant of encryptFileMetadata that takes a metadata string+ * instead of the metadata bytes.+ */+export const encryptFileMetadataString = async (+ metadata: string,+ keyB64: string,+) => encryptFileMetadata(new TextEncoder().encode(metadata), keyB64);++/**+ * Decrypt arbitrary metadata associated with a file using the file's key.** @param encryptedMetadataB64 Base64 encoded string containing the encrypted* data.@@ -48,18 +52,33 @@ export const encryptFileMetadata = async (* @param keyB64 Base64 encoded string containing the encryption key (this'll* generally be the file's key).*- * @returns The decrypted utf-8 string.+ * @returns The decrypted metadata bytes.*/export const decryptFileMetadata = async (encryptedMetadataB64: string,decryptionHeaderB64: string,keyB64: string,-) => {- const metadataBytes = await libsodium.decryptChaChaOneShot(+) =>+ libsodium.decryptChaChaOneShot(await libsodium.fromB64(encryptedMetadataB64),await libsodium.fromB64(decryptionHeaderB64),keyB64,);- const textDecoder = new TextDecoder();- return textDecoder.decode(metadataBytes);-};++/**+ * Decrypt arbitrary string metadata associated with a file using the file's+ * key. This is a variant of {@link decryptFileMetadata} returns the decrypted+ * utf-8 string.+ */+export const decryptFileMetadataString = async (+ encryptedMetadataB64: string,+ decryptionHeaderB64: string,+ keyB64: string,+) =>+ new TextDecoder().decode(+ await decryptFileMetadata(+ encryptedMetadataB64,+ decryptionHeaderB64,+ keyB64,+ ),+ );