Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: restoring encrypted backups caused temper error

thecodrreb08460a8866
diff --git a/packages/core/database/backup.js b/packages/core/database/backup.js
index b8b0ded16..a2bf0824b 100644
--- a/packages/core/database/backup.js
+++ b/packages/core/database/backup.js
@@ -62,7 +62,7 @@ export default class Backup {
*
* @param {string} data the backup data
*/
- async import(data) {
+ async import(data, key) {
if (!data) return;
let backup = JSON.parse(data);
@@ -71,16 +71,16 @@ export default class Backup {
backup = this._migrateBackup(backup);
+ if (!this._verify(backup))
+ throw new Error("Backup file has been tempered, aborting...");
+
let db = backup.data;
//check if we have encrypted data
if (db.salt && db.iv) {
- const key = await this._db.user.getEncryptionKey();
- db = JSON.parse(await this._db.context.decrypt(key, db));
+ if (!key) key = await this._db.user.getEncryptionKey();
+ 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);
}