mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
Linted & added salting to vault
This commit is contained in:
parent
e5c95d68f8
commit
383f8ea7dc
@ -129,7 +129,7 @@
|
|||||||
"one-var": [2, { "initialized": "never" }],
|
"one-var": [2, { "initialized": "never" }],
|
||||||
"operator-linebreak": [1, "after", { "overrides": { "?": "before", ":": "before" } }],
|
"operator-linebreak": [1, "after", { "overrides": { "?": "before", ":": "before" } }],
|
||||||
"padded-blocks": [1, "never"],
|
"padded-blocks": [1, "never"],
|
||||||
"quotes": [2, "single", "avoid-escape"],
|
"quotes": [2, "single", {"avoidEscape": true, "allowTemplateLiterals": true}],
|
||||||
"semi": [2, "never"],
|
"semi": [2, "never"],
|
||||||
"semi-spacing": [2, { "before": false, "after": true }],
|
"semi-spacing": [2, { "before": false, "after": true }],
|
||||||
"space-before-blocks": [1, "always"],
|
"space-before-blocks": [1, "always"],
|
||||||
|
@ -12,37 +12,6 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
this.keyChains = []
|
this.keyChains = []
|
||||||
}
|
}
|
||||||
|
|
||||||
keyFromPassword(password, callback) {
|
|
||||||
deriveKeyFromPassword(password, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Takes a pw and callback, returns a password-dervied key
|
|
||||||
getKeyForPassword(password, callback) {
|
|
||||||
let salt = this.configManager.getSalt()
|
|
||||||
|
|
||||||
if (!salt) {
|
|
||||||
salt = generateSalt(32)
|
|
||||||
this.configManager.setSalt(salt)
|
|
||||||
}
|
|
||||||
|
|
||||||
var logN = 14
|
|
||||||
var r = 8
|
|
||||||
var dkLen = 32
|
|
||||||
var interruptStep = 200
|
|
||||||
|
|
||||||
var cb = function(derKey) {
|
|
||||||
try {
|
|
||||||
var ui8arr = (new Uint8Array(derKey))
|
|
||||||
this.pwDerivedKey = ui8arr
|
|
||||||
callback(null, ui8arr)
|
|
||||||
} catch (err) {
|
|
||||||
callback(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scrypt(password, salt, logN, r, dkLen, interruptStep, cb, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
getState() {
|
getState() {
|
||||||
return {
|
return {
|
||||||
isInitialized: !!this.configManager.getVault(),
|
isInitialized: !!this.configManager.getVault(),
|
||||||
@ -66,11 +35,13 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createNewVault(password, entropy, cb) {
|
createNewVault(password, entropy, cb) {
|
||||||
|
const salt = generateNewSalt()
|
||||||
|
this.configManager.setSalt(salt)
|
||||||
this.loadKey(password)
|
this.loadKey(password)
|
||||||
.then((key) => {
|
.then((key) => {
|
||||||
return encryptor.encryptWithKey(key, {})
|
return encryptor.encryptWithKey(key, {})
|
||||||
})
|
})
|
||||||
.then((encryptedString) => {
|
.then((encryptedString) => {
|
||||||
this.configManager.setVault(encryptedString)
|
this.configManager.setVault(encryptedString)
|
||||||
cb(null, this.getState())
|
cb(null, this.getState())
|
||||||
})
|
})
|
||||||
@ -90,7 +61,8 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadKey(password) {
|
loadKey(password) {
|
||||||
return encryptor.keyFromPassword(password)
|
const salt = this.configManager.getSalt()
|
||||||
|
return encryptor.keyFromPassword(password + salt)
|
||||||
.then((key) => {
|
.then((key) => {
|
||||||
this.key = key
|
this.key = key
|
||||||
return key
|
return key
|
||||||
@ -141,5 +113,8 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateSalt (byteCount) {
|
function generateSalt (byteCount) {
|
||||||
return bitcore.crypto.Random.getRandomBuffer(byteCount || 32).toString('base64')
|
var view = new Uint8Array(32)
|
||||||
|
global.crypto.getRandomValues(view)
|
||||||
|
var b64encoded = btoa(String.fromCharCode.apply(null, view))
|
||||||
|
return b64encoded
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ ConfigManager.prototype.setVault = function (encryptedString) {
|
|||||||
|
|
||||||
ConfigManager.prototype.getVault = function () {
|
ConfigManager.prototype.getVault = function () {
|
||||||
var data = this.getData()
|
var data = this.getData()
|
||||||
return ('vault' in data) && data.vault
|
return ('vault' in data) && data.vault
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigManager.prototype.getKeychains = function () {
|
ConfigManager.prototype.getKeychains = function () {
|
||||||
|
@ -18,6 +18,10 @@ module.exports = {
|
|||||||
// Buffer <-> Hex string methods
|
// Buffer <-> Hex string methods
|
||||||
serializeBufferForStorage,
|
serializeBufferForStorage,
|
||||||
serializeBufferFromStorage,
|
serializeBufferFromStorage,
|
||||||
|
|
||||||
|
// Buffer <-> base64 string methods
|
||||||
|
encodeBufferToBase64,
|
||||||
|
decodeBase64ToBuffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a Pojo, returns encrypted text.
|
// Takes a Pojo, returns encrypted text.
|
||||||
@ -117,3 +121,15 @@ function unprefixedHex (num) {
|
|||||||
}
|
}
|
||||||
return hex
|
return hex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function encodeBufferToBase64 (buf) {
|
||||||
|
var b64encoded = btoa(String.fromCharCode.apply(null, buf))
|
||||||
|
return b64encoded
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodeBase64ToBuffer (base64) {
|
||||||
|
var u8_2 = new Uint8Array(atob(b64encoded).split("")
|
||||||
|
.map(function(c) {
|
||||||
|
return c.charCodeAt(0)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
@ -340,7 +340,7 @@ function backToUnlockView () {
|
|||||||
|
|
||||||
function showNewKeychain () {
|
function showNewKeychain () {
|
||||||
return {
|
return {
|
||||||
type: actions.SHOW_NEW_KEYCHAIN
|
type: actions.SHOW_NEW_KEYCHAIN,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ const ReactCSSTransitionGroup = require('react-addons-css-transition-group')
|
|||||||
const DisclaimerScreen = require('./first-time/disclaimer')
|
const DisclaimerScreen = require('./first-time/disclaimer')
|
||||||
const InitializeMenuScreen = require('./first-time/init-menu')
|
const InitializeMenuScreen = require('./first-time/init-menu')
|
||||||
const CreateVaultScreen = require('./first-time/create-vault')
|
const CreateVaultScreen = require('./first-time/create-vault')
|
||||||
const NewKeychainScreen = require('./new-keychain')
|
const NewKeyChainScreen = require('./new-keychain')
|
||||||
// unlock
|
// unlock
|
||||||
const UnlockScreen = require('./unlock')
|
const UnlockScreen = require('./unlock')
|
||||||
// accounts
|
// accounts
|
||||||
|
@ -15,7 +15,7 @@ function NewKeychain () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NewKeychain.prototype.render = function () {
|
NewKeychain.prototype.render = function () {
|
||||||
const props = this.props
|
// const props = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
h('div', {
|
h('div', {
|
||||||
@ -23,11 +23,7 @@ NewKeychain.prototype.render = function () {
|
|||||||
background: 'blue',
|
background: 'blue',
|
||||||
},
|
},
|
||||||
}, [
|
}, [
|
||||||
h('h1',`Here's a list!!!!`),
|
h('h1', `Here's a list!!!!`),
|
||||||
h('button',
|
|
||||||
{
|
|
||||||
onClick: () => this.props.dispatch(actions.goHome())
|
|
||||||
})
|
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user