Electron 45 deprecates the synchronous safeStorage methods and Electron 46 removes them. Credential encryption now uses encryptStringAsync, decryptStringAsync and isAsyncEncryptionAvailable. - secret-store: async encryptField/decryptField/encryptCredentials/ decryptCredentials, decryptFieldWithStatus exposes shouldReEncrypt. Unavailable or failing encryption still rejects with the existing SECRET_STORE_* codes; legacy plaintext stays readable. - config-store: the first load runs asynchronously through init(); writes encrypt before the atomic write. A synchronous load() of an encrypted config before init() fails with SECRET_STORE_NOT_READY and schedules a refresh. Values flagged with shouldReEncrypt are re-encrypted once after loading. - main: await configStore.init() after app ready, before the first load. - MCP access store and online backup keyring await the async helpers; MCP saves keep their call order. Existing enc:v1 values written with encryptString stay readable: on Windows both APIs use the same v10 format and Local State key, verified in both directions with real Electron 41 and 45. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
94e7b91797
commit
0b30a9180a
7 files changed
+125
-65
No files matched your search
+36
-16
@@ -196,6 +196,7 @@ class ConfigStore {
|
||||
this._cacheKey = '';
|
||||
this._lastConfigCheck = 0;
|
||||
this._refreshTask = null;
|
||||
this._reEncryptScheduled = false;
|
||||
this._perfLog = null;
|
||||
this._wqDepth = 0;
|
||||
|
||||
@@ -458,11 +459,24 @@ class ConfigStore {
|
||||
const rotationCursors = (data.rotationCursors && typeof data.rotationCursors === 'object' && !Array.isArray(data.rotationCursors))
|
||||
? data.rotationCursors
|
||||
: {};
|
||||
const result = { hosters, hosterSettings, globalSettings, history: this._historyMigrated ? [] : (data.history || []), rotationCursors };
|
||||
// Decrypt credentials stored with safeStorage so the rest of the app
|
||||
// keeps working with plaintext in memory.
|
||||
secretStore.decryptCredentials(result);
|
||||
return result;
|
||||
return { hosters, hosterSettings, globalSettings, history: this._historyMigrated ? [] : (data.history || []), rotationCursors };
|
||||
}
|
||||
|
||||
async _normalizeAndDecrypt(data) {
|
||||
const config = this._normalizeConfig(data);
|
||||
const { shouldReEncrypt } = await secretStore.decryptCredentials(config);
|
||||
return { config, shouldReEncrypt };
|
||||
}
|
||||
|
||||
init() {
|
||||
if (this._cache) return Promise.resolve();
|
||||
return this.refresh();
|
||||
}
|
||||
|
||||
_scheduleReEncrypt() {
|
||||
if (this._reEncryptScheduled || this._writesQuiesced) return;
|
||||
this._reEncryptScheduled = true;
|
||||
void this._enqueueWrite(async () => this._commit(this.load())).catch(() => {});
|
||||
}
|
||||
|
||||
_loadImpl() {
|
||||
@@ -475,11 +489,14 @@ class ConfigStore {
|
||||
try { data = this._readAndParse(file); } catch {}
|
||||
if (data) break;
|
||||
}
|
||||
try { this._cache = this._normalizeConfig(data || {}); }
|
||||
catch (error) {
|
||||
if (error instanceof secretStore.SecretStoreError) throw error;
|
||||
this._cache = this._normalizeConfig({});
|
||||
let normalized;
|
||||
try { normalized = this._normalizeConfig(data || {}); }
|
||||
catch { normalized = this._normalizeConfig({}); }
|
||||
if (secretStore.hasEncryptedCredentials(normalized)) {
|
||||
this._scheduleConfigRefresh();
|
||||
throw new secretStore.SecretStoreError('SECRET_STORE_NOT_READY', 'Gespeicherte Zugangsdaten wurden noch nicht geladen');
|
||||
}
|
||||
this._cache = normalized;
|
||||
this._lastConfigCheck = Date.now();
|
||||
return this._clone(this._cache);
|
||||
}
|
||||
@@ -508,8 +525,10 @@ class ConfigStore {
|
||||
try {
|
||||
const data = JSON.parse(await fs.promises.readFile(file, 'utf8'));
|
||||
if (!data || typeof data !== 'object' || Array.isArray(data)) continue;
|
||||
this._cache = this._normalizeConfig(data);
|
||||
const { config, shouldReEncrypt } = await this._normalizeAndDecrypt(data);
|
||||
this._cache = config;
|
||||
this._cacheKey = file === this.filePath ? key : '';
|
||||
if (shouldReEncrypt) this._scheduleReEncrypt();
|
||||
return;
|
||||
} catch (error) {
|
||||
if (error instanceof secretStore.SecretStoreError) throw error;
|
||||
@@ -523,20 +542,20 @@ class ConfigStore {
|
||||
// (history, globalSettings, …) is referenced read-only into the stringified
|
||||
// object. Deep-cloning the whole config here (incl. an ever-growing history)
|
||||
// on every write was a primary long-running main-thread stall.
|
||||
_serializeForDisk(config) {
|
||||
async _serializeForDisk(config) {
|
||||
const hosters = this._clone(config.hosters || {});
|
||||
const globalSettings = this._clone(config.globalSettings || {});
|
||||
delete globalSettings.remote;
|
||||
delete globalSettings.diagnostics;
|
||||
delete globalSettings.allowPlaintextCredentialStorage;
|
||||
secretStore.encryptCredentials({ hosters, globalSettings });
|
||||
await secretStore.encryptCredentials({ hosters, globalSettings });
|
||||
return JSON.stringify({ ...config, globalSettings, hosters }, null, 2);
|
||||
}
|
||||
|
||||
_commit(config) {
|
||||
if (!this._perfLog) return this._atomicWrite(this._serializeForDisk(config));
|
||||
async _commit(config) {
|
||||
if (!this._perfLog) return this._atomicWrite(await this._serializeForDisk(config));
|
||||
const t0 = performance.now();
|
||||
const data = this._serializeForDisk(config);
|
||||
const data = await this._serializeForDisk(config);
|
||||
const dt = performance.now() - t0;
|
||||
if (dt >= 20) {
|
||||
const q = this._pqLen(config.globalSettings);
|
||||
@@ -819,6 +838,7 @@ class ConfigStore {
|
||||
}
|
||||
|
||||
async _atomicWrite(data) {
|
||||
const { config: nextCache } = await this._normalizeAndDecrypt(JSON.parse(data));
|
||||
const tmpPath = this.filePath + '.tmp';
|
||||
const backupPath = this.filePath + '.bak';
|
||||
const fileHandle = await fs.promises.open(tmpPath, 'w');
|
||||
@@ -836,7 +856,7 @@ class ConfigStore {
|
||||
if (current && current.trim().length > 2) await fs.promises.writeFile(backupPath, current, 'utf-8');
|
||||
} catch {}
|
||||
await fs.promises.rename(tmpPath, this.filePath);
|
||||
this._cache = this._normalizeConfig(JSON.parse(data));
|
||||
this._cache = nextCache;
|
||||
this._cacheKey = '';
|
||||
this._lastConfigCheck = Date.now();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user