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

+10 -10
View File
@@ -181,7 +181,7 @@ function createOnlineBackupKeyring({
return canonicalJson({ generation: document.generation, keys: document.keys });
}
function validateEntry(entry) {
async function validateEntry(entry) {
const hasLegacyShape = hasExactKeys(entry, STORED_LEGACY_ENTRY_KEYS);
const hasIpShape = hasExactKeys(entry, STORED_IP_ENTRY_KEYS);
const hasExpiringShape = hasExactKeys(entry, STORED_EXPIRING_ENTRY_KEYS) || hasIpShape;
@@ -214,7 +214,7 @@ function createOnlineBackupKeyring({
}
let key;
try {
key = decryptField(entry.encryptedKey);
key = await decryptField(entry.encryptedKey);
} catch (error) {
return { issue: decryptionIssue(error), id: entry.id };
}
@@ -238,7 +238,7 @@ function createOnlineBackupKeyring({
};
}
function inspectSource(source) {
async function inspectSource(source) {
const idCounts = new Map();
for (const entry of source.document.keys) {
if (isCanonicalId(entry?.id)) idCounts.set(entry.id, (idCounts.get(entry.id) || 0) + 1);
@@ -248,7 +248,7 @@ function createOnlineBackupKeyring({
const problems = [];
for (const entry of source.document.keys) {
if (duplicateIds.has(entry?.id)) continue;
const result = validateEntry(entry);
const result = await validateEntry(entry);
if (result.entry) entries.push(result.entry);
else problems.push({ code: result.issue, id: result.id });
}
@@ -307,12 +307,12 @@ function createOnlineBackupKeyring({
modified = (await fsImpl.stat(candidatePath)).mtimeMs;
} catch {}
}
states.push(inspectSource({ ...candidate, modified, recovered: candidatePath !== filePath }));
states.push(await inspectSource({ ...candidate, modified, recovered: candidatePath !== filePath }));
}
if (states.length === 0) {
if (observedCandidate) throw issueError(KEYRING_ERROR_CODES.structure);
const document = { version: 1, generation: 0, keys: [] };
return inspectSource({
return await inspectSource({
status: 'valid',
path: filePath,
contents: JSON.stringify({ version: 1, keys: [] }),
@@ -408,7 +408,7 @@ function createOnlineBackupKeyring({
async function validateStaging(stagingPath, generation, payload) {
const candidate = await readCandidate(stagingPath);
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);
if (blockingIssue) throw issueError(blockingIssue);
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;
try {
parsed = parseKey(key);
@@ -483,7 +483,7 @@ function createOnlineBackupKeyring({
}
let encryptedKey;
try {
encryptedKey = encryptField(key);
encryptedKey = await encryptField(key);
} catch (error) {
throw encryptionError(error);
}
@@ -505,7 +505,7 @@ function createOnlineBackupKeyring({
function commit(entry) {
return serialize(async () => {
const validated = validateEntry(entry);
const validated = await validateEntry(entry);
if (!validated.entry) throw issueError(validated.issue);
const state = await readState();
const blockingIssue = firstBlockingIssue(state);