π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Keygen
Manav Rathi9af44e15b4c9
diff --git a/web/packages/base/crypto/index.ts b/web/packages/base/crypto/index.tsindex c2cf7bc005..eceea2408d 100644--- a/web/packages/base/crypto/index.ts+++ b/web/packages/base/crypto/index.ts@@ -89,10 +89,16 @@ const assertInWorker = <T>(x: T): T => {};/**- * Generate a new randomly generated 256-bit key suitable for use with the *Box+ * Return a new randomly generated 256-bit key suitable for use with the *Box* encryption functions.*/-export const generateBoxKey = libsodium.generateBoxKey;+export const generateNewBoxKey = libsodium.generateNewBoxKey;++/**+ * Return a new randomly generated 256-bit key suitable for use with the *Blob+ * or *Stream encryption functions.+ */+export const generateNewBlobOrStreamKey = libsodium.generateNewBlobOrStreamKey;/*** Encrypt the given data, returning a box containing the encrypted data and adiff --git a/web/packages/base/crypto/libsodium.ts b/web/packages/base/crypto/libsodium.tsindex cd91633c17..25ff0057e9 100644--- a/web/packages/base/crypto/libsodium.ts+++ b/web/packages/base/crypto/libsodium.ts@@ -134,11 +134,22 @@ const bytes = async (bob: BytesOrB64) =>* This returns a new randomly generated 256-bit key suitable for being used* with libsodium's secretbox APIs.*/-export const generateBoxKey = async () => {+export const generateNewBoxKey = async () => {await sodium.ready;return toB64(sodium.crypto_secretbox_keygen());};+/**+ * Generate a key for use with the *Blob or *Stream encryption functions.+ *+ * This returns a new randomly generated 256-bit key suitable for being used+ * with libsodium's secretstream APIs.+ */+export const generateNewBlobOrStreamKey = async () => {+ await sodium.ready;+ return toB64(sodium.crypto_secretstream_xchacha20poly1305_keygen());+};+/*** Encrypt the given data using libsodium's secretbox APIs, using a randomly* generated nonce.diff --git a/web/packages/new/photos/services/ml/cgroups.ts b/web/packages/new/photos/services/ml/cgroups.tsindex 42274a7e37..49388eb990 100644--- a/web/packages/new/photos/services/ml/cgroups.ts+++ b/web/packages/new/photos/services/ml/cgroups.ts@@ -118,6 +118,7 @@ export const syncCGroups = () => {//// The user can see both the cgroups and clusters in the UI, but only the// cgroups are synced.+ // const syncCGroupsWithRemote()/** After clustering, we also do some routine cleanup. Faces belonging to files* that have been deleted (including those in Trash) should be pruned off.diff --git a/web/packages/new/photos/services/user-entity.ts b/web/packages/new/photos/services/user-entity.tsindex ab76dce517..927ed08168 100644--- a/web/packages/new/photos/services/user-entity.ts+++ b/web/packages/new/photos/services/user-entity.ts@@ -2,7 +2,7 @@ import {decryptBlob,decryptBoxB64,encryptBoxB64,- generateBoxKey,+ generateNewBlobOrStreamKey,} from "@/base/crypto";import { authenticatedRequestHeaders, ensureOk, HTTPError } from "@/base/http";import { getKV, getKVN, setKV } from "@/base/kv";@@ -201,16 +201,15 @@ const getOrCreateEntityKeyB64 = async (type: EntityType) => {}// Nada. Create a new one, put it to remote, save it locally, and return.- // TODO-Cluster Keep this read only, only add the writeable bits after other- // stuff has been tested.- throw new Error("Not implemented");- // const generatedKeyB64 = await worker.generateEncryptionKey();- // const encryptedNewKey = await worker.encryptToB64(- // generatedKeyB64,- // encryptionKeyB64,- // );- // await postUserEntityKey(type, newKey);- // return decrypt(newKey);++ // As a sanity check, genarate the key but immediately encrypt it as if it+ // were fetched from remote and then try to decrypt it before doing anything+ // with it.+ const generated = await generateNewEncryptedEntityKey();+ const result = decryptEntityKey(generated);+ await postUserEntityKey(type, generated);+ await saveRemoteUserEntityKey(type, generated);+ return result;};const entityKeyKey = (type: EntityType) => `entityKey/${type}`;@@ -235,12 +234,17 @@ const saveRemoteUserEntityKey = () => setKV(entityKeyKey(type), JSON.stringify(entityKey));/**- * Generate a new entity key and return it after encrypting it using the user's- * master key.+ * Generate a new entity key and return it in the shape of an+ * {@link RemoteUserEntityKey} after encrypting it using the user's master key.*/-// TODO: Temporary export to silence lint-export const generateEncryptedEntityKey = async () =>- encryptBoxB64(await generateBoxKey(), await masterKeyFromSession());+const generateNewEncryptedEntityKey = async () => {+ const { encryptedData, nonce } = await encryptBoxB64(+ await generateNewBlobOrStreamKey(),+ await masterKeyFromSession(),+ );+ // Remote calls it the header, but it really is the nonce.+ return { encryptedKey: encryptedData, header: nonce };+};/*** Decrypt an encrypted entity key using the user's master key.@@ -283,7 +287,9 @@ const getUserEntityKey = async (};const RemoteUserEntityKey = z.object({+ /** Base64 encoded entity key, encrypted with the user's master key. */encryptedKey: z.string(),+ /** Base64 encoded nonce used during encryption of this entity key. */header: z.string(),});@@ -294,8 +300,7 @@ type RemoteUserEntityKey = z.infer<typeof RemoteUserEntityKey>;** See: [Note: User entity keys]*/-// TODO-Cluster remove export-export const postUserEntityKey = async (+const postUserEntityKey = async (type: EntityType,entityKey: RemoteUserEntityKey,) => {