Merge pull request #2148 from matiu/bug/encrypt-localstorage
Bug/encrypt localstorage
This commit is contained in:
commit
275dc2e3d6
5 changed files with 33 additions and 13 deletions
|
|
@ -5,7 +5,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
||||||
var _credentials, _firstpin;
|
var _credentials, _firstpin;
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
$scope.isMobile = isMobile.any();
|
$scope.isMobile = isMobile.any();
|
||||||
$scope.attempt=0;
|
$scope.attempt = 0;
|
||||||
|
|
||||||
// This is only for backwards compat, insight api should link to #!/confirmed directly
|
// This is only for backwards compat, insight api should link to #!/confirmed directly
|
||||||
if (getParam('confirmed')) {
|
if (getParam('confirmed')) {
|
||||||
|
|
@ -43,12 +43,12 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
||||||
if (newValue === _firstpin) {
|
if (newValue === _firstpin) {
|
||||||
_firstpin = null;
|
_firstpin = null;
|
||||||
$scope.createPin(newValue);
|
$scope.createPin(newValue);
|
||||||
} else {
|
} else {
|
||||||
$scope.$$childTail.setPinForm.newpin.$setViewValue('');
|
$scope.$$childTail.setPinForm.newpin.$setViewValue('');
|
||||||
$scope.$$childTail.setPinForm.newpin.$render();
|
$scope.$$childTail.setPinForm.newpin.$render();
|
||||||
$scope.$$childTail.setPinForm.repeatpin.$setViewValue('');
|
$scope.$$childTail.setPinForm.repeatpin.$setViewValue('');
|
||||||
$scope.$$childTail.setPinForm.repeatpin.$render();
|
$scope.$$childTail.setPinForm.repeatpin.$render();
|
||||||
|
|
||||||
_firstpin = null;
|
_firstpin = null;
|
||||||
$scope.askForPin = 1;
|
$scope.askForPin = 1;
|
||||||
$scope.error = 'Entered PINs were not equal. Try again';
|
$scope.error = 'Entered PINs were not equal. Try again';
|
||||||
|
|
@ -62,7 +62,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$rootScope.starting = true;
|
$rootScope.starting = true;
|
||||||
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
var credentials = pinService.get(pin, function(err, credentials) {
|
var credentials = pinService.get(pin, function(err, credentials) {
|
||||||
if (err || !credentials) {
|
if (err || !credentials) {
|
||||||
|
|
@ -72,7 +72,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
||||||
}
|
}
|
||||||
$scope.open(credentials.email, credentials.password);
|
$scope.open(credentials.email, credentials.password);
|
||||||
});
|
});
|
||||||
},100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.openWallets = function() {
|
$scope.openWallets = function() {
|
||||||
|
|
@ -98,7 +98,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
||||||
$rootScope.starting = null;
|
$rootScope.starting = null;
|
||||||
$scope.openWallets();
|
$scope.openWallets();
|
||||||
});
|
});
|
||||||
},100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.openWithCredentials = function(form) {
|
$scope.openWithCredentials = function(form) {
|
||||||
|
|
@ -128,7 +128,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
||||||
if ((err.toString() || '').match('PNOTFOUND')) {
|
if ((err.toString() || '').match('PNOTFOUND')) {
|
||||||
$scope.error = 'Invalid email or password';
|
$scope.error = 'Invalid email or password';
|
||||||
|
|
||||||
if($scope.attempt++>1) {
|
if ($scope.attempt++ > 1) {
|
||||||
var storage = $scope.usingLocalStorage ? 'this device storage' : 'cloud storage';
|
var storage = $scope.usingLocalStorage ? 'this device storage' : 'cloud storage';
|
||||||
$scope.error = 'Invalid email or password. You are trying to sign in using ' + storage + '. Change it on settings is necessary.';
|
$scope.error = 'Invalid email or password. You are trying to sign in using ' + storage + '. Change it on settings is necessary.';
|
||||||
};
|
};
|
||||||
|
|
@ -144,9 +144,9 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
||||||
$scope.error = 'Unknown error';
|
$scope.error = 'Unknown error';
|
||||||
}
|
}
|
||||||
$rootScope.starting = false;
|
$rootScope.starting = false;
|
||||||
$timeout(function(){
|
$timeout(function() {
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
},1)
|
}, 1)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,7 +164,9 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
||||||
$scope.askForPin = 1;
|
$scope.askForPin = 1;
|
||||||
$rootScope.starting = false;
|
$rootScope.starting = false;
|
||||||
$rootScope.hideNavigation = true;
|
$rootScope.hideNavigation = true;
|
||||||
$rootScope.$digest();
|
$timeout(function() {
|
||||||
|
$rootScope.$digest();
|
||||||
|
}, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// no mobile
|
// no mobile
|
||||||
|
|
|
||||||
|
|
@ -377,6 +377,7 @@ Identity.prototype._cleanUp = function() {
|
||||||
* @desc Closes the wallet and disconnects all services
|
* @desc Closes the wallet and disconnects all services
|
||||||
*/
|
*/
|
||||||
Identity.prototype.close = function() {
|
Identity.prototype.close = function() {
|
||||||
|
|
||||||
this._cleanUp();
|
this._cleanUp();
|
||||||
this.emitAndKeepAlive('closed');
|
this.emitAndKeepAlive('closed');
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ function EncryptedInsightStorage(config) {
|
||||||
}
|
}
|
||||||
inherits(EncryptedInsightStorage, InsightStorage);
|
inherits(EncryptedInsightStorage, InsightStorage);
|
||||||
|
|
||||||
|
|
||||||
EncryptedInsightStorage.prototype._brokenDecrypt = function(body) {
|
EncryptedInsightStorage.prototype._brokenDecrypt = function(body) {
|
||||||
var key = cryptoUtil.kdf(this.password + this.email, 'mjuBtGybi/4=', 100);
|
var key = cryptoUtil.kdf(this.password + this.email, 'mjuBtGybi/4=', 100);
|
||||||
log.debug('Trying legacy decrypt')
|
log.debug('Trying legacy decrypt')
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ var cryptoUtil = require('../util/crypto');
|
||||||
var log = require('../util/log');
|
var log = require('../util/log');
|
||||||
var LocalStorage = require('./LocalStorage');
|
var LocalStorage = require('./LocalStorage');
|
||||||
var inherits = require('inherits');
|
var inherits = require('inherits');
|
||||||
|
var preconditions = require('preconditions').singleton();
|
||||||
|
|
||||||
var SEPARATOR = '@#$';
|
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) {
|
EncryptedLocalStorage.prototype.getItem = function(name, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
preconditions.checkState(self.email);
|
||||||
|
|
||||||
LocalStorage.prototype.getItem.apply(this, [name,
|
LocalStorage.prototype.getItem.apply(this, [name,
|
||||||
function(err, body) {
|
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) {
|
if (!decryptedJson) {
|
||||||
log.debug('Could not decrypt value using current decryption schema');
|
log.debug('Could not decrypt value using current decryption schema');
|
||||||
decryptedJson = self._brokenDecrypt(body);
|
decryptedJson = self._brokenDecrypt(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!decryptedJson) {
|
||||||
|
decryptedJson = self._brokenDecryptUndef(body);
|
||||||
|
}
|
||||||
|
|
||||||
if (!decryptedJson) {
|
if (!decryptedJson) {
|
||||||
log.debug('Could not decrypt value.');
|
log.debug('Could not decrypt value.');
|
||||||
return callback('PNOTFOUND');
|
return callback('PNOTFOUND');
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,8 @@ function LocalStorage(opts) {
|
||||||
LocalStorage.prototype.init = function() {};
|
LocalStorage.prototype.init = function() {};
|
||||||
|
|
||||||
LocalStorage.prototype.setCredentials = function(email, password, opts) {
|
LocalStorage.prototype.setCredentials = function(email, password, opts) {
|
||||||
// NOP
|
this.email = email;
|
||||||
|
this.password = password;
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.getItem = function(k, cb) {
|
LocalStorage.prototype.getItem = function(k, cb) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue