You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-12-02 22:49:09 +02:00
All: Fixed various issues regarding encryption and decryptino of resources, and started doing GUI for Electron app
This commit is contained in:
@@ -268,20 +268,17 @@ class BaseItem extends BaseModel {
|
||||
|
||||
const cipherText = await this.encryptionService().encryptString(serialized);
|
||||
|
||||
const reducedItem = Object.assign({}, item);
|
||||
//const reducedItem = Object.assign({}, item);
|
||||
|
||||
// List of keys that won't be encrypted - mostly foreign keys required to link items
|
||||
// with each others and timestamp required for synchronisation.
|
||||
const keepKeys = ['id', 'note_id', 'tag_id', 'parent_id', 'updated_time', 'type_'];
|
||||
const reducedItem = {};
|
||||
|
||||
for (let n in reducedItem) {
|
||||
if (!reducedItem.hasOwnProperty(n)) continue;
|
||||
|
||||
if (keepKeys.indexOf(n) >= 0) {
|
||||
continue;
|
||||
} else {
|
||||
delete reducedItem[n];
|
||||
}
|
||||
for (let i = 0; i < keepKeys.length; i++) {
|
||||
const n = keepKeys[i];
|
||||
if (!item.hasOwnProperty(n)) continue;
|
||||
reducedItem[n] = item[n];
|
||||
}
|
||||
|
||||
reducedItem.encryption_applied = 1;
|
||||
@@ -370,7 +367,7 @@ class BaseItem extends BaseModel {
|
||||
const className = classNames[i];
|
||||
const ItemClass = this.getClass(className);
|
||||
|
||||
const whereSql = ['encryption_applied = 1'];
|
||||
const whereSql = className === 'Resource' ? ['(encryption_blob_encrypted = 1 OR encryption_applied = 1)'] : ['encryption_applied = 1'];
|
||||
if (exclusions.length) whereSql.push('id NOT IN ("' + exclusions.join('","') + '")');
|
||||
|
||||
const sql = sprintf(`
|
||||
|
||||
@@ -53,7 +53,9 @@ class Resource extends BaseItem {
|
||||
|
||||
// For resources, we need to decrypt the item (metadata) and the resource binary blob.
|
||||
static async decrypt(item) {
|
||||
const decryptedItem = await super.decrypt(item);
|
||||
// The item might already be decrypted but not the blob (for instance if it crashes while
|
||||
// decrypting the blob or was otherwise interrupted).
|
||||
const decryptedItem = item.encryption_cipher_text ? await super.decrypt(item) : Object.assign({}, item);
|
||||
if (!decryptedItem.encryption_blob_encrypted) return decryptedItem;
|
||||
|
||||
const plainTextPath = this.fullPath(decryptedItem);
|
||||
@@ -69,7 +71,7 @@ class Resource extends BaseItem {
|
||||
}
|
||||
|
||||
await this.encryptionService().decryptFile(encryptedPath, plainTextPath);
|
||||
item.encryption_blob_encrypted = 0;
|
||||
decryptedItem.encryption_blob_encrypted = 0;
|
||||
return Resource.save(decryptedItem, { autoTimestamp: false });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user