mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
fix: restoring encrypted backups caused temper error
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user