2014-10-24 08:24:44 -07:00
|
|
|
var cryptoUtil = require('../util/crypto');
|
|
|
|
var InsightStorage = require('./InsightStorage');
|
|
|
|
var inherits = require('inherits');
|
2014-12-02 06:17:03 -08:00
|
|
|
var log = require('../util/log');
|
2014-11-10 20:23:12 -08:00
|
|
|
var SEPARATOR = '%^#@';
|
2014-10-24 08:24:44 -07:00
|
|
|
|
|
|
|
function EncryptedInsightStorage(config) {
|
|
|
|
InsightStorage.apply(this, [config]);
|
|
|
|
}
|
|
|
|
inherits(EncryptedInsightStorage, InsightStorage);
|
|
|
|
|
2014-11-10 17:58:46 -08:00
|
|
|
EncryptedInsightStorage.prototype._brokenDecrypt = function(body) {
|
|
|
|
var key = cryptoUtil.kdf(this.password + this.email, 'mjuBtGybi/4=', 100);
|
|
|
|
log.debug('Trying legacy decrypt')
|
|
|
|
var decryptedJson = cryptoUtil.decrypt(key, body);
|
|
|
|
return decryptedJson;
|
|
|
|
};
|
|
|
|
|
2014-12-18 10:50:42 -08:00
|
|
|
EncryptedInsightStorage.prototype.resendVerificationEmail = function(callback) {
|
|
|
|
InsightStorage.prototype.resendVerificationEmail.apply(this, [callback]);
|
|
|
|
};
|
|
|
|
|
2014-10-24 08:24:44 -07:00
|
|
|
EncryptedInsightStorage.prototype.getItem = function(name, callback) {
|
2014-11-10 18:08:14 -08:00
|
|
|
var self = this;
|
2014-10-27 06:49:25 -07:00
|
|
|
InsightStorage.prototype.getItem.apply(this, [name,
|
2014-12-01 11:19:34 -08:00
|
|
|
function(err, body, headers) {
|
2014-10-28 11:20:43 -07:00
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
2014-11-10 20:23:12 -08:00
|
|
|
var decryptedJson = cryptoUtil.decrypt(self.email + SEPARATOR + self.password, body);
|
2014-11-10 17:58:46 -08:00
|
|
|
|
|
|
|
if (!decryptedJson) {
|
2014-11-10 18:08:14 -08:00
|
|
|
log.debug('Could not decrypt value using current decryption schema');
|
|
|
|
decryptedJson = self._brokenDecrypt(body);
|
2014-11-10 17:58:46 -08:00
|
|
|
}
|
|
|
|
|
2014-10-27 06:49:25 -07:00
|
|
|
if (!decryptedJson) {
|
2014-11-10 17:58:46 -08:00
|
|
|
log.debug('Could not decrypt value.');
|
2014-10-28 14:06:32 -07:00
|
|
|
return callback('PNOTFOUND');
|
2014-10-27 06:49:25 -07:00
|
|
|
}
|
2014-12-01 11:19:34 -08:00
|
|
|
return callback(null, decryptedJson, headers);
|
2014-10-24 08:24:44 -07:00
|
|
|
}
|
2014-10-27 06:49:25 -07:00
|
|
|
]);
|
2014-10-24 08:24:44 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
EncryptedInsightStorage.prototype.setItem = function(name, value, callback) {
|
2014-11-10 20:23:12 -08:00
|
|
|
var record = cryptoUtil.encrypt(this.email + SEPARATOR + this.password, value);
|
2014-10-24 08:24:44 -07:00
|
|
|
InsightStorage.prototype.setItem.apply(this, [name, record, callback]);
|
|
|
|
};
|
|
|
|
|
2014-10-27 06:49:25 -07:00
|
|
|
EncryptedInsightStorage.prototype.removeItem = function(name, callback) {
|
|
|
|
InsightStorage.prototype.removeItem.apply(this, [name, callback]);
|
|
|
|
};
|
|
|
|
|
2014-12-10 07:03:00 -08:00
|
|
|
EncryptedInsightStorage.prototype.clear = function(callback) {
|
|
|
|
InsightStorage.prototype.clear.apply(this, [callback]);
|
|
|
|
};
|
|
|
|
|
2014-10-24 08:24:44 -07:00
|
|
|
module.exports = EncryptedInsightStorage;
|