π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Rename
Manav Rathi0381cf66dcc4
diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.tsindex b4e7eff0ca..ce977a5088 100644--- a/desktop/src/main/ipc.ts+++ b/desktop/src/main/ipc.ts@@ -50,8 +50,8 @@ import { convertToJPEG, generateImageThumbnail } from "./services/image";import { logout } from "./services/logout";import {lastShownChangelogVersion,- masterKeyB64,- saveMasterKeyB64,+ masterKeyFromSafeStorage,+ saveMasterKeyInSafeStorage,setLastShownChangelogVersion,} from "./services/store";import {@@ -108,10 +108,12 @@ export const attachIPCHandlers = () => {ipcMain.handle("selectDirectory", () => selectDirectory());- ipcMain.handle("masterKeyB64", () => masterKeyB64());+ ipcMain.handle("masterKeyFromSafeStorage", () =>+ masterKeyFromSafeStorage(),+ );- ipcMain.handle("saveMasterKeyB64", (_, masterKeyB64: string) =>- saveMasterKeyB64(masterKeyB64),+ ipcMain.handle("saveMasterKeyInSafeStorage", (_, masterKey: string) =>+ saveMasterKeyInSafeStorage(masterKey),);ipcMain.handle("lastShownChangelogVersion", () =>diff --git a/desktop/src/main/services/store.ts b/desktop/src/main/services/store.tsindex f4f5a9369a..227fe691c6 100644--- a/desktop/src/main/services/store.ts+++ b/desktop/src/main/services/store.ts@@ -24,17 +24,17 @@ export const clearStores = () => {* On macOS, `safeStorage` stores our data under a Keychain entry named* "<app-name> Safe Storage". In our case, "ente Safe Storage".*/-export const saveMasterKeyB64 = (masterKeyB64: string) => {- const encryptedKey = safeStorage.encryptString(masterKeyB64);- const b64EncryptedKey = Buffer.from(encryptedKey).toString("base64");- safeStorageStore.set("encryptionKey", b64EncryptedKey);+export const saveMasterKeyInSafeStorage = (masterKey: string) => {+ const encryptedKeyBuffer = safeStorage.encryptString(masterKey);+ const encryptedKey = Buffer.from(encryptedKeyBuffer).toString("base64");+ safeStorageStore.set("encryptionKey", encryptedKey);};-export const masterKeyB64 = (): string | undefined => {- const b64EncryptedKey = safeStorageStore.get("encryptionKey");- if (!b64EncryptedKey) return undefined;- const keyBuffer = Buffer.from(b64EncryptedKey, "base64");- return safeStorage.decryptString(keyBuffer);+export const masterKeyFromSafeStorage = (): string | undefined => {+ const encryptedKey = safeStorageStore.get("encryptionKey");+ if (!encryptedKey) return undefined;+ const encryptedKeyBuffer = Buffer.from(encryptedKey, "base64");+ return safeStorage.decryptString(encryptedKeyBuffer);};export const lastShownChangelogVersion = (): number | undefined =>diff --git a/desktop/src/preload.ts b/desktop/src/preload.tsindex e983855d5f..ea6a7af7b2 100644--- a/desktop/src/preload.ts+++ b/desktop/src/preload.ts@@ -113,10 +113,11 @@ const logout = () => {return ipcRenderer.invoke("logout");};-const masterKeyB64 = () => ipcRenderer.invoke("masterKeyB64");+const masterKeyFromSafeStorage = () =>+ ipcRenderer.invoke("masterKeyFromSafeStorage");-const saveMasterKeyB64 = (masterKeyB64: string) =>- ipcRenderer.invoke("saveMasterKeyB64", masterKeyB64);+const saveMasterKeyInSafeStorage = (masterKey: string) =>+ ipcRenderer.invoke("saveMasterKeyInSafeStorage", masterKey);const lastShownChangelogVersion = () =>ipcRenderer.invoke("lastShownChangelogVersion");@@ -358,8 +359,8 @@ contextBridge.exposeInMainWorld("electron", {selectDirectory,pathForFile,logout,- masterKeyB64,- saveMasterKeyB64,+ masterKeyFromSafeStorage,+ saveMasterKeyInSafeStorage,lastShownChangelogVersion,setLastShownChangelogVersion,isAutoLaunchEnabled,diff --git a/web/packages/base/session.ts b/web/packages/base/session.tsindex 13539e49fd..d1b41a4630 100644--- a/web/packages/base/session.ts+++ b/web/packages/base/session.ts@@ -86,7 +86,7 @@ export const saveMasterKeyInSessionStore = async (await saveKeyInSessionStore("encryptionKey", masterKey);const electron = globalThis.electron;if (electron && !fromDesktop) {- await electron.saveMasterKeyB64(masterKey);+ await electron.saveMasterKeyInSafeStorage(masterKey);}};@@ -138,7 +138,7 @@ export const updateSessionFromElectronSafeStorageIfNeeded = async () => {let masterKey: string | undefined;try {- masterKey = await electron.masterKeyB64();+ masterKey = await electron.masterKeyFromSafeStorage();} catch (e) {log.error("Failed to read master key from safe storage", e);}diff --git a/web/packages/base/types/ipc.ts b/web/packages/base/types/ipc.tsindex d44a92e980..ed41ac0453 100644--- a/web/packages/base/types/ipc.ts+++ b/web/packages/base/types/ipc.ts@@ -90,15 +90,15 @@ export interface Electron {** If the key is not found, return `undefined`.*- * See also: {@link saveMasterKeyB64}.+ * See also: {@link saveMasterKeyInSafeStorage}.*/- masterKeyB64: () => Promise<string | undefined>;+ masterKeyFromSafeStorage: () => Promise<string | undefined>;/**- * Save the given {@link masterKeyB64} (encoded as a base64 string) to the+ * Save the given {@link masterKey} (encoded as a base64 string) to the* persistent safe storage accessible to the desktop app.*/- saveMasterKeyB64: (masterKeyB64: string) => Promise<void>;+ saveMasterKeyInSafeStorage: (masterKey: string) => Promise<void>;/*** Set or clear the callback {@link cb} to invoke whenever the app comesdiff --git a/web/packages/shared/crypto/helpers.ts b/web/packages/shared/crypto/helpers.tsindex 315fa3b36d..56ba94cee4 100644--- a/web/packages/shared/crypto/helpers.ts+++ b/web/packages/shared/crypto/helpers.ts@@ -12,6 +12,6 @@ export const saveKeyInSessionStore = async (setKey(keyType, sessionKeyAttributes);const electron = globalThis.electron;if (electron && !fromDesktop && keyType == "encryptionKey") {- electron.saveMasterKeyB64(key);+ electron.saveMasterKeyInSafeStorage(key);}};