mirror of https://github.com/keeweb/keeweb
clearing cache on file close
parent
5002c2ce67
commit
d0d013e046
|
@ -6,6 +6,10 @@ const logger = new Logger('chal-resp');
|
|||
const ChalRespCalculator = {
|
||||
cache: {},
|
||||
|
||||
getCacheKey(params) {
|
||||
return `${params.vid}:${params.pid}:${params.serial}`;
|
||||
},
|
||||
|
||||
build(params) {
|
||||
if (!params) {
|
||||
return null;
|
||||
|
@ -17,8 +21,8 @@ const ChalRespCalculator = {
|
|||
challenge = Buffer.from(challenge);
|
||||
const hexChallenge = challenge.toString('hex');
|
||||
|
||||
const deviceCacheKey = `${params.vid}:${params.pid}:${params.serial}`;
|
||||
const respFromCache = this.cache[deviceCacheKey]?.[hexChallenge];
|
||||
const cacheKey = this.getCacheKey(params);
|
||||
const respFromCache = this.cache[cacheKey]?.[hexChallenge];
|
||||
if (respFromCache) {
|
||||
logger.debug('Found ChalResp in cache');
|
||||
return resolve(Buffer.from(respFromCache, 'hex'));
|
||||
|
@ -41,16 +45,20 @@ const ChalRespCalculator = {
|
|||
return reject(err);
|
||||
}
|
||||
|
||||
if (!this.cache[deviceCacheKey]) {
|
||||
this.cache[deviceCacheKey] = {};
|
||||
if (!this.cache[cacheKey]) {
|
||||
this.cache[cacheKey] = {};
|
||||
}
|
||||
this.cache[deviceCacheKey][hexChallenge] = response.toString('hex');
|
||||
this.cache[cacheKey][hexChallenge] = response.toString('hex');
|
||||
|
||||
logger.info('Calculated ChalResp', logger.ts(ts));
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
clearCache(params) {
|
||||
delete this.cache[this.getCacheKey(params)];
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -688,7 +688,7 @@ class AppModel {
|
|||
this.fileOpened(file, data, params);
|
||||
};
|
||||
const open = () => {
|
||||
file.open(params.password, data, params.keyFileData, params.chalResp, openComplete);
|
||||
file.open(params.password, data, params.keyFileData, openComplete);
|
||||
};
|
||||
if (needLoadKeyFile) {
|
||||
Storage.file.load(params.keyFilePath, {}, (err, data) => {
|
||||
|
|
|
@ -21,9 +21,9 @@ class FileModel extends Model {
|
|||
});
|
||||
}
|
||||
|
||||
open(password, fileData, keyFileData, chalResp, callback) {
|
||||
open(password, fileData, keyFileData, callback) {
|
||||
try {
|
||||
const challengeResponse = ChalRespCalculator.build(chalResp);
|
||||
const challengeResponse = ChalRespCalculator.build(this.chalResp);
|
||||
const credentials = new kdbxweb.Credentials(password, keyFileData, challengeResponse);
|
||||
const ts = logger.ts();
|
||||
|
||||
|
@ -58,7 +58,7 @@ class FileModel extends Model {
|
|||
logger.info(
|
||||
'Error opening file with empty password, try to open with null password'
|
||||
);
|
||||
return this.open(null, fileData, keyFileData, chalResp, callback);
|
||||
return this.open(null, fileData, keyFileData, this.chalResp, callback);
|
||||
}
|
||||
logger.error('Error opening file', err.code, err.message, err);
|
||||
callback(err);
|
||||
|
@ -346,6 +346,9 @@ class FileModel extends Model {
|
|||
keyFileChanged: false,
|
||||
syncing: false
|
||||
});
|
||||
if (this.chalResp) {
|
||||
ChalRespCalculator.clearCache(this.chalResp);
|
||||
}
|
||||
}
|
||||
|
||||
getEntry(id) {
|
||||
|
|
Loading…
Reference in New Issue