fix compatibility issues
This commit is contained in:
parent
7207f03bd1
commit
7942048dd1
7 changed files with 115 additions and 43 deletions
|
|
@ -7,15 +7,29 @@ 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')
|
||||
var decryptedJson = cryptoUtil.decrypt(key, body);
|
||||
return decryptedJson;
|
||||
};
|
||||
|
||||
EncryptedInsightStorage.prototype.getItem = function(name, callback) {
|
||||
var key = cryptoUtil.kdf(this.password + this.email);
|
||||
InsightStorage.prototype.getItem.apply(this, [name,
|
||||
function(err, body) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var decryptedJson = cryptoUtil.decrypt(key, body);
|
||||
var decryptedJson = cryptoUtil.decrypt(this.password, body);
|
||||
log.debug('Could not decrypt value using current decryption schema');
|
||||
|
||||
if (!decryptedJson) {
|
||||
decryptedJson = this._brokenDecrypt(body);
|
||||
}
|
||||
|
||||
if (!decryptedJson) {
|
||||
log.debug('Could not decrypt value.');
|
||||
return callback('PNOTFOUND');
|
||||
}
|
||||
return callback(null, decryptedJson);
|
||||
|
|
@ -24,13 +38,11 @@ EncryptedInsightStorage.prototype.getItem = function(name, callback) {
|
|||
};
|
||||
|
||||
EncryptedInsightStorage.prototype.setItem = function(name, value, callback) {
|
||||
var key = cryptoUtil.kdf(this.password + this.email);
|
||||
var record = cryptoUtil.encrypt(key, value);
|
||||
var record = cryptoUtil.encrypt(this.password, value);
|
||||
InsightStorage.prototype.setItem.apply(this, [name, record, callback]);
|
||||
};
|
||||
|
||||
EncryptedInsightStorage.prototype.removeItem = function(name, callback) {
|
||||
var key = cryptoUtil.kdf(this.password + this.email);
|
||||
InsightStorage.prototype.removeItem.apply(this, [name, callback]);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue