Merge pull request #879 from MetaMask/i843-MoveSaltIntoEncryptor

Fix new encryptor implementation
feature/default_network_editable
Kevin Serrano 8 years ago committed by GitHub
commit ec8b0148f0
  1. 7
      app/scripts/keyring-controller.js
  2. 1
      app/scripts/lib/encryptor.js
  3. 11
      test/integration/lib/keyring-controller-test.js
  4. 1
      test/unit/keyring-controller-test.js
  5. 7
      ui/app/app.js

@ -118,6 +118,7 @@ module.exports = class KeyringController extends EventEmitter {
return this.idStoreMigrator.migratedVaultForPassword(password) return this.idStoreMigrator.migratedVaultForPassword(password)
.then((serialized) => { .then((serialized) => {
if (serialized && shouldMigrate) { if (serialized && shouldMigrate) {
this.password = password
const keyring = this.restoreKeyring(serialized) const keyring = this.restoreKeyring(serialized)
this.keyrings.push(keyring) this.keyrings.push(keyring)
this.configManager.setSelectedAccount(keyring.getAccounts()[0]) this.configManager.setSelectedAccount(keyring.getAccounts()[0])
@ -185,7 +186,6 @@ module.exports = class KeyringController extends EventEmitter {
cb(null, this.getState()) cb(null, this.getState())
}) })
.catch((err) => { .catch((err) => {
console.error(err)
cb(err) cb(err)
}) })
} }
@ -274,8 +274,9 @@ module.exports = class KeyringController extends EventEmitter {
unlockKeyrings (password) { unlockKeyrings (password) {
const encryptedVault = this.configManager.getVault() const encryptedVault = this.configManager.getVault()
return this.encryptor.decrypt(this.password, encryptedVault) return this.encryptor.decrypt(password, encryptedVault)
.then((vault) => { .then((vault) => {
this.password = password
vault.forEach(this.restoreKeyring.bind(this)) vault.forEach(this.restoreKeyring.bind(this))
return this.keyrings return this.keyrings
}) })
@ -557,7 +558,7 @@ module.exports = class KeyringController extends EventEmitter {
} }
setLocked (cb) { setLocked (cb) {
this.key = null this.password = null
this.keyrings = [] this.keyrings = []
this.emit('update') this.emit('update')
cb() cb()

@ -42,7 +42,6 @@ function encryptWithKey (key, dataObj) {
var data = JSON.stringify(dataObj) var data = JSON.stringify(dataObj)
var dataBuffer = convertStringToArrayBufferView(data) var dataBuffer = convertStringToArrayBufferView(data)
var vector = global.crypto.getRandomValues(new Uint8Array(16)) var vector = global.crypto.getRandomValues(new Uint8Array(16))
return global.crypto.subtle.encrypt({ return global.crypto.subtle.encrypt({
name: 'AES-GCM', name: 'AES-GCM',
iv: vector, iv: vector,

@ -44,3 +44,14 @@ QUnit.test('keyringController:submitPassword', function (assert) {
done() 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()
})
})

@ -87,6 +87,7 @@ describe('KeyringController', function() {
keyringController.migrateOldVaultIfAny(password) keyringController.migrateOldVaultIfAny(password)
.then(() => { .then(() => {
assert(keyringController.configManager.getVault(), 'now has a vault') assert(keyringController.configManager.getVault(), 'now has a vault')
assert(keyringController.password, 'has a password set')
done() done()
}) })
.catch((reason) => { .catch((reason) => {

@ -258,7 +258,7 @@ App.prototype.renderNetworkDropdown = function () {
activeNetworkRender: props.provider.rpcTarget, activeNetworkRender: props.provider.rpcTarget,
}), }),
this.renderCustomOption(props.provider.rpcTarget), this.renderCustomOption(props.provider),
h(DropMenuItem, { h(DropMenuItem, {
label: 'Custom RPC', 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) { switch (rpcTarget) {
case 'http://localhost:8545': case 'http://localhost:8545':

Loading…
Cancel
Save