Use same nomenclature as the architecture document

This commit is contained in:
Manav Rathi
2024-08-16 21:34:25 +05:30
parent 3962f3a133
commit d91462773a
7 changed files with 31 additions and 24 deletions

View File

@@ -45,9 +45,9 @@ import { convertToJPEG, generateImageThumbnail } from "./services/image";
import { logout } from "./services/logout";
import { createMLWorker } from "./services/ml";
import {
encryptionKey,
lastShownChangelogVersion,
saveEncryptionKey,
masterKeyB64,
saveMasterKeyB64,
setLastShownChangelogVersion,
} from "./services/store";
import {
@@ -103,10 +103,10 @@ export const attachIPCHandlers = () => {
ipcMain.handle("selectDirectory", () => selectDirectory());
ipcMain.handle("encryptionKey", () => encryptionKey());
ipcMain.handle("masterKeyB64", () => masterKeyB64());
ipcMain.handle("saveEncryptionKey", (_, encryptionKey: string) =>
saveEncryptionKey(encryptionKey),
ipcMain.handle("saveMasterKeyB64", (_, masterKeyB64: string) =>
saveMasterKeyB64(masterKeyB64),
);
ipcMain.handle("lastShownChangelogVersion", () =>

View File

@@ -24,13 +24,13 @@ 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 saveEncryptionKey = (encryptionKey: string) => {
const encryptedKey = safeStorage.encryptString(encryptionKey);
export const saveMasterKeyB64 = (masterKeyB64: string) => {
const encryptedKey = safeStorage.encryptString(masterKeyB64);
const b64EncryptedKey = Buffer.from(encryptedKey).toString("base64");
safeStorageStore.set("encryptionKey", b64EncryptedKey);
};
export const encryptionKey = (): string | undefined => {
export const masterKeyB64 = (): string | undefined => {
const b64EncryptedKey = safeStorageStore.get("encryptionKey");
if (!b64EncryptedKey) return undefined;
const keyBuffer = Buffer.from(b64EncryptedKey, "base64");

View File

@@ -103,10 +103,10 @@ const logout = () => {
return ipcRenderer.invoke("logout");
};
const encryptionKey = () => ipcRenderer.invoke("encryptionKey");
const masterKeyB64 = () => ipcRenderer.invoke("masterKeyB64");
const saveEncryptionKey = (encryptionKey: string) =>
ipcRenderer.invoke("saveEncryptionKey", encryptionKey);
const saveMasterKeyB64 = (masterKeyB64: string) =>
ipcRenderer.invoke("saveMasterKeyB64", masterKeyB64);
const lastShownChangelogVersion = () =>
ipcRenderer.invoke("lastShownChangelogVersion");
@@ -342,8 +342,8 @@ contextBridge.exposeInMainWorld("electron", {
openLogDirectory,
selectDirectory,
logout,
encryptionKey,
saveEncryptionKey,
masterKeyB64,
saveMasterKeyB64,
lastShownChangelogVersion,
setLastShownChangelogVersion,
onMainWindowFocus,

View File

@@ -73,9 +73,9 @@ export default function LandingPage() {
const electron = globalThis.electron;
if (!key && electron) {
try {
key = await electron.encryptionKey();
key = await electron.masterKeyB64();
} catch (e) {
log.error("Failed to get encryption key from electron", e);
log.error("Failed to read master key from secure storage", e);
}
if (key) {
await saveKeyInSessionStore(

View File

@@ -125,9 +125,12 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
const electron = globalThis.electron;
if (!key && electron) {
try {
key = await electron.encryptionKey();
key = await electron.masterKeyB64();
} catch (e) {
log.error("Failed to get encryption key from electron", e);
log.error(
"Failed to read master key from secure storage",
e,
);
}
if (key) {
await saveKeyInSessionStore(

View File

@@ -69,18 +69,22 @@ export interface Electron {
logout: () => Promise<void>;
/**
* Return the previously saved encryption key from persistent safe storage.
* Return the previously saved user's master key from the persistent safe
* storage accessible to the desktop app.
*
* If no such key is found, return `undefined`.
* The key is returned as a base64 encoded string.
*
* See also: {@link saveEncryptionKey}.
* If the key is not found, return `undefined`.
*
* See also: {@link saveMasterKeyB64}.
*/
encryptionKey: () => Promise<string | undefined>;
masterKeyB64: () => Promise<string | undefined>;
/**
* Save the given {@link encryptionKey} into persistent safe storage.
* Save the given {@link masterKeyB64} (encoded as a base64 string) to the
* persistent safe storage accessible to the desktop app.
*/
saveEncryptionKey: (encryptionKey: string) => Promise<void>;
saveMasterKeyB64: (masterKeyB64: string) => Promise<void>;
/**
* Set or clear the callback {@link cb} to invoke whenever the app comes

View File

@@ -108,7 +108,7 @@ export const saveKeyInSessionStore = async (
setKey(keyType, sessionKeyAttributes);
const electron = globalThis.electron;
if (electron && !fromDesktop && keyType === SESSION_KEYS.ENCRYPTION_KEY) {
electron.saveEncryptionKey(key);
electron.saveMasterKeyB64(key);
}
};