From 822face7a3513a709277a197e27fd550b7b21954 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 22 Nov 2016 16:29:46 -0800 Subject: [PATCH 1/3] Fix password reference --- app/scripts/keyring-controller.js | 3 ++- test/unit/keyring-controller-test.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index 4fa2b4ee8..141a1281a 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -274,8 +274,9 @@ module.exports = class KeyringController extends EventEmitter { unlockKeyrings (password) { const encryptedVault = this.configManager.getVault() - return this.encryptor.decrypt(this.password, encryptedVault) + return this.encryptor.decrypt(password, encryptedVault) .then((vault) => { + this.password = password vault.forEach(this.restoreKeyring.bind(this)) return this.keyrings }) diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js index a58043c7a..b20def02e 100644 --- a/test/unit/keyring-controller-test.js +++ b/test/unit/keyring-controller-test.js @@ -87,6 +87,7 @@ describe('KeyringController', function() { keyringController.migrateOldVaultIfAny(password) .then(() => { assert(keyringController.configManager.getVault(), 'now has a vault') + assert(keyringController.password, 'has a password set') done() }) .catch((reason) => { From 1e46d858e995c6c50f155f1bcdaf64b922402599 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 22 Nov 2016 16:34:02 -0800 Subject: [PATCH 2/3] Fix undefined provider menu item --- ui/app/app.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ui/app/app.js b/ui/app/app.js index f9694214a..94e8adc34 100644 --- a/ui/app/app.js +++ b/ui/app/app.js @@ -258,7 +258,7 @@ App.prototype.renderNetworkDropdown = function () { activeNetworkRender: props.provider.rpcTarget, }), - this.renderCustomOption(props.provider.rpcTarget), + this.renderCustomOption(props.provider), h(DropMenuItem, { label: 'Custom RPC', @@ -480,7 +480,10 @@ App.prototype.toggleMetamaskActive = function () { } } -App.prototype.renderCustomOption = function (rpcTarget) { +App.prototype.renderCustomOption = function (provider) { + const { rpcTarget, type } = provider + if (type !== 'rpc') return null + switch (rpcTarget) { case 'http://localhost:8545': From 05c8658ff343af61b1a40a5624ecba77adb2ef00 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 22 Nov 2016 17:40:29 -0800 Subject: [PATCH 3/3] Fix new encryptor migration logic --- app/scripts/keyring-controller.js | 4 ++-- app/scripts/lib/encryptor.js | 1 - test/integration/lib/keyring-controller-test.js | 11 +++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index 141a1281a..68cf62f7a 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -118,6 +118,7 @@ module.exports = class KeyringController extends EventEmitter { return this.idStoreMigrator.migratedVaultForPassword(password) .then((serialized) => { if (serialized && shouldMigrate) { + this.password = password const keyring = this.restoreKeyring(serialized) this.keyrings.push(keyring) this.configManager.setSelectedAccount(keyring.getAccounts()[0]) @@ -185,7 +186,6 @@ module.exports = class KeyringController extends EventEmitter { cb(null, this.getState()) }) .catch((err) => { - console.error(err) cb(err) }) } @@ -558,7 +558,7 @@ module.exports = class KeyringController extends EventEmitter { } setLocked (cb) { - this.key = null + this.password = null this.keyrings = [] this.emit('update') cb() diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js index 8bacab766..4770d2f54 100644 --- a/app/scripts/lib/encryptor.js +++ b/app/scripts/lib/encryptor.js @@ -42,7 +42,6 @@ function encryptWithKey (key, dataObj) { var data = JSON.stringify(dataObj) var dataBuffer = convertStringToArrayBufferView(data) var vector = global.crypto.getRandomValues(new Uint8Array(16)) - return global.crypto.subtle.encrypt({ name: 'AES-GCM', iv: vector, diff --git a/test/integration/lib/keyring-controller-test.js b/test/integration/lib/keyring-controller-test.js index bea485270..678744834 100644 --- a/test/integration/lib/keyring-controller-test.js +++ b/test/integration/lib/keyring-controller-test.js @@ -44,3 +44,14 @@ QUnit.test('keyringController:submitPassword', function (assert) { done() }) }) + +QUnit.test('keyringController:setLocked', function (assert) { + var done = assert.async() + var self = this + + this.keyringController.setLocked(function(err) { + assert.notOk(self.keyringController.password, 'password should be deallocated') + assert.deepEqual(self.keyringController.keyrings, [], 'keyrings should be deallocated') + done() + }) +})