From 114dc47535977fd52749883344de57d086eee00b Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Thu, 30 Nov 2017 17:07:23 +0000 Subject: [PATCH] Make password management errors immediately fatal --- .gitignore | 1 + .../composer-templates/lib/template-store.es6 | 1 + app/src/flux/stores/identity-store.es6 | 1 + app/src/key-manager.es6 | 31 ++++++++++++------- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 996ac1abe..f89b918cc 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,4 @@ client_secret.json **.so* **.bin **.tar.gz +/app/mailsync.dSYM diff --git a/app/internal_packages/composer-templates/lib/template-store.es6 b/app/internal_packages/composer-templates/lib/template-store.es6 index e79fcaa52..f719663eb 100644 --- a/app/internal_packages/composer-templates/lib/template-store.es6 +++ b/app/internal_packages/composer-templates/lib/template-store.es6 @@ -154,6 +154,7 @@ class TemplateStore extends MailspringStore { const dialog = require('electron').remote.dialog; dialog.showErrorBox('Template Creation Error', message); } + _displayDialog(title, message, buttons) { const dialog = require('electron').remote.dialog; return ( diff --git a/app/src/flux/stores/identity-store.es6 b/app/src/flux/stores/identity-store.es6 index 86509f65e..5a089a032 100644 --- a/app/src/flux/stores/identity-store.es6 +++ b/app/src/flux/stores/identity-store.es6 @@ -80,6 +80,7 @@ class IdentityStore extends MailspringStore { if (nextToken && nextToken !== this._identity.token) { // Note: We /must/ await this because calling config.set below // will try to retrieve the password via getPassword. + // If this fails, the app may quit here. await KeyManager.replacePassword(KEYCHAIN_NAME, nextToken); } diff --git a/app/src/key-manager.es6 b/app/src/key-manager.es6 index 201994e38..7bc938279 100644 --- a/app/src/key-manager.es6 +++ b/app/src/key-manager.es6 @@ -23,7 +23,7 @@ class KeyManager { delete keys[`${account.emailAddress}-refresh-token`]; await this._writeKeyHash(keys); } catch (err) { - this._handleError(err); + this._reportFatalError(err); } } @@ -35,7 +35,7 @@ class KeyManager { keys[`${account.emailAddress}-refresh-token`] = account.settings.refresh_token; await this._writeKeyHash(keys); } catch (err) { - this._handleError(err); + this._reportFatalError(err); } const next = account.clone(); delete next.settings.imap_password; @@ -59,7 +59,7 @@ class KeyManager { keys[keyName] = newVal; await this._writeKeyHash(keys); } catch (err) { - this._handleError(err); + this._reportFatalError(err); } } @@ -69,7 +69,7 @@ class KeyManager { delete keys[keyName]; await this._writeKeyHash(keys); } catch (err) { - this._handleError(err); + this._reportFatalError(err); } } @@ -78,7 +78,7 @@ class KeyManager { const keys = await this._getKeyHash(); return keys[keyName]; } catch (err) { - this._handleError(err); + this._reportFatalError(err); } } @@ -95,12 +95,21 @@ class KeyManager { await keytar.setPassword(this.SERVICE_NAME, this.KEY_NAME, JSON.stringify(keys)); } - _handleError(err) { - remote.dialog.showErrorBox( - 'Password Management Error', - "We couldn't store your password securely! For more information, visit http://support.getmailspring.com/hc/en-us/articles/115001875571" - ); - AppEnv.reportError(err); + _reportFatalError(err) { + let more = ''; + if (process.platform === 'linux') { + more = 'Make sure you have `libsecret` installed and a keyring is present. '; + } + remote.dialog.showMessageBox({ + type: 'error', + buttons: ['Quit'], + message: `Mailspring could not store your password securely. ${more} For more information, visit http://support.getmailspring.com/hc/en-us/articles/115001875571`, + }); + + // tell the app to exit and rethrow the error to ensure code relying + // on the passwords being saved never runs (saving identity for example) + remote.app.quit(); + throw err; } }