Migrate credential encryption to the async safeStorage API
CI / verify (push) Canceled after 0s

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:
SucukdeluxeandClaude Opus 5.5 committed 2026-10-22 07:57:54 +02:00
1 parent 94e7b91797
commit 0b30a9180a
7 files changed
+125 -65

No files matched your search

+17 -6
View File
@@ -27,15 +27,18 @@ class McpStore {
|| 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'
|| (grant.allowTransfer !== undefined && typeof grant.allowTransfer !== 'boolean'))) throw new Error('format');
const decode = identity => {
const decode = async identity => {
if (!identity) return null;
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');
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');
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) {
this.value.enabled = false;
if (this.value.identity) {
@@ -55,13 +58,21 @@ class McpStore {
finally { await handle.close(); }
}
async clearDisabled() { await fs.unlink(this.disabledMarker).catch(error => { if (error.code !== 'ENOENT') throw error; }); }
async save(next) {
const encode = identity => identity ? { ...identity, agentToken: this.encrypt(identity.agentToken), clientToken: this.encrypt(identity.clientToken) } : null;
const disk = { ...next, identity: encode(next.identity), revocations: next.revocations.map(encode) };
async _encode(next) {
const encode = async identity => identity ? { ...identity, agentToken: await this.encrypt(identity.agentToken), clientToken: await this.encrypt(identity.clientToken) } : null;
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)) {
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 disk = await encoded;
await fs.mkdir(path.dirname(this.file), { recursive: true });
const temporary = this.file + '.' + randomUUID() + '.tmp';
try { await fs.writeFile(temporary, JSON.stringify(disk), { mode: 0o600, flag: 'wx' }); await fs.rename(temporary, this.file); }