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
@@ -178,7 +178,7 @@ English is the default language for new profiles. Open **Settings > General** to
|
|||||||
|
|
||||||
### Local data and credentials
|
### Local data and credentials
|
||||||
|
|
||||||
Settings, pending queue state, and upload history are stored in Electron's user-data directory. Passwords and API keys must be encrypted with Electron `safeStorage` before they are written. On Windows, `safeStorage` uses DPAPI and ties encrypted values to the current Windows user profile. If operating-system encryption is unavailable or encryption fails, the write is rejected and credentials are never written as plaintext. Legacy plaintext credentials remain readable for migration and are encrypted during the next successful save.
|
Settings, pending queue state, and upload history are stored in Electron's user-data directory. Passwords and API keys must be encrypted with Electron `safeStorage` before they are written. On Windows, `safeStorage` uses DPAPI and ties encrypted values to the current Windows user profile. If operating-system encryption is unavailable or encryption fails, the write is rejected and credentials are never written as plaintext. Legacy plaintext credentials remain readable for migration and are encrypted during the next successful save. The app uses the asynchronous `safeStorage` API (`encryptStringAsync`, `decryptStringAsync`, `isAsyncEncryptionAvailable`). Values encrypted by earlier versions with the synchronous API keep the same `enc:v1:` format and remain readable; when `decryptStringAsync` reports `shouldReEncrypt`, the settings file is re-encrypted once after loading.
|
||||||
|
|
||||||
Credentials are decrypted when required for account validation or upload to the selected host. Do not share application data files, backup files, screenshots containing credentials, or generated backup keys.
|
Credentials are decrypted when required for account validation or upload to the selected host. Do not share application data files, backup files, screenshots containing credentials, or generated backup keys.
|
||||||
|
|
||||||
|
|||||||
+36
-16
@@ -196,6 +196,7 @@ class ConfigStore {
|
|||||||
this._cacheKey = '';
|
this._cacheKey = '';
|
||||||
this._lastConfigCheck = 0;
|
this._lastConfigCheck = 0;
|
||||||
this._refreshTask = null;
|
this._refreshTask = null;
|
||||||
|
this._reEncryptScheduled = false;
|
||||||
this._perfLog = null;
|
this._perfLog = null;
|
||||||
this._wqDepth = 0;
|
this._wqDepth = 0;
|
||||||
|
|
||||||
@@ -458,11 +459,24 @@ class ConfigStore {
|
|||||||
const rotationCursors = (data.rotationCursors && typeof data.rotationCursors === 'object' && !Array.isArray(data.rotationCursors))
|
const rotationCursors = (data.rotationCursors && typeof data.rotationCursors === 'object' && !Array.isArray(data.rotationCursors))
|
||||||
? data.rotationCursors
|
? data.rotationCursors
|
||||||
: {};
|
: {};
|
||||||
const result = { hosters, hosterSettings, globalSettings, history: this._historyMigrated ? [] : (data.history || []), rotationCursors };
|
return { 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);
|
async _normalizeAndDecrypt(data) {
|
||||||
return result;
|
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() {
|
_loadImpl() {
|
||||||
@@ -475,11 +489,14 @@ class ConfigStore {
|
|||||||
try { data = this._readAndParse(file); } catch {}
|
try { data = this._readAndParse(file); } catch {}
|
||||||
if (data) break;
|
if (data) break;
|
||||||
}
|
}
|
||||||
try { this._cache = this._normalizeConfig(data || {}); }
|
let normalized;
|
||||||
catch (error) {
|
try { normalized = this._normalizeConfig(data || {}); }
|
||||||
if (error instanceof secretStore.SecretStoreError) throw error;
|
catch { normalized = this._normalizeConfig({}); }
|
||||||
this._cache = 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();
|
this._lastConfigCheck = Date.now();
|
||||||
return this._clone(this._cache);
|
return this._clone(this._cache);
|
||||||
}
|
}
|
||||||
@@ -508,8 +525,10 @@ class ConfigStore {
|
|||||||
try {
|
try {
|
||||||
const data = JSON.parse(await fs.promises.readFile(file, 'utf8'));
|
const data = JSON.parse(await fs.promises.readFile(file, 'utf8'));
|
||||||
if (!data || typeof data !== 'object' || Array.isArray(data)) continue;
|
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 : '';
|
this._cacheKey = file === this.filePath ? key : '';
|
||||||
|
if (shouldReEncrypt) this._scheduleReEncrypt();
|
||||||
return;
|
return;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof secretStore.SecretStoreError) throw error;
|
if (error instanceof secretStore.SecretStoreError) throw error;
|
||||||
@@ -523,20 +542,20 @@ class ConfigStore {
|
|||||||
// (history, globalSettings, …) is referenced read-only into the stringified
|
// (history, globalSettings, …) is referenced read-only into the stringified
|
||||||
// object. Deep-cloning the whole config here (incl. an ever-growing history)
|
// object. Deep-cloning the whole config here (incl. an ever-growing history)
|
||||||
// on every write was a primary long-running main-thread stall.
|
// on every write was a primary long-running main-thread stall.
|
||||||
_serializeForDisk(config) {
|
async _serializeForDisk(config) {
|
||||||
const hosters = this._clone(config.hosters || {});
|
const hosters = this._clone(config.hosters || {});
|
||||||
const globalSettings = this._clone(config.globalSettings || {});
|
const globalSettings = this._clone(config.globalSettings || {});
|
||||||
delete globalSettings.remote;
|
delete globalSettings.remote;
|
||||||
delete globalSettings.diagnostics;
|
delete globalSettings.diagnostics;
|
||||||
delete globalSettings.allowPlaintextCredentialStorage;
|
delete globalSettings.allowPlaintextCredentialStorage;
|
||||||
secretStore.encryptCredentials({ hosters, globalSettings });
|
await secretStore.encryptCredentials({ hosters, globalSettings });
|
||||||
return JSON.stringify({ ...config, globalSettings, hosters }, null, 2);
|
return JSON.stringify({ ...config, globalSettings, hosters }, null, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
_commit(config) {
|
async _commit(config) {
|
||||||
if (!this._perfLog) return this._atomicWrite(this._serializeForDisk(config));
|
if (!this._perfLog) return this._atomicWrite(await this._serializeForDisk(config));
|
||||||
const t0 = performance.now();
|
const t0 = performance.now();
|
||||||
const data = this._serializeForDisk(config);
|
const data = await this._serializeForDisk(config);
|
||||||
const dt = performance.now() - t0;
|
const dt = performance.now() - t0;
|
||||||
if (dt >= 20) {
|
if (dt >= 20) {
|
||||||
const q = this._pqLen(config.globalSettings);
|
const q = this._pqLen(config.globalSettings);
|
||||||
@@ -819,6 +838,7 @@ class ConfigStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _atomicWrite(data) {
|
async _atomicWrite(data) {
|
||||||
|
const { config: nextCache } = await this._normalizeAndDecrypt(JSON.parse(data));
|
||||||
const tmpPath = this.filePath + '.tmp';
|
const tmpPath = this.filePath + '.tmp';
|
||||||
const backupPath = this.filePath + '.bak';
|
const backupPath = this.filePath + '.bak';
|
||||||
const fileHandle = await fs.promises.open(tmpPath, 'w');
|
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');
|
if (current && current.trim().length > 2) await fs.promises.writeFile(backupPath, current, 'utf-8');
|
||||||
} catch {}
|
} catch {}
|
||||||
await fs.promises.rename(tmpPath, this.filePath);
|
await fs.promises.rename(tmpPath, this.filePath);
|
||||||
this._cache = this._normalizeConfig(JSON.parse(data));
|
this._cache = nextCache;
|
||||||
this._cacheKey = '';
|
this._cacheKey = '';
|
||||||
this._lastConfigCheck = Date.now();
|
this._lastConfigCheck = Date.now();
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-6
@@ -27,15 +27,18 @@ class McpStore {
|
|||||||
|| value.grants.some(grant => !grant || typeof grant.id !== 'string' || typeof grant.path !== 'string' || !path.isAbsolute(grant.path)
|
|| value.grants.some(grant => !grant || typeof grant.id !== 'string' || typeof grant.path !== 'string' || !path.isAbsolute(grant.path)
|
||||||
|| typeof grant.label !== 'string' || typeof grant.readOnly !== 'boolean'
|
|| typeof grant.label !== 'string' || typeof grant.readOnly !== 'boolean'
|
||||||
|| (grant.allowTransfer !== undefined && typeof grant.allowTransfer !== 'boolean'))) throw new Error('format');
|
|| (grant.allowTransfer !== undefined && typeof grant.allowTransfer !== 'boolean'))) throw new Error('format');
|
||||||
const decode = identity => {
|
const decode = async identity => {
|
||||||
if (!identity) return null;
|
if (!identity) return null;
|
||||||
if (identity.relayUrl !== RELAY_URL || !/^[a-f0-9-]{36}$/.test(identity.installationId)) throw new Error('identity');
|
if (identity.relayUrl !== RELAY_URL || !/^[a-f0-9-]{36}$/.test(identity.installationId)) throw new Error('identity');
|
||||||
if (!identity.agentToken?.startsWith('enc:v1:') || !identity.clientToken?.startsWith('enc:v1:')) throw new Error('encryption');
|
if (!identity.agentToken?.startsWith('enc:v1:') || !identity.clientToken?.startsWith('enc:v1:')) throw new Error('encryption');
|
||||||
const decoded = { ...identity, agentToken: this.decrypt(identity.agentToken), clientToken: this.decrypt(identity.clientToken) };
|
const decoded = { ...identity, agentToken: await this.decrypt(identity.agentToken), clientToken: await this.decrypt(identity.clientToken) };
|
||||||
if (![decoded.agentToken, decoded.clientToken].every(token => /^[A-Za-z0-9_-]{43}$/.test(token)) || decoded.agentToken === decoded.clientToken) throw new Error('credentials');
|
if (![decoded.agentToken, decoded.clientToken].every(token => /^[A-Za-z0-9_-]{43}$/.test(token)) || decoded.agentToken === decoded.clientToken) throw new Error('credentials');
|
||||||
return decoded;
|
return decoded;
|
||||||
};
|
};
|
||||||
this.value = { ...value, capabilities: value.capabilities.filter(item => CAPABILITIES.includes(item)), identity: decode(value.identity), revocations: value.revocations.map(decode) };
|
const identity = await decode(value.identity);
|
||||||
|
const revocations = [];
|
||||||
|
for (const revoked of value.revocations) revocations.push(await decode(revoked));
|
||||||
|
this.value = { ...value, capabilities: value.capabilities.filter(item => CAPABILITIES.includes(item)), identity, revocations };
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
this.value.enabled = false;
|
this.value.enabled = false;
|
||||||
if (this.value.identity) {
|
if (this.value.identity) {
|
||||||
@@ -55,13 +58,21 @@ class McpStore {
|
|||||||
finally { await handle.close(); }
|
finally { await handle.close(); }
|
||||||
}
|
}
|
||||||
async clearDisabled() { await fs.unlink(this.disabledMarker).catch(error => { if (error.code !== 'ENOENT') throw error; }); }
|
async clearDisabled() { await fs.unlink(this.disabledMarker).catch(error => { if (error.code !== 'ENOENT') throw error; }); }
|
||||||
async save(next) {
|
async _encode(next) {
|
||||||
const encode = identity => identity ? { ...identity, agentToken: this.encrypt(identity.agentToken), clientToken: this.encrypt(identity.clientToken) } : null;
|
const encode = async identity => identity ? { ...identity, agentToken: await this.encrypt(identity.agentToken), clientToken: await this.encrypt(identity.clientToken) } : null;
|
||||||
const disk = { ...next, identity: encode(next.identity), revocations: next.revocations.map(encode) };
|
const revocations = [];
|
||||||
|
for (const revoked of next.revocations) revocations.push(await encode(revoked));
|
||||||
|
const disk = { ...next, identity: await encode(next.identity), revocations };
|
||||||
for (const identity of [disk.identity, ...disk.revocations].filter(Boolean)) {
|
for (const identity of [disk.identity, ...disk.revocations].filter(Boolean)) {
|
||||||
if (!identity.agentToken.startsWith('enc:v1:') || !identity.clientToken.startsWith('enc:v1:')) throw new McpAccessError('ENCRYPTION_UNAVAILABLE');
|
if (!identity.agentToken.startsWith('enc:v1:') || !identity.clientToken.startsWith('enc:v1:')) throw new McpAccessError('ENCRYPTION_UNAVAILABLE');
|
||||||
}
|
}
|
||||||
|
return disk;
|
||||||
|
}
|
||||||
|
save(next) {
|
||||||
|
const encoded = this._encode(next);
|
||||||
|
encoded.catch(() => {});
|
||||||
const task = this.tail.then(async () => {
|
const task = this.tail.then(async () => {
|
||||||
|
const disk = await encoded;
|
||||||
await fs.mkdir(path.dirname(this.file), { recursive: true });
|
await fs.mkdir(path.dirname(this.file), { recursive: true });
|
||||||
const temporary = this.file + '.' + randomUUID() + '.tmp';
|
const temporary = this.file + '.' + randomUUID() + '.tmp';
|
||||||
try { await fs.writeFile(temporary, JSON.stringify(disk), { mode: 0o600, flag: 'wx' }); await fs.rename(temporary, this.file); }
|
try { await fs.writeFile(temporary, JSON.stringify(disk), { mode: 0o600, flag: 'wx' }); await fs.rename(temporary, this.file); }
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ function createOnlineBackupKeyring({
|
|||||||
return canonicalJson({ generation: document.generation, keys: document.keys });
|
return canonicalJson({ generation: document.generation, keys: document.keys });
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateEntry(entry) {
|
async function validateEntry(entry) {
|
||||||
const hasLegacyShape = hasExactKeys(entry, STORED_LEGACY_ENTRY_KEYS);
|
const hasLegacyShape = hasExactKeys(entry, STORED_LEGACY_ENTRY_KEYS);
|
||||||
const hasIpShape = hasExactKeys(entry, STORED_IP_ENTRY_KEYS);
|
const hasIpShape = hasExactKeys(entry, STORED_IP_ENTRY_KEYS);
|
||||||
const hasExpiringShape = hasExactKeys(entry, STORED_EXPIRING_ENTRY_KEYS) || hasIpShape;
|
const hasExpiringShape = hasExactKeys(entry, STORED_EXPIRING_ENTRY_KEYS) || hasIpShape;
|
||||||
@@ -214,7 +214,7 @@ function createOnlineBackupKeyring({
|
|||||||
}
|
}
|
||||||
let key;
|
let key;
|
||||||
try {
|
try {
|
||||||
key = decryptField(entry.encryptedKey);
|
key = await decryptField(entry.encryptedKey);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { issue: decryptionIssue(error), id: entry.id };
|
return { issue: decryptionIssue(error), id: entry.id };
|
||||||
}
|
}
|
||||||
@@ -238,7 +238,7 @@ function createOnlineBackupKeyring({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function inspectSource(source) {
|
async function inspectSource(source) {
|
||||||
const idCounts = new Map();
|
const idCounts = new Map();
|
||||||
for (const entry of source.document.keys) {
|
for (const entry of source.document.keys) {
|
||||||
if (isCanonicalId(entry?.id)) idCounts.set(entry.id, (idCounts.get(entry.id) || 0) + 1);
|
if (isCanonicalId(entry?.id)) idCounts.set(entry.id, (idCounts.get(entry.id) || 0) + 1);
|
||||||
@@ -248,7 +248,7 @@ function createOnlineBackupKeyring({
|
|||||||
const problems = [];
|
const problems = [];
|
||||||
for (const entry of source.document.keys) {
|
for (const entry of source.document.keys) {
|
||||||
if (duplicateIds.has(entry?.id)) continue;
|
if (duplicateIds.has(entry?.id)) continue;
|
||||||
const result = validateEntry(entry);
|
const result = await validateEntry(entry);
|
||||||
if (result.entry) entries.push(result.entry);
|
if (result.entry) entries.push(result.entry);
|
||||||
else problems.push({ code: result.issue, id: result.id });
|
else problems.push({ code: result.issue, id: result.id });
|
||||||
}
|
}
|
||||||
@@ -307,12 +307,12 @@ function createOnlineBackupKeyring({
|
|||||||
modified = (await fsImpl.stat(candidatePath)).mtimeMs;
|
modified = (await fsImpl.stat(candidatePath)).mtimeMs;
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
states.push(inspectSource({ ...candidate, modified, recovered: candidatePath !== filePath }));
|
states.push(await inspectSource({ ...candidate, modified, recovered: candidatePath !== filePath }));
|
||||||
}
|
}
|
||||||
if (states.length === 0) {
|
if (states.length === 0) {
|
||||||
if (observedCandidate) throw issueError(KEYRING_ERROR_CODES.structure);
|
if (observedCandidate) throw issueError(KEYRING_ERROR_CODES.structure);
|
||||||
const document = { version: 1, generation: 0, keys: [] };
|
const document = { version: 1, generation: 0, keys: [] };
|
||||||
return inspectSource({
|
return await inspectSource({
|
||||||
status: 'valid',
|
status: 'valid',
|
||||||
path: filePath,
|
path: filePath,
|
||||||
contents: JSON.stringify({ version: 1, keys: [] }),
|
contents: JSON.stringify({ version: 1, keys: [] }),
|
||||||
@@ -408,7 +408,7 @@ function createOnlineBackupKeyring({
|
|||||||
async function validateStaging(stagingPath, generation, payload) {
|
async function validateStaging(stagingPath, generation, payload) {
|
||||||
const candidate = await readCandidate(stagingPath);
|
const candidate = await readCandidate(stagingPath);
|
||||||
if (candidate.status !== 'valid') throw issueError(KEYRING_ERROR_CODES.structure);
|
if (candidate.status !== 'valid') throw issueError(KEYRING_ERROR_CODES.structure);
|
||||||
const state = inspectSource({ ...candidate, recovered: false });
|
const state = await inspectSource({ ...candidate, recovered: false });
|
||||||
const blockingIssue = firstBlockingIssue(state);
|
const blockingIssue = firstBlockingIssue(state);
|
||||||
if (blockingIssue) throw issueError(blockingIssue);
|
if (blockingIssue) throw issueError(blockingIssue);
|
||||||
if (state.generation !== generation || state.payload !== payload) throw issueError(KEYRING_ERROR_CODES.structure);
|
if (state.generation !== generation || state.payload !== payload) throw issueError(KEYRING_ERROR_CODES.structure);
|
||||||
@@ -474,7 +474,7 @@ function createOnlineBackupKeyring({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepare(key, createdAt, expiresAt = null) {
|
async function prepare(key, createdAt, expiresAt = null) {
|
||||||
let parsed;
|
let parsed;
|
||||||
try {
|
try {
|
||||||
parsed = parseKey(key);
|
parsed = parseKey(key);
|
||||||
@@ -483,7 +483,7 @@ function createOnlineBackupKeyring({
|
|||||||
}
|
}
|
||||||
let encryptedKey;
|
let encryptedKey;
|
||||||
try {
|
try {
|
||||||
encryptedKey = encryptField(key);
|
encryptedKey = await encryptField(key);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw encryptionError(error);
|
throw encryptionError(error);
|
||||||
}
|
}
|
||||||
@@ -505,7 +505,7 @@ function createOnlineBackupKeyring({
|
|||||||
|
|
||||||
function commit(entry) {
|
function commit(entry) {
|
||||||
return serialize(async () => {
|
return serialize(async () => {
|
||||||
const validated = validateEntry(entry);
|
const validated = await validateEntry(entry);
|
||||||
if (!validated.entry) throw issueError(validated.issue);
|
if (!validated.entry) throw issueError(validated.issue);
|
||||||
const state = await readState();
|
const state = await readState();
|
||||||
const blockingIssue = firstBlockingIssue(state);
|
const blockingIssue = firstBlockingIssue(state);
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ function createOnlineBackupManager({
|
|||||||
const settings = await loadSettings();
|
const settings = await loadSettings();
|
||||||
const recoveryPublicKey = await loadRecoveryPublicKey();
|
const recoveryPublicKey = await loadRecoveryPublicKey();
|
||||||
const created = createBackup(settings, appVersion(), createdAt, retention, recoveryPublicKey);
|
const created = createBackup(settings, appVersion(), createdAt, retention, recoveryPublicKey);
|
||||||
let prepared = keyring.prepare(created.key, createdAt, created.expiresAt ?? null);
|
let prepared = await keyring.prepare(created.key, createdAt, created.expiresAt ?? null);
|
||||||
const metadata = await uploadBackup(created.record);
|
const metadata = await uploadBackup(created.record);
|
||||||
if (metadata?.sourceIp) prepared = Object.freeze({ ...prepared, sourceIp: metadata.sourceIp });
|
if (metadata?.sourceIp) prepared = Object.freeze({ ...prepared, sourceIp: metadata.sourceIp });
|
||||||
try {
|
try {
|
||||||
|
|||||||
+59
-31
@@ -20,12 +20,12 @@ class SecretStoreError extends Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let _safeStorageCache = undefined;
|
let _safeStorageCache = undefined;
|
||||||
function getSafeStorage() {
|
async function getSafeStorage() {
|
||||||
if (_safeStorageCache !== undefined) return _safeStorageCache;
|
if (_safeStorageCache !== undefined) return _safeStorageCache;
|
||||||
try {
|
try {
|
||||||
const { safeStorage } = require('electron');
|
const { safeStorage } = require('electron');
|
||||||
if (safeStorage && typeof safeStorage.isEncryptionAvailable === 'function'
|
if (safeStorage && typeof safeStorage.isAsyncEncryptionAvailable === 'function'
|
||||||
&& safeStorage.isEncryptionAvailable()) {
|
&& await safeStorage.isAsyncEncryptionAvailable()) {
|
||||||
_safeStorageCache = safeStorage;
|
_safeStorageCache = safeStorage;
|
||||||
return _safeStorageCache;
|
return _safeStorageCache;
|
||||||
}
|
}
|
||||||
@@ -33,6 +33,14 @@ function getSafeStorage() {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function unavailableError() {
|
||||||
|
return new SecretStoreError('SECRET_STORE_UNAVAILABLE', 'Sicherer Zugangsdaten-Speicher ist nicht verfügbar');
|
||||||
|
}
|
||||||
|
|
||||||
|
function decryptFailedError(cause) {
|
||||||
|
return new SecretStoreError('SECRET_STORE_DECRYPT_FAILED', 'Gespeicherte Zugangsdaten konnten nicht entschlüsselt werden', cause);
|
||||||
|
}
|
||||||
|
|
||||||
function isEncrypted(value) {
|
function isEncrypted(value) {
|
||||||
if (typeof value !== 'string' || !value.startsWith(SENTINEL)) return false;
|
if (typeof value !== 'string' || !value.startsWith(SENTINEL)) return false;
|
||||||
const encoded = value.slice(SENTINEL.length);
|
const encoded = value.slice(SENTINEL.length);
|
||||||
@@ -41,68 +49,88 @@ function isEncrypted(value) {
|
|||||||
return decoded.length > 0 && decoded.toString('base64') === encoded;
|
return decoded.length > 0 && decoded.toString('base64') === encoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
function encryptField(value) {
|
async function encryptField(value) {
|
||||||
if (!value || typeof value !== 'string') return value;
|
if (!value || typeof value !== 'string') return value;
|
||||||
if (isEncrypted(value)) return value;
|
if (isEncrypted(value)) return value;
|
||||||
const ss = getSafeStorage();
|
const ss = await getSafeStorage();
|
||||||
if (!ss) {
|
if (!ss) throw unavailableError();
|
||||||
throw new SecretStoreError('SECRET_STORE_UNAVAILABLE', 'Sicherer Zugangsdaten-Speicher ist nicht verfügbar');
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const buf = ss.encryptString(value);
|
const buf = await ss.encryptStringAsync(value);
|
||||||
return SENTINEL + buf.toString('base64');
|
return SENTINEL + Buffer.from(buf).toString('base64');
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
throw new SecretStoreError('SECRET_STORE_ENCRYPT_FAILED', 'Zugangsdaten konnten nicht sicher verschlüsselt werden', cause);
|
throw new SecretStoreError('SECRET_STORE_ENCRYPT_FAILED', 'Zugangsdaten konnten nicht sicher verschlüsselt werden', cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function decryptField(value) {
|
async function decryptFieldWithStatus(value) {
|
||||||
if (!value || typeof value !== 'string') return value;
|
if (!value || typeof value !== 'string') return { value, shouldReEncrypt: false };
|
||||||
if (!isEncrypted(value)) {
|
if (!isEncrypted(value)) {
|
||||||
if (value.startsWith(SENTINEL)) {
|
if (value.startsWith(SENTINEL)) throw decryptFailedError();
|
||||||
throw new SecretStoreError('SECRET_STORE_DECRYPT_FAILED', 'Gespeicherte Zugangsdaten konnten nicht entschlüsselt werden');
|
return { value, shouldReEncrypt: false };
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
const ss = getSafeStorage();
|
|
||||||
if (!ss) {
|
|
||||||
throw new SecretStoreError('SECRET_STORE_UNAVAILABLE', 'Sicherer Zugangsdaten-Speicher ist nicht verfügbar');
|
|
||||||
}
|
}
|
||||||
|
const ss = await getSafeStorage();
|
||||||
|
if (!ss) throw unavailableError();
|
||||||
|
let decrypted;
|
||||||
try {
|
try {
|
||||||
const buf = Buffer.from(value.slice(SENTINEL.length), 'base64');
|
decrypted = await ss.decryptStringAsync(Buffer.from(value.slice(SENTINEL.length), 'base64'));
|
||||||
return ss.decryptString(buf);
|
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
throw new SecretStoreError('SECRET_STORE_DECRYPT_FAILED', 'Gespeicherte Zugangsdaten konnten nicht entschlüsselt werden', cause);
|
throw decryptFailedError(cause);
|
||||||
}
|
}
|
||||||
|
if (!decrypted || typeof decrypted.result !== 'string') throw decryptFailedError();
|
||||||
|
return { value: decrypted.result, shouldReEncrypt: decrypted.shouldReEncrypt === true };
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapHosterAccounts(config, fn) {
|
async function decryptField(value) {
|
||||||
if (config?.globalSettings?.cloudLogSync?.apiKey) {
|
return (await decryptFieldWithStatus(value)).value;
|
||||||
config.globalSettings.cloudLogSync.apiKey = fn(config.globalSettings.cloudLogSync.apiKey);
|
}
|
||||||
}
|
|
||||||
if (!config || !config.hosters || typeof config.hosters !== 'object') return config;
|
function credentialSlots(config) {
|
||||||
|
const slots = [];
|
||||||
|
const cloudLogSync = config?.globalSettings?.cloudLogSync;
|
||||||
|
if (cloudLogSync?.apiKey) slots.push([cloudLogSync, 'apiKey']);
|
||||||
|
if (!config || !config.hosters || typeof config.hosters !== 'object') return slots;
|
||||||
for (const accounts of Object.values(config.hosters)) {
|
for (const accounts of Object.values(config.hosters)) {
|
||||||
if (!Array.isArray(accounts)) continue;
|
if (!Array.isArray(accounts)) continue;
|
||||||
for (const acc of accounts) {
|
for (const acc of accounts) {
|
||||||
if (!acc || typeof acc !== 'object') continue;
|
if (!acc || typeof acc !== 'object') continue;
|
||||||
for (const f of CRED_FIELDS) {
|
for (const f of CRED_FIELDS) {
|
||||||
if (acc[f]) acc[f] = fn(acc[f]);
|
if (acc[f]) slots.push([acc, f]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return slots;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function mapHosterAccounts(config, fn) {
|
||||||
|
for (const [owner, field] of credentialSlots(config)) owner[field] = await fn(owner[field]);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
function encryptCredentials(config) {
|
function hasEncryptedCredentials(config) {
|
||||||
|
return credentialSlots(config).some(([owner, field]) => typeof owner[field] === 'string' && owner[field].startsWith(SENTINEL));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function encryptCredentials(config) {
|
||||||
return mapHosterAccounts(config, encryptField);
|
return mapHosterAccounts(config, encryptField);
|
||||||
}
|
}
|
||||||
function decryptCredentials(config) { return mapHosterAccounts(config, decryptField); }
|
|
||||||
|
async function decryptCredentials(config) {
|
||||||
|
let shouldReEncrypt = false;
|
||||||
|
await mapHosterAccounts(config, async value => {
|
||||||
|
const decrypted = await decryptFieldWithStatus(value);
|
||||||
|
if (decrypted.shouldReEncrypt) shouldReEncrypt = true;
|
||||||
|
return decrypted.value;
|
||||||
|
});
|
||||||
|
return { config, shouldReEncrypt };
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
SecretStoreError,
|
SecretStoreError,
|
||||||
encryptField,
|
encryptField,
|
||||||
decryptField,
|
decryptField,
|
||||||
|
decryptFieldWithStatus,
|
||||||
encryptCredentials,
|
encryptCredentials,
|
||||||
decryptCredentials,
|
decryptCredentials,
|
||||||
|
hasEncryptedCredentials,
|
||||||
isEncrypted
|
isEncrypted
|
||||||
};
|
};
|
||||||
@@ -2010,6 +2010,7 @@ async function runAutomaticUpdateCheck(forceRefresh) {
|
|||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
await mcpUpdate.load().catch(() => logError('MCP update state unavailable'));
|
await mcpUpdate.load().catch(() => logError('MCP update state unavailable'));
|
||||||
if (!_hasSingleInstanceLock) return;
|
if (!_hasSingleInstanceLock) return;
|
||||||
|
await configStore.init().catch(error => logError(`config load failed: ${error?.code || error?.message || error}`));
|
||||||
startupDiagnostics.write('application-ready', { hardwareAcceleration: app.isHardwareAccelerationEnabled(), gpuFeatures: app.getGPUFeatureStatus() });
|
startupDiagnostics.write('application-ready', { hardwareAcceleration: app.isHardwareAccelerationEnabled(), gpuFeatures: app.getGPUFeatureStatus() });
|
||||||
void app.getGPUInfo('basic').then(info => {
|
void app.getGPUInfo('basic').then(info => {
|
||||||
const devices = Array.isArray(info.gpuDevice) ? info.gpuDevice.map(device => ({
|
const devices = Array.isArray(info.gpuDevice) ? info.gpuDevice.map(device => ({
|
||||||
|
|||||||
Reference in new issue
Block a user