π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Decrypt
Manav Rathi46082796d7c4
diff --git a/web/packages/base/crypto/ente.ts b/web/packages/base/crypto/ente.tsindex 017c38aa2c..f1dedb94e0 100644--- a/web/packages/base/crypto/ente.ts+++ b/web/packages/base/crypto/ente.ts@@ -115,7 +115,7 @@ export const encryptMetadata = async (metadata: unknown, keyB64: string) => {** This is the sibling of {@link encryptAssociatedData}.*- * See {@link decryptChaChaOneShot2} for the implementation details.+ * See {@link decryptChaChaOneShot} for the implementation details.** @param encryptedData A {@link Uint8Array} containing the bytes to decrypt.*@@ -166,7 +166,7 @@ export const decryptFileEmbedding = async (* Decrypt the metadata associated with an Ente object (file, collection or* entity) using the object's key.*- * This is the sibling of {@link decryptMetadata}.+ * This is the sibling of {@link encryptMetadata}.** @param encryptedDataB64 base64 encoded string containing the encrypted data.*@@ -180,7 +180,6 @@ export const decryptFileEmbedding = async (* @returns The decrypted JSON value. Since TypeScript does not have a native* JSON type, we need to return it as an `unknown`.*/-export const decryptMetadata = async (encryptedDataB64: string,decryptionHeaderB64: string,@@ -188,10 +187,26 @@ export const decryptMetadata = async () =>JSON.parse(new TextDecoder().decode(- await decryptAssociatedData(- await libsodium.fromB64(encryptedDataB64),+ await decryptMetadataBytes(+ encryptedDataB64,decryptionHeaderB64,keyB64,),),) as unknown;++/**+ * A variant of {@link decryptMetadata} that does not attempt to parse the+ * decrypted data as a JSON string and instead just returns the raw decrypted+ * bytes that we got.+ */+export const decryptMetadataBytes = async (+ encryptedDataB64: string,+ decryptionHeaderB64: string,+ keyB64: string,+) =>+ await decryptAssociatedData(+ await libsodium.fromB64(encryptedDataB64),+ decryptionHeaderB64,+ keyB64,+ );diff --git a/web/packages/new/photos/services/user-entity.ts b/web/packages/new/photos/services/user-entity.tsindex 9b3335952e..939ed9d4e9 100644--- a/web/packages/new/photos/services/user-entity.ts+++ b/web/packages/new/photos/services/user-entity.ts@@ -1,3 +1,4 @@+import { decryptMetadataBytes } from "@/base/crypto/ente";import { authenticatedRequestHeaders, ensureOk } from "@/base/http";import { apiURL } from "@/base/origins";import { z } from "zod";@@ -69,7 +70,7 @@ const RemoteUserEntity = z.object({header: z.string(),isDeleted: z.boolean(),updatedAt: z.number(),-}+});/*** Fetch all user entities of the given type that have been created or updated@@ -81,13 +82,17 @@ const RemoteUserEntity = z.object({* only entities whose {@link updatedAt} is more than the given value. Set this* to zero to start from the beginning.*- * @param entityKey The key to use for decrypting the encrypted contents of the- * user entity.+ * @param entityKeyB64 The base64 encoded key to use for decrypting the+ * encrypted contents of the user entity.*/export const userEntityDiff = async (type: EntityType,sinceTime: number,-): Promise<RemoteUserEntity[]> => {+ entityKeyB64: string,+): Promise<UserEntity[]> => {+ const decrypt = (dataB64: string, headerB64: string) =>+ decryptMetadataBytes(dataB64, headerB64, entityKeyB64);+const params = new URLSearchParams({type,sinceTime: sinceTime.toString(),@@ -98,4 +103,17 @@ export const userEntityDiff = async (headers: await authenticatedRequestHeaders(),});ensureOk(res);+ const entities = z+ .object({ diff: z.array(RemoteUserEntity) })+ .parse(await res.json()).diff;+ return Promise.all(+ entities.map(+ async ({ encryptedData, header, isDeleted, updatedAt }) => ({+ data: isDeleted+ ? undefined+ : await decrypt(encryptedData, header),+ updatedAt,+ }),+ ),+ );};