fix: restoring encrypted backups caused temper error

This commit is contained in:
thecodrr
2021-07-05 20:35:14 +05:00
parent e29d49768c
commit eb08460a88

View File

@@ -62,7 +62,7 @@ export default class Backup {
* *
* @param {string} data the backup data * @param {string} data the backup data
*/ */
async import(data) { async import(data, key) {
if (!data) return; if (!data) return;
let backup = JSON.parse(data); let backup = JSON.parse(data);
@@ -71,16 +71,16 @@ export default class Backup {
backup = this._migrateBackup(backup); backup = this._migrateBackup(backup);
if (!this._verify(backup))
throw new Error("Backup file has been tempered, aborting...");
let db = backup.data; let db = backup.data;
//check if we have encrypted data //check if we have encrypted data
if (db.salt && db.iv) { if (db.salt && db.iv) {
const key = await this._db.user.getEncryptionKey(); if (!key) key = await this._db.user.getEncryptionKey();
db = JSON.parse(await this._db.context.decrypt(key, db)); backup.data = JSON.parse(await this._db.context.decrypt(key, db));
} }
if (!this._verify(backup))
throw new Error("Backup file has been tempered, aborting...");
await this._migrateData(backup); await this._migrateData(backup);
} }