mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
feat: no need for integrity check for encrypted backups
This commit is contained in:
@@ -39,22 +39,23 @@ export default class Backup {
|
||||
);
|
||||
|
||||
let data = Object.fromEntries(await this._db.context.readMulti(keys));
|
||||
let hash = {};
|
||||
|
||||
if (encrypt) {
|
||||
const key = await this._db.user.getEncryptionKey();
|
||||
data = await this._db.context.encrypt(key, JSON.stringify(data));
|
||||
} else {
|
||||
hash = { hash: SparkMD5.hash(JSON.stringify(data)), hash_type: "md5" };
|
||||
}
|
||||
|
||||
// save backup time
|
||||
await this._db.context.write("lastBackupTime", Date.now());
|
||||
|
||||
return JSON.stringify({
|
||||
version: CURRENT_DATABASE_VERSION,
|
||||
type,
|
||||
date: Date.now(),
|
||||
data,
|
||||
hash: SparkMD5.hash(JSON.stringify(data)),
|
||||
hash_type: "md5",
|
||||
...hash,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,15 +72,13 @@ 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) {
|
||||
if (!key) key = await this._db.user.getEncryptionKey();
|
||||
backup.data = JSON.parse(await this._db.context.decrypt(key, db));
|
||||
}
|
||||
} else if (!this._verify(backup))
|
||||
throw new Error("Backup file has been tempered, aborting...");
|
||||
|
||||
await this._migrateData(backup);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user