From be5829baaa5daecdd459372a1f43a93c600c0c9e Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Thu, 11 Jul 2024 09:40:56 -0700 Subject: [PATCH] Deprecate fallback "key" property in config --- _locales/en/messages.json | 4 ++-- app/main.ts | 49 +++++---------------------------------- 2 files changed, 8 insertions(+), 45 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 49fb11a29c..3ef1ecaecc 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -125,11 +125,11 @@ }, "icu:databaseError__recover__detail": { "messageformat": "A database error occurred. You can copy the error and contact Signal support to help fix the issue. If you need to use Signal right away, you can attempt to recover your data.\n\nContact support by visiting: {link}", - "description": "Description shown in a popup if the database key cannot be read, but can be recovered" + "description": "(Deleted 2024/07/11) Description shown in a popup if the database key cannot be read, but can be recovered" }, "icu:databaseError__recover__button": { "messageformat": "Recover data", - "description": "Text of a button shown in a popup if the database cannot start up properly; allows user to attempt data recovery of their database" + "description": "(Deleted 2024/07/11) Text of a button shown in a popup if the database cannot start up properly; allows user to attempt data recovery of their database" }, "icu:mainMenuFile": { "messageformat": "&File", diff --git a/app/main.ts b/app/main.ts index 87fdf1df0f..37a1bad0c7 100644 --- a/app/main.ts +++ b/app/main.ts @@ -1610,6 +1610,11 @@ function getSQLKey(): string { getLogger().info('getSQLKey: decrypting key'); const encrypted = Buffer.from(modernKeyValue, 'hex'); key = safeStorage.decryptString(encrypted); + + if (legacyKeyValue != null) { + getLogger().info('getSQLKey: removing legacy key'); + userConfig.set('key', undefined); + } } else if (typeof legacyKeyValue === 'string') { key = legacyKeyValue; update = isEncryptionAvailable; @@ -1632,7 +1637,6 @@ function getSQLKey(): string { getLogger().info('getSQLKey: updating encrypted key in the config'); const encrypted = safeStorage.encryptString(key).toString('hex'); userConfig.set('encryptedKey', encrypted); - userConfig.set('key', key); } else { getLogger().info('getSQLKey: updating plaintext key in the config'); userConfig.set('key', key); @@ -1645,47 +1649,6 @@ async function initializeSQL( userDataPath: string ): Promise<{ ok: true; error: undefined } | { ok: false; error: Error }> { sqlInitTimeStart = Date.now(); - let key: string; - try { - key = getSQLKey(); - } catch (error: unknown) { - const SIGNAL_SUPPORT_LINK = 'https://support.signal.org/error'; - - const { i18n } = getResolvedMessagesLocale(); - - const buttonIndex = dialog.showMessageBoxSync({ - buttons: [ - i18n('icu:databaseError__recover__button'), - i18n('icu:copyErrorAndQuit'), - ], - defaultId: 0, - cancelId: 1, - message: i18n('icu:databaseError'), - detail: i18n('icu:databaseError__recover__detail', { - link: SIGNAL_SUPPORT_LINK, - }), - noLink: true, - type: 'error', - }); - - const copyErrorAndQuitButtonIndex = 1; - if (buttonIndex === copyErrorAndQuitButtonIndex) { - clipboard.writeText( - `Database startup error:\n\n${redactAll(Errors.toLogFormat(error))}` - ); - - getLogger().error('onDatabaseError: Quitting application'); - app.exit(1); - - // Don't let go through, while `app.exit()` is finalizing asynchronously - await new Promise(noop); - } - - getLogger().error('onDatabaseError: Removing malformed key'); - userConfig.set('encryptedKey', undefined); - key = getSQLKey(); - } - try { // This should be the first awaited call in this function, otherwise // `sql.sqlCall` will throw an uninitialized error instead of waiting for @@ -1693,7 +1656,7 @@ async function initializeSQL( await sql.initialize({ appVersion: app.getVersion(), configDir: userDataPath, - key, + key: getSQLKey(), logger: getLogger(), }); } catch (error: unknown) {