Skip to content

armgit / ente

Public Imported from GitHub
0

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

ret 2

Manav Rathi413f5479ef34
diff --git a/web/packages/base/crypto/ente-impl.ts b/web/packages/base/crypto/ente-impl.ts
index e6123ae1c5..7c9feeb148 100644
--- a/web/packages/base/crypto/ente-impl.ts
+++ b/web/packages/base/crypto/ente-impl.ts
@@ -64,11 +64,11 @@ export const _decryptBoxBytes = libsodium.decryptBoxBytes;
export const _decryptBox = libsodium.decryptBox;
-export const _decryptBlob = libsodium.decryptBlob;
+export const _decryptBlobBytes = libsodium.decryptBlobBytes;
-export const _decryptBlobB64 = libsodium.decryptBlobB64;
+export const _decryptBlob = libsodium.decryptBlob;
-export const _decryptThumbnail = _decryptBlob;
+export const _decryptThumbnail = _decryptBlobBytes;
export const _decryptStreamBytes = libsodium.decryptStreamBytes;
@@ -81,7 +81,7 @@ export const _decryptMetadataJSON_New = async (
key: BytesOrB64,
) =>
JSON.parse(
- new TextDecoder().decode(await _decryptBlob(blob, key)),
+ new TextDecoder().decode(await _decryptBlobBytes(blob, key)),
) as unknown;
export const _decryptMetadataJSON = async (r: {
diff --git a/web/packages/base/crypto/index.ts b/web/packages/base/crypto/index.ts
index 9c1fbb3198..1d3a5123be 100644
--- a/web/packages/base/crypto/index.ts
+++ b/web/packages/base/crypto/index.ts
@@ -181,7 +181,7 @@ export const encryptBoxB64 = (data: BytesOrB64, key: BytesOrB64) =>
* This function is usually used to encrypt data associated with an Ente object
* (file, collection, entity) using the object's key.
*
- * Use {@link decryptBlob} to decrypt the result.
+ * Use {@link decryptBlob} or {@link decryptBlobBytes} to decrypt the result.
*
* > The suffix "Blob" comes from our convention of naming functions that use
* > the secretstream APIs without breaking the data into chunks.
@@ -197,7 +197,7 @@ export const encryptBlob = (data: BytesOrB64, key: BytesOrB64) =>
* A variant of {@link encryptBlob} that returns the result components as bytes
* instead of as base64 strings.
*
- * Use {@link decryptBlob} to decrypt the result.
+ * Use {@link decryptBlob} or {@link decryptBlobBytes} to decrypt the result.
*/
export const encryptBlobBytes = (data: BytesOrB64, key: BytesOrB64) =>
assertInWorker(ei._encryptBlobBytes(data, key));
@@ -303,7 +303,7 @@ export const decryptBoxBytes = (box: EncryptedBox, key: BytesOrB64) =>
/**
* Decrypt a blob encrypted using either {@link encryptBlobBytes} or
- * {@link encryptBlob}.
+ * {@link encryptBlob} and return it as a base64 encoded string.
*/
export const decryptBlob = (blob: EncryptedBlob, key: BytesOrB64) =>
inWorker()
@@ -311,12 +311,13 @@ export const decryptBlob = (blob: EncryptedBlob, key: BytesOrB64) =>
: sharedWorker().then((w) => w.decryptBlob(blob, key));
/**
- * A variant of {@link decryptBlob} that returns the result as a base64 string.
+ * A variant of {@link decryptBlobBytes} that returns the result bytes directly
+ * (instead of encoding them as a base64 string).
*/
-export const decryptBlobB64 = (blob: EncryptedBlob, key: BytesOrB64) =>
+export const decryptBlobBytes = (blob: EncryptedBlob, key: BytesOrB64) =>
inWorker()
- ? ei._decryptBlobB64(blob, key)
- : sharedWorker().then((w) => w.decryptBlobB64(blob, key));
+ ? ei._decryptBlobBytes(blob, key)
+ : sharedWorker().then((w) => w.decryptBlobBytes(blob, key));
/**
* Decrypt the thumbnail encrypted using {@link encryptThumbnail}.
diff --git a/web/packages/base/crypto/libsodium.ts b/web/packages/base/crypto/libsodium.ts
index efa31aeaf6..af1cc49acd 100644
--- a/web/packages/base/crypto/libsodium.ts
+++ b/web/packages/base/crypto/libsodium.ts
@@ -173,7 +173,7 @@ export const generateBlobOrStreamKey = async () => {
* Encrypt the given data using libsodium's secretbox APIs, using a randomly
* generated nonce.
*
- * Use {@link decryptBoxBytes} to decrypt the result.
+ * Use {@link decryptBox} or {@link decryptBoxBytes} to decrypt the result.
*
* @param data The data to encrypt.
*
@@ -286,7 +286,7 @@ export const encryptBoxB64 = async (
/**
* Encrypt the given data using libsodium's secretstream APIs without chunking.
*
- * Use {@link decryptBlob} to decrypt the result.
+ * Use {@link decryptBlobBytes} to decrypt the result.
*
* @param data The data to encrypt.
*
@@ -494,7 +494,7 @@ export const decryptBox = (
/**
* Decrypt the result of {@link encryptBlobBytes} or {@link encryptBlob}.
*/
-export const decryptBlob = async (
+export const decryptBlobBytes = async (
{ encryptedData, decryptionHeader }: EncryptedBlob,
key: BytesOrB64,
): Promise<Uint8Array> => {
@@ -512,12 +512,13 @@ export const decryptBlob = async (
};
/**
- * A variant of {@link decryptBlob} that returns the result as a base64 string.
+ * A variant of {@link decryptBlobBytes} that returns the result as a base64
+ * string.
*/
-export const decryptBlobB64 = (
+export const decryptBlob = (
blob: EncryptedBlob,
key: BytesOrB64,
-): Promise<string> => decryptBlob(blob, key).then(toB64);
+): Promise<string> => decryptBlobBytes(blob, key).then(toB64);
/**
* Decrypt the result of {@link encryptStreamBytes}.
diff --git a/web/packages/base/crypto/worker.ts b/web/packages/base/crypto/worker.ts
index 64737f61fe..9a43b6bd79 100644
--- a/web/packages/base/crypto/worker.ts
+++ b/web/packages/base/crypto/worker.ts
@@ -30,8 +30,8 @@ export class CryptoWorker {
encryptMetadataJSON = ei._encryptMetadataJSON;
decryptBoxBytes = ei._decryptBoxBytes;
decryptBox = ei._decryptBox;
+ decryptBlobBytes = ei._decryptBlobBytes;
decryptBlob = ei._decryptBlob;
- decryptBlobB64 = ei._decryptBlobB64;
decryptThumbnail = ei._decryptThumbnail;
decryptStreamBytes = ei._decryptStreamBytes;
initChunkDecryption = ei._initChunkDecryption;
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index b3f4ebb775..0587ebc3af 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -1,6 +1,6 @@
import { isDesktop } from "ente-base/app";
import { assertionFailed } from "ente-base/assert";
-import { decryptBlob, encryptBlob } from "ente-base/crypto";
+import { decryptBlobBytes, encryptBlob } from "ente-base/crypto";
import type { EncryptedBlob } from "ente-base/crypto/types";
import { ensureElectron } from "ente-base/electron";
import { isHTTP4xxError, type PublicAlbumsCredentials } from "ente-base/http";
@@ -484,7 +484,7 @@ const decryptPlaylistJSON = async (
encryptedPlaylist: EncryptedBlob,
file: EnteFile,
) => {
- const decryptedBytes = await decryptBlob(encryptedPlaylist, file.key);
+ const decryptedBytes = await decryptBlobBytes(encryptedPlaylist, file.key);
const jsonString = await gunzip(decryptedBytes);
return PlaylistJSON.parse(JSON.parse(jsonString));
};
diff --git a/web/packages/new/photos/services/ml/ml-data.ts b/web/packages/new/photos/services/ml/ml-data.ts
index 5f035d9cc0..28271ec65e 100644
--- a/web/packages/new/photos/services/ml/ml-data.ts
+++ b/web/packages/new/photos/services/ml/ml-data.ts
@@ -1,4 +1,4 @@
-import { decryptBlob } from "ente-base/crypto";
+import { decryptBlobBytes } from "ente-base/crypto";
import log from "ente-base/log";
import { fetchFilesData, putFileData } from "ente-gallery/services/file-data";
import type { EnteFile } from "ente-media/file";
@@ -169,11 +169,14 @@ export const fetchMLData = async (
}
try {
- // See: [Note: strict mode migration]
- //
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore
- const decryptedBytes = await decryptBlob(remoteFileData, file.key);
+ const decryptedBytes = await decryptBlobBytes(
+ remoteFileData,
+ // See: [Note: strict mode migration]
+ //
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore
+ file.key,
+ );
const jsonString = await gunzip(decryptedBytes);
result.set(
fileID,
diff --git a/web/packages/new/photos/services/user-entity/remote.ts b/web/packages/new/photos/services/user-entity/remote.ts
index 54b5048cc6..beb8448cea 100644
--- a/web/packages/new/photos/services/user-entity/remote.ts
+++ b/web/packages/new/photos/services/user-entity/remote.ts
@@ -1,4 +1,4 @@
-import { decryptBlob } from "ente-base/crypto";
+import { decryptBlobBytes } from "ente-base/crypto";
import type { EncryptedBlobB64 } from "ente-base/crypto/types";
import {
authenticatedRequestHeaders,
@@ -132,7 +132,7 @@ export const userEntityDiff = async (
entityKeyB64: string,
): Promise<UserEntityChange[]> => {
const decrypt = (encryptedData: string, decryptionHeader: string) =>
- decryptBlob({ encryptedData, decryptionHeader }, entityKeyB64);
+ decryptBlobBytes({ encryptedData, decryptionHeader }, entityKeyB64);
const params = new URLSearchParams({
type,