more fixes
This commit is contained in:
parent
5ca398a97a
commit
dd61c1b5b3
4 changed files with 20 additions and 12 deletions
|
|
@ -2,6 +2,7 @@ var cryptoUtil = require('../util/crypto');
|
||||||
var InsightStorage = require('./InsightStorage');
|
var InsightStorage = require('./InsightStorage');
|
||||||
var inherits = require('inherits');
|
var inherits = require('inherits');
|
||||||
var log = require('../log');
|
var log = require('../log');
|
||||||
|
var SEPARATOR = '%^#@';
|
||||||
|
|
||||||
function EncryptedInsightStorage(config) {
|
function EncryptedInsightStorage(config) {
|
||||||
InsightStorage.apply(this, [config]);
|
InsightStorage.apply(this, [config]);
|
||||||
|
|
@ -23,7 +24,7 @@ EncryptedInsightStorage.prototype.getItem = function(name, callback) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
var decryptedJson = cryptoUtil.decrypt(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');
|
||||||
|
|
@ -40,7 +41,7 @@ EncryptedInsightStorage.prototype.getItem = function(name, callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
EncryptedInsightStorage.prototype.setItem = function(name, value, callback) {
|
EncryptedInsightStorage.prototype.setItem = function(name, value, callback) {
|
||||||
var record = cryptoUtil.encrypt(this.password, value);
|
var record = cryptoUtil.encrypt(this.email + SEPARATOR + this.password, value);
|
||||||
InsightStorage.prototype.setItem.apply(this, [name, record, callback]);
|
InsightStorage.prototype.setItem.apply(this, [name, record, callback]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ var log = require('../log');
|
||||||
var LocalStorage = require('./LocalStorage');
|
var LocalStorage = require('./LocalStorage');
|
||||||
var inherits = require('inherits');
|
var inherits = require('inherits');
|
||||||
|
|
||||||
|
var SEPARATOR = '@#$';
|
||||||
|
|
||||||
function EncryptedLocalStorage(config) {
|
function EncryptedLocalStorage(config) {
|
||||||
LocalStorage.apply(this, [config]);
|
LocalStorage.apply(this, [config]);
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +23,7 @@ EncryptedLocalStorage.prototype.getItem = function(name, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
LocalStorage.prototype.getItem.apply(this, [name,
|
LocalStorage.prototype.getItem.apply(this, [name,
|
||||||
function(err, body) {
|
function(err, body) {
|
||||||
var decryptedJson = cryptoUtil.decrypt(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');
|
||||||
|
|
@ -42,7 +44,7 @@ EncryptedLocalStorage.prototype.setItem = function(name, value, callback) {
|
||||||
if (!_.isString(value)) {
|
if (!_.isString(value)) {
|
||||||
value = JSON.stringify(value);
|
value = JSON.stringify(value);
|
||||||
}
|
}
|
||||||
var record = cryptoUtil.encrypt(this.password, value);
|
var record = cryptoUtil.encrypt(this.email + SEPARATOR + this.password, value);
|
||||||
LocalStorage.prototype.setItem.apply(this, [name, record, callback]);
|
LocalStorage.prototype.setItem.apply(this, [name, record, callback]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
var cryptoUtil = require('../util/crypto');
|
var cryptoUtil = require('../util/crypto');
|
||||||
|
var bitcore = require('bitcore');
|
||||||
var buffers = require('buffer');
|
var buffers = require('buffer');
|
||||||
var querystring = require('querystring');
|
var querystring = require('querystring');
|
||||||
var Identity = require('../models/Identity');
|
var Identity = require('../models/Identity');
|
||||||
|
var log = require('../log');
|
||||||
|
|
||||||
var SEPARATOR = '|';
|
var SEPARATOR = '|';
|
||||||
var BODY = 'IR7GCUVgaLGe4LCtXjtUo4hsH8BO67jIrBKCeFiYOQ7CKWVPx3FshqTM';
|
|
||||||
|
|
||||||
function InsightStorage(config) {
|
function InsightStorage(config) {
|
||||||
this.type = 'DB';
|
this.type = 'DB';
|
||||||
|
|
@ -46,6 +47,7 @@ InsightStorage.prototype.getItem = function(name, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this._makeGetRequest(passphrase, name, function(err, body) {
|
this._makeGetRequest(passphrase, name, function(err, body) {
|
||||||
|
console.log('[InsightStorage.js.49:err:]',err); //TODO
|
||||||
if (err && err.indexOf('PNOTFOUND') !== -1 && mayBeOldPassword(self.password)) {
|
if (err && err.indexOf('PNOTFOUND') !== -1 && mayBeOldPassword(self.password)) {
|
||||||
return self._brokenGetItem(name, callback);
|
return self._brokenGetItem(name, callback);
|
||||||
}
|
}
|
||||||
|
|
@ -53,12 +55,13 @@ InsightStorage.prototype.getItem = function(name, callback) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This key has not need to have the same
|
/* This key need to have DIFFERENT
|
||||||
* settings(salt,iterations) as the kdf for wallet/profile encryption
|
* settings(salt,iterations) than the kdf for wallet/profile encryption
|
||||||
* in Encrpted*Storage. And, actually, it good for the user to be able
|
* in Encrpted*Storage. The user should be able
|
||||||
* to change the settings con config.js to modify salt / iterations but
|
* to change the settings on config.js to modify salt / iterations
|
||||||
|
* for encryption, but
|
||||||
* mantain the same key & passphrase. This is why those settings are
|
* mantain the same key & passphrase. This is why those settings are
|
||||||
* not shared.
|
* not shared with encryption
|
||||||
*/
|
*/
|
||||||
InsightStorage.prototype.getKey = function() {
|
InsightStorage.prototype.getKey = function() {
|
||||||
if (!this._cachedKey) {
|
if (!this._cachedKey) {
|
||||||
|
|
@ -68,12 +71,13 @@ InsightStorage.prototype.getKey = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
InsightStorage.prototype.getPassphrase = function() {
|
InsightStorage.prototype.getPassphrase = function() {
|
||||||
return cryptoUtil.hmac(this.getKey(), BODY);
|
return bitcore.util.twoSha256(this.getKey()).toString('base64');
|
||||||
};
|
};
|
||||||
|
|
||||||
InsightStorage.prototype._makeGetRequest = function(passphrase, key, callback) {
|
InsightStorage.prototype._makeGetRequest = function(passphrase, key, callback) {
|
||||||
var authHeader = new buffers.Buffer(this.email + ':' + passphrase).toString('base64');
|
var authHeader = new buffers.Buffer(this.email + ':' + passphrase).toString('base64');
|
||||||
var retrieveUrl = this.storeUrl + '/retrieve';
|
var retrieveUrl = this.storeUrl + '/retrieve';
|
||||||
|
log.debug(retrieveUrl);
|
||||||
this.request.get({
|
this.request.get({
|
||||||
url: retrieveUrl + '?' + querystring.encode({
|
url: retrieveUrl + '?' + querystring.encode({
|
||||||
key: key
|
key: key
|
||||||
|
|
@ -100,6 +104,7 @@ InsightStorage.prototype._makeGetRequest = function(passphrase, key, callback) {
|
||||||
InsightStorage.prototype._brokenGetItem = function(name, callback) {
|
InsightStorage.prototype._brokenGetItem = function(name, callback) {
|
||||||
var passphrase = this._makeBrokenSecret();
|
var passphrase = this._makeBrokenSecret();
|
||||||
var self = this;
|
var self = this;
|
||||||
|
log.debug('using legacy get');
|
||||||
this._makeGetRequest(passphrase, name, function(err, body) {
|
this._makeGetRequest(passphrase, name, function(err, body) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
return self._changePassphrase(function(err) {
|
return self._changePassphrase(function(err) {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ describe('insight storage plugin', function() {
|
||||||
var namespace = 'profile::0000000000000000000000000000000000000000';
|
var namespace = 'profile::0000000000000000000000000000000000000000';
|
||||||
|
|
||||||
var oldSecret = 'rFA+F/N+ZvKXp717zBdfCKYQ5v9Fjry0W6tautj5etIH' + 'KLQliZBEYXA7AXjTJ9K3DglzGWJKost3QJUCMbhM/A=='
|
var oldSecret = 'rFA+F/N+ZvKXp717zBdfCKYQ5v9Fjry0W6tautj5etIH' + 'KLQliZBEYXA7AXjTJ9K3DglzGWJKost3QJUCMbhM/A=='
|
||||||
var newSecret = 'rcNEqxJZV1fsrZgpwpET8D9aCsCIYXS7XOGlsONgEiA=';
|
var newSecret = '96KnVsaQFv8vsbxAFeYyGM4nO/8B6YaVNKz9IxDmwzk=';
|
||||||
|
|
||||||
var setupStorageCredentials = function() {
|
var setupStorageCredentials = function() {
|
||||||
storage.setCredentials(email, password);
|
storage.setCredentials(email, password);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue