1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Use verifyPassword instead of submitPassword when exporting priv key (#9288)

* 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
ad823d0ac1/index.js (L562)
ad823d0ac1/index.js (L726)

Also, pass hideWarning action prop so it will clear the appState.warning if a correct password is never provided on componentWillUnmount

* Hide Warning on componentWillUnmount

* Update exportAccount tests to verifyPassword

* Update ui/app/store/actions.js
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
This commit is contained in:
Thomas Huang 2020-08-26 16:19:41 -07:00 committed by GitHub
parent 20b0e66cc9
commit 79d477009e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 9 deletions

View File

@ -1144,10 +1144,10 @@ describe('Actions', function () {
}) })
describe('#exportAccount', function () { describe('#exportAccount', function () {
let submitPasswordSpy, exportAccountSpy let verifyPasswordSpy, exportAccountSpy
afterEach(function () { afterEach(function () {
submitPasswordSpy.restore() verifyPasswordSpy.restore()
exportAccountSpy.restore() exportAccountSpy.restore()
}) })
@ -1159,11 +1159,11 @@ describe('Actions', function () {
{ type: 'SHOW_PRIVATE_KEY', value: '7ec73b91bb20f209a7ff2d32f542c3420b4fccf14abcc7840d2eff0ebcb18505' }, { type: 'SHOW_PRIVATE_KEY', value: '7ec73b91bb20f209a7ff2d32f542c3420b4fccf14abcc7840d2eff0ebcb18505' },
] ]
submitPasswordSpy = sinon.spy(background, 'submitPassword') verifyPasswordSpy = sinon.spy(background, 'verifyPassword')
exportAccountSpy = sinon.spy(background, 'exportAccount') exportAccountSpy = sinon.spy(background, 'exportAccount')
await store.dispatch(actions.exportAccount(password, '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc')) await store.dispatch(actions.exportAccount(password, '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'))
assert(submitPasswordSpy.calledOnce) assert(verifyPasswordSpy.calledOnce)
assert(exportAccountSpy.calledOnce) assert(exportAccountSpy.calledOnce)
assert.deepEqual(store.getActions(), expectedActions) assert.deepEqual(store.getActions(), expectedActions)
}) })
@ -1176,8 +1176,8 @@ describe('Actions', function () {
{ type: 'DISPLAY_WARNING', value: 'Incorrect Password.' }, { type: 'DISPLAY_WARNING', value: 'Incorrect Password.' },
] ]
submitPasswordSpy = sinon.stub(background, 'submitPassword') verifyPasswordSpy = sinon.stub(background, 'verifyPassword')
submitPasswordSpy.callsFake((_, callback) => { verifyPasswordSpy.callsFake((_, callback) => {
callback(new Error('error')) callback(new Error('error'))
}) })

View File

@ -25,6 +25,7 @@ export default class ExportPrivateKeyModal extends Component {
warning: PropTypes.node, warning: PropTypes.node,
showAccountDetailModal: PropTypes.func.isRequired, showAccountDetailModal: PropTypes.func.isRequired,
hideModal: PropTypes.func.isRequired, hideModal: PropTypes.func.isRequired,
hideWarning: PropTypes.func.isRequired,
clearAccountDetails: PropTypes.func.isRequired, clearAccountDetails: PropTypes.func.isRequired,
previousModalState: PropTypes.string, previousModalState: PropTypes.string,
} }
@ -37,6 +38,7 @@ export default class ExportPrivateKeyModal extends Component {
componentWillUnmount () { componentWillUnmount () {
this.props.clearAccountDetails() this.props.clearAccountDetails()
this.props.hideWarning()
} }
exportAccountAndGetPrivateKey = (password, address) => { exportAccountAndGetPrivateKey = (password, address) => {

View File

@ -32,6 +32,7 @@ function mapDispatchToProps (dispatch) {
}, },
showAccountDetailModal: () => dispatch(showModal({ name: 'ACCOUNT_DETAILS' })), showAccountDetailModal: () => dispatch(showModal({ name: 'ACCOUNT_DETAILS' })),
hideModal: () => dispatch(hideModal()), hideModal: () => dispatch(hideModal()),
hideWarning: () => dispatch(hideWarning()),
clearAccountDetails: () => dispatch(clearAccountDetails()), clearAccountDetails: () => dispatch(clearAccountDetails()),
} }
} }

View File

@ -1707,11 +1707,11 @@ export function exportAccount (password, address) {
return function (dispatch) { return function (dispatch) {
dispatch(showLoadingIndication()) dispatch(showLoadingIndication())
log.debug(`background.submitPassword`) log.debug(`background.verifyPassword`)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
background.submitPassword(password, function (err) { background.verifyPassword(password, function (err) {
if (err) { if (err) {
log.error('Error in submitting password.') log.error('Error in verifying password.')
dispatch(hideLoadingIndication()) dispatch(hideLoadingIndication())
dispatch(displayWarning('Incorrect Password.')) dispatch(displayWarning('Incorrect Password.'))
reject(err) reject(err)