Skip to content

armgit / ente

Public Imported from GitHub
0

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

Transparent but handrolled proxy

Manav Rathia029b168516f
diff --git a/web/packages/base/crypto/ente.ts b/web/packages/base/crypto/ente.ts
index f1dedb94e0..74dfb800bb 100644
--- a/web/packages/base/crypto/ente.ts
+++ b/web/packages/base/crypto/ente.ts
@@ -17,7 +17,11 @@
* 2. internal/libsodium.ts (wrappers over libsodium)
* 3. libsodium (JS bindings).
*/
+import ComlinkCryptoWorker from "@ente/shared/crypto";
import * as libsodium from "@ente/shared/crypto/internal/libsodium";
+import { inWorker } from "../env";
+
+const cryptoWorker = () => ComlinkCryptoWorker.getInstance();
/**
* Encrypt arbitrary data associated with an Ente object (file, collection,
@@ -200,7 +204,22 @@ export const decryptMetadata = async (
* decrypted data as a JSON string and instead just returns the raw decrypted
* bytes that we got.
*/
-export const decryptMetadataBytes = async (
+export const decryptMetadataBytes = (
+ encryptedDataB64: string,
+ decryptionHeaderB64: string,
+ keyB64: string,
+) =>
+ inWorker()
+ ? decryptMetadataBytesI(encryptedDataB64, decryptionHeaderB64, keyB64)
+ : cryptoWorker().then((cw) =>
+ cw.decryptMetadataBytes(
+ encryptedDataB64,
+ decryptionHeaderB64,
+ keyB64,
+ ),
+ );
+
+export const decryptMetadataBytesI = async (
encryptedDataB64: string,
decryptionHeaderB64: string,
keyB64: string,
diff --git a/web/packages/shared/crypto/internal/crypto.worker.ts b/web/packages/shared/crypto/internal/crypto.worker.ts
index 356bde8580..15b6b15b27 100644
--- a/web/packages/shared/crypto/internal/crypto.worker.ts
+++ b/web/packages/shared/crypto/internal/crypto.worker.ts
@@ -40,6 +40,10 @@ export class DedicatedCryptoWorker {
);
}
+ async decryptMetadataBytes(a: string, b: string, c: string) {
+ return ente.decryptMetadataBytesI(a, b, c);
+ }
+
async decryptFile(fileData: Uint8Array, header: Uint8Array, key: string) {
return libsodium.decryptChaCha(fileData, header, key);
}