fix: Major bug cleanup pass 1
All checks were successful
Queue Release Build / prepare (push) Successful in 19s
Deploy Web Apps / deploy (push) Successful in 8m12s
Queue Release Build / build-windows (push) Successful in 27m44s
Queue Release Build / build-linux (push) Successful in 48m1s
Queue Release Build / build-android (push) Successful in 22m7s
Queue Release Build / finalize (push) Successful in 2m42s
All checks were successful
Queue Release Build / prepare (push) Successful in 19s
Deploy Web Apps / deploy (push) Successful in 8m12s
Queue Release Build / build-windows (push) Successful in 27m44s
Queue Release Build / build-linux (push) Successful in 48m1s
Queue Release Build / build-android (push) Successful in 22m7s
Queue Release Build / finalize (push) Successful in 2m42s
This commit is contained in:
60
electron/api/provision-secret-store.ts
Normal file
60
electron/api/provision-secret-store.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { safeStorage } from 'electron';
|
||||
import {
|
||||
mkdir,
|
||||
readFile,
|
||||
writeFile
|
||||
} from 'fs/promises';
|
||||
import path from 'path';
|
||||
import { app } from 'electron';
|
||||
|
||||
const STORAGE_DIR_NAME = 'provision-secrets';
|
||||
|
||||
function getStorageDir(): string {
|
||||
return path.join(app.getPath('userData'), STORAGE_DIR_NAME);
|
||||
}
|
||||
|
||||
function getSecretFilePath(homeUserId: string): string {
|
||||
return path.join(getStorageDir(), `${homeUserId}.bin`);
|
||||
}
|
||||
|
||||
async function ensureStorageDir(): Promise<void> {
|
||||
await mkdir(getStorageDir(), { recursive: true });
|
||||
}
|
||||
|
||||
export async function storeProvisionSecret(homeUserId: string, secret: string): Promise<boolean> {
|
||||
if (!homeUserId.trim() || !secret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await ensureStorageDir();
|
||||
|
||||
if (!safeStorage.isEncryptionAvailable()) {
|
||||
await writeFile(getSecretFilePath(homeUserId), secret, 'utf8');
|
||||
return true;
|
||||
}
|
||||
|
||||
const encrypted = safeStorage.encryptString(secret);
|
||||
|
||||
await writeFile(getSecretFilePath(homeUserId), encrypted);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function getProvisionSecret(homeUserId: string): Promise<string | null> {
|
||||
if (!homeUserId.trim()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const filePath = getSecretFilePath(homeUserId);
|
||||
const payload = await readFile(filePath);
|
||||
|
||||
if (!safeStorage.isEncryptionAvailable()) {
|
||||
return payload.toString('utf8');
|
||||
}
|
||||
|
||||
return safeStorage.decryptString(payload);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
type DesktopSettings
|
||||
} from '../desktop-settings';
|
||||
import { applyLocalApiSettings, getLocalApiSnapshot } from '../api';
|
||||
import { getProvisionSecret, storeProvisionSecret } from '../api/provision-secret-store';
|
||||
import {
|
||||
activateLinuxScreenShareAudioRouting,
|
||||
deactivateLinuxScreenShareAudioRouting,
|
||||
@@ -62,7 +63,11 @@ import { listRunningProcessNames } from '../process-list';
|
||||
import { detectActiveGame } from '../game-detection';
|
||||
import { collectAppMetricsSnapshot } from '../app-metrics';
|
||||
import { clearAllTokens } from '../api/auth-store';
|
||||
import { assertPathUnderUserData, grantPluginReadRoot, resolveReadablePath } from '../path-jail';
|
||||
import {
|
||||
assertPathUnderUserData,
|
||||
grantPluginReadRoot,
|
||||
resolveReadablePath
|
||||
} from '../path-jail';
|
||||
|
||||
const DEFAULT_MIME_TYPE = 'application/octet-stream';
|
||||
const MAX_ACTIVE_DESKTOP_NOTIFICATIONS = 20;
|
||||
@@ -380,6 +385,14 @@ export function setupSystemHandlers(): void {
|
||||
|
||||
ipcMain.handle('get-app-metrics', () => collectAppMetricsSnapshot());
|
||||
|
||||
ipcMain.handle('store-provision-secret', async (_event, homeUserId: string, secret: string) =>
|
||||
await storeProvisionSecret(homeUserId, secret)
|
||||
);
|
||||
|
||||
ipcMain.handle('get-provision-secret', async (_event, homeUserId: string) =>
|
||||
await getProvisionSecret(homeUserId)
|
||||
);
|
||||
|
||||
ipcMain.handle('get-app-data-path', () => app.getPath('userData'));
|
||||
ipcMain.handle('open-current-data-folder', async () => await openCurrentDataFolder());
|
||||
ipcMain.handle('export-user-data', async () => await exportUserData());
|
||||
|
||||
@@ -37,8 +37,10 @@ describe('path-jail', () => {
|
||||
|
||||
it('accepts cached plugin bundle paths under plugin-bundles', async () => {
|
||||
const bundleDir = path.join(tempRoot, 'plugin-bundles', 'example.plugin', '1.0.0');
|
||||
|
||||
fs.mkdirSync(bundleDir, { recursive: true });
|
||||
const bundlePath = path.join(bundleDir, 'main.js');
|
||||
|
||||
fs.writeFileSync(bundlePath, 'export default {}');
|
||||
|
||||
await expect(assertPathUnderRoot(tempRoot, bundlePath)).resolves.toBe(bundlePath);
|
||||
@@ -59,6 +61,7 @@ describe('path-jail', () => {
|
||||
it('allows user-granted plugin source roots outside app data', async () => {
|
||||
const externalRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'metoyou-plugin-source-'));
|
||||
const manifestPath = path.join(externalRoot, 'plugin-source.json');
|
||||
|
||||
fs.writeFileSync(manifestPath, '{}');
|
||||
|
||||
grantPluginReadRoot(externalRoot);
|
||||
|
||||
@@ -346,6 +346,9 @@ export interface ElectronAPI {
|
||||
|
||||
command: <T = unknown>(command: Command) => Promise<T>;
|
||||
query: <T = unknown>(query: Query) => Promise<T>;
|
||||
|
||||
storeProvisionSecret: (homeUserId: string, secret: string) => Promise<boolean>;
|
||||
getProvisionSecret: (homeUserId: string) => Promise<string | null>;
|
||||
}
|
||||
|
||||
const electronAPI: ElectronAPI = {
|
||||
@@ -502,7 +505,10 @@ const electronAPI: ElectronAPI = {
|
||||
},
|
||||
|
||||
command: (command) => ipcRenderer.invoke('cqrs:command', command),
|
||||
query: (query) => ipcRenderer.invoke('cqrs:query', query)
|
||||
query: (query) => ipcRenderer.invoke('cqrs:query', query),
|
||||
|
||||
storeProvisionSecret: (homeUserId, secret) => ipcRenderer.invoke('store-provision-secret', homeUserId, secret),
|
||||
getProvisionSecret: (homeUserId) => ipcRenderer.invoke('get-provision-secret', homeUserId)
|
||||
};
|
||||
|
||||
contextBridge.exposeInMainWorld('electronAPI', electronAPI);
|
||||
|
||||
Reference in New Issue
Block a user