Merge pull request #2148 from matiu/bug/encrypt-localstorage

Bug/encrypt localstorage
This commit is contained in:
Matias Alejo Garcia 2014-12-13 20:13:54 -03:00
commit 275dc2e3d6
5 changed files with 33 additions and 13 deletions

View file

@ -164,7 +164,9 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
$scope.askForPin = 1;
$rootScope.starting = false;
$rootScope.hideNavigation = true;
$timeout(function() {
$rootScope.$digest();
}, 1);
return;
}
// no mobile

View file

@ -377,6 +377,7 @@ Identity.prototype._cleanUp = function() {
* @desc Closes the wallet and disconnects all services
*/
Identity.prototype.close = function() {
this._cleanUp();
this.emitAndKeepAlive('closed');
};

View file

@ -9,7 +9,6 @@ function EncryptedInsightStorage(config) {
}
inherits(EncryptedInsightStorage, InsightStorage);
EncryptedInsightStorage.prototype._brokenDecrypt = function(body) {
var key = cryptoUtil.kdf(this.password + this.email, 'mjuBtGybi/4=', 100);
log.debug('Trying legacy decrypt')

View file

@ -2,6 +2,7 @@ var cryptoUtil = require('../util/crypto');
var log = require('../util/log');
var LocalStorage = require('./LocalStorage');
var inherits = require('inherits');
var preconditions = require('preconditions').singleton();
var SEPARATOR = '@#$';
@ -19,17 +20,33 @@ EncryptedLocalStorage.prototype._brokenDecrypt = function(body) {
};
EncryptedLocalStorage.prototype._brokenDecryptUndef = function(body) {
var badkey = undefined + SEPARATOR + undefined;
return cryptoUtil.decrypt(badkey, body);
};
EncryptedLocalStorage.prototype.getItem = function(name, callback) {
var self = this;
preconditions.checkState(self.email);
LocalStorage.prototype.getItem.apply(this, [name,
function(err, body) {
var decryptedJson = cryptoUtil.decrypt(self.email + SEPARATOR + self.password, body);
var decryptedJson = cryptoUtil.decrypt(self.email + SEPARATOR + self.password, body);
if (!decryptedJson) {
log.debug('Could not decrypt value using current decryption schema');
decryptedJson = self._brokenDecrypt(body);
}
if (!decryptedJson) {
decryptedJson = self._brokenDecryptUndef(body);
}
if (!decryptedJson) {
log.debug('Could not decrypt value.');
return callback('PNOTFOUND');

View file

@ -26,7 +26,8 @@ function LocalStorage(opts) {
LocalStorage.prototype.init = function() {};
LocalStorage.prototype.setCredentials = function(email, password, opts) {
// NOP
this.email = email;
this.password = password;
};
LocalStorage.prototype.getItem = function(k, cb) {