From ee8302bcae08275851b1c26fbf879f77b0f4615a Mon Sep 17 00:00:00 2001 From: tmashuang Date: Fri, 21 Aug 2020 04:47:50 -0700 Subject: [PATCH 1/5] Use verifyPassword instead of submitPassword when exporting priv key Fixes #9287 which was when submitPassword is called will fully clear the keyring state https://github.com/MetaMask/KeyringController/blob/master/index.js#L155 https://github.com/MetaMask/KeyringController/blob/ad823d0ac15560d2bd22f737516736361f3ea107/index.js#L562 https://github.com/MetaMask/KeyringController/blob/ad823d0ac15560d2bd22f737516736361f3ea107/index.js#L726 Also, pass hideWarning action prop so it will clear the appState.warning if a correct password is never provided on componentWillUnmount --- ui/app/store/actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index 543860f5a840..9f58f9958079 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -1709,7 +1709,7 @@ export function exportAccount (password, address) { log.debug(`background.submitPassword`) return new Promise((resolve, reject) => { - background.submitPassword(password, function (err) { + background.verifyPassword(password, function (err) { if (err) { log.error('Error in submitting password.') dispatch(hideLoadingIndication()) From 9bce86825eec9efc7857c99797fca2f15e547740 Mon Sep 17 00:00:00 2001 From: tmashuang Date: Fri, 21 Aug 2020 04:54:45 -0700 Subject: [PATCH 2/5] Hide Warning on componentWillUnmount --- .../export-private-key-modal.component.js | 2 ++ .../export-private-key-modal.container.js | 1 + 2 files changed, 3 insertions(+) diff --git a/ui/app/components/app/modals/export-private-key-modal/export-private-key-modal.component.js b/ui/app/components/app/modals/export-private-key-modal/export-private-key-modal.component.js index 965d5a703a9d..032860e57d89 100644 --- a/ui/app/components/app/modals/export-private-key-modal/export-private-key-modal.component.js +++ b/ui/app/components/app/modals/export-private-key-modal/export-private-key-modal.component.js @@ -25,6 +25,7 @@ export default class ExportPrivateKeyModal extends Component { warning: PropTypes.node, showAccountDetailModal: PropTypes.func.isRequired, hideModal: PropTypes.func.isRequired, + hideWarning: PropTypes.func.isRequired, clearAccountDetails: PropTypes.func.isRequired, previousModalState: PropTypes.string, } @@ -37,6 +38,7 @@ export default class ExportPrivateKeyModal extends Component { componentWillUnmount () { this.props.clearAccountDetails() + this.props.hideWarning() } exportAccountAndGetPrivateKey = (password, address) => { diff --git a/ui/app/components/app/modals/export-private-key-modal/export-private-key-modal.container.js b/ui/app/components/app/modals/export-private-key-modal/export-private-key-modal.container.js index e1676f8be925..c7f858988cf2 100644 --- a/ui/app/components/app/modals/export-private-key-modal/export-private-key-modal.container.js +++ b/ui/app/components/app/modals/export-private-key-modal/export-private-key-modal.container.js @@ -32,6 +32,7 @@ function mapDispatchToProps (dispatch) { }, showAccountDetailModal: () => dispatch(showModal({ name: 'ACCOUNT_DETAILS' })), hideModal: () => dispatch(hideModal()), + hideWarning: () => dispatch(hideWarning()), clearAccountDetails: () => dispatch(clearAccountDetails()), } } From 5a0a9c3fae5c82495b23b694182b6d698976323f Mon Sep 17 00:00:00 2001 From: tmashuang Date: Fri, 21 Aug 2020 05:17:45 -0700 Subject: [PATCH 3/5] Update exportAccount tests to verifyPassword --- test/unit/ui/app/actions.spec.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js index 8f2dc0bbfb4d..30f3680f339e 100644 --- a/test/unit/ui/app/actions.spec.js +++ b/test/unit/ui/app/actions.spec.js @@ -1144,10 +1144,10 @@ describe('Actions', function () { }) describe('#exportAccount', function () { - let submitPasswordSpy, exportAccountSpy + let verifyPasswordSpy, exportAccountSpy afterEach(function () { - submitPasswordSpy.restore() + verifyPasswordSpy.restore() exportAccountSpy.restore() }) @@ -1159,11 +1159,11 @@ describe('Actions', function () { { type: 'SHOW_PRIVATE_KEY', value: '7ec73b91bb20f209a7ff2d32f542c3420b4fccf14abcc7840d2eff0ebcb18505' }, ] - submitPasswordSpy = sinon.spy(background, 'submitPassword') + verifyPasswordSpy = sinon.spy(background, 'verifyPassword') exportAccountSpy = sinon.spy(background, 'exportAccount') await store.dispatch(actions.exportAccount(password, '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc')) - assert(submitPasswordSpy.calledOnce) + assert(verifyPasswordSpy.calledOnce) assert(exportAccountSpy.calledOnce) assert.deepEqual(store.getActions(), expectedActions) }) @@ -1176,8 +1176,8 @@ describe('Actions', function () { { type: 'DISPLAY_WARNING', value: 'Incorrect Password.' }, ] - submitPasswordSpy = sinon.stub(background, 'submitPassword') - submitPasswordSpy.callsFake((_, callback) => { + verifyPasswordSpy = sinon.stub(background, 'verifyPassword') + verifyPasswordSpy.callsFake((_, callback) => { callback(new Error('error')) }) From dd6b916f2c1f950e35e49b33fb51ff8acba4cd00 Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Wed, 26 Aug 2020 15:56:02 -0700 Subject: [PATCH 4/5] Update ui/app/store/actions.js Co-authored-by: Mark Stacey --- ui/app/store/actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index 9f58f9958079..89e608aca43d 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -1707,7 +1707,7 @@ export function exportAccount (password, address) { return function (dispatch) { dispatch(showLoadingIndication()) - log.debug(`background.submitPassword`) + log.debug(`background.verifyPassword`) return new Promise((resolve, reject) => { background.verifyPassword(password, function (err) { if (err) { From d622acd9e3a4474aac421b007fbc810a72974927 Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Wed, 26 Aug 2020 15:56:10 -0700 Subject: [PATCH 5/5] Update ui/app/store/actions.js Co-authored-by: Mark Stacey --- ui/app/store/actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index 89e608aca43d..9e084b69e0e5 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -1711,7 +1711,7 @@ export function exportAccount (password, address) { return new Promise((resolve, reject) => { background.verifyPassword(password, function (err) { if (err) { - log.error('Error in submitting password.') + log.error('Error in verifying password.') dispatch(hideLoadingIndication()) dispatch(displayWarning('Incorrect Password.')) reject(err)