This commit is contained in:
ZacharyZhang-NY committed 2026-04-05 20:14:48 -04:00
1 parent 09971cabc2
commit 9145572422
163 files changed
+3348 -2874

No files matched your search

+10 -5
View File
@@ -1,5 +1,5 @@
import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { closeSync, mkdirSync, openSync, readFileSync, writeSync } from "node:fs";
import { join } from "node:path";
import { safeStorage } from "electron";
@@ -68,13 +68,18 @@ export class SecretVault {
private ensureKey(): Buffer {
mkdirSync(this.profileDir, { recursive: true });
if (!existsSync(this.keyPath)) {
try {
const fd = openSync(this.keyPath, "wx", 0o600);
const nextKey = randomBytes(32);
writeFileSync(this.keyPath, nextKey);
chmodSync(this.keyPath, 0o600);
writeSync(fd, nextKey);
closeSync(fd);
return nextKey;
} catch (err: unknown) {
if ((err as NodeJS.ErrnoException).code === "EEXIST") {
return readFileSync(this.keyPath);
}
throw err;
}
return readFileSync(this.keyPath);
}
private canUseSafeStorage() {