From de30095737f7ae9168aa6a4684b583fca6c93c1d Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 25 Sep 2020 20:55:45 +0200 Subject: [PATCH 1/5] change salts on password change + more robust handling of decryption failures --- package-lock.json | 2 +- src/entities/note.js | 2 +- src/services/change_password.js | 10 +++++++--- src/services/note_cache/entities/note.js | 2 +- src/services/note_cache/note_cache_loader.js | 8 +++++++- src/services/protected_session.js | 12 +++++++++--- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 42014c0a1..4aeaa7bbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.44.3-beta", + "version": "0.44.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/entities/note.js b/src/entities/note.js index 1db0e8abb..5bb4326a3 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -805,7 +805,7 @@ class Note extends Entity { * @returns {boolean} - true if note has children */ hasChildren() { - return (this.getChildNotes()).length > 0; + return this.getChildNotes().length > 0; } /** diff --git a/src/services/change_password.js b/src/services/change_password.js index ed59a1808..b06e71328 100644 --- a/src/services/change_password.js +++ b/src/services/change_password.js @@ -14,10 +14,14 @@ function changePassword(currentPassword, newPassword) { }; } - const newPasswordVerificationKey = utils.toBase64(myScryptService.getVerificationHash(newPassword)); - const decryptedDataKey = passwordEncryptionService.getDataKey(currentPassword); - sql.transactional(() => { + const decryptedDataKey = passwordEncryptionService.getDataKey(currentPassword); + + optionService.setOption('passwordVerificationSalt', utils.randomSecureToken(32)); + optionService.setOption('passwordDerivedKeySalt', utils.randomSecureToken(32)); + + const newPasswordVerificationKey = utils.toBase64(myScryptService.getVerificationHash(newPassword)); + passwordEncryptionService.setDataKey(newPassword, decryptedDataKey); optionService.setOption('passwordVerificationHash', newPasswordVerificationKey); diff --git a/src/services/note_cache/entities/note.js b/src/services/note_cache/entities/note.js index 0ed575941..7186eb9d0 100644 --- a/src/services/note_cache/entities/note.js +++ b/src/services/note_cache/entities/note.js @@ -327,7 +327,7 @@ class Note { decrypt() { if (this.isProtected && !this.isDecrypted && protectedSessionService.isProtectedSessionAvailable()) { - this.title = protectedSessionService.decryptString(note.title); + this.title = protectedSessionService.decryptString(this.title); this.isDecrypted = true; } diff --git a/src/services/note_cache/note_cache_loader.js b/src/services/note_cache/note_cache_loader.js index 6129bf07f..eca5b6d83 100644 --- a/src/services/note_cache/note_cache_loader.js +++ b/src/services/note_cache/note_cache_loader.js @@ -4,6 +4,7 @@ const sql = require('../sql.js'); const eventService = require('../events.js'); const noteCache = require('./note_cache'); const sqlInit = require('../sql_init'); +const log = require('../log'); const Note = require('./entities/note'); const Branch = require('./entities/branch'); const Attribute = require('./entities/attribute'); @@ -147,7 +148,12 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED }); eventService.subscribe(eventService.ENTER_PROTECTED_SESSION, () => { - noteCache.decryptProtectedNotes(); + try { + noteCache.decryptProtectedNotes(); + } + catch (e) { + log.error(`Could not decrypt protected notes: ${e.message} ${e.stack}`); + } }); module.exports = { diff --git a/src/services/protected_session.js b/src/services/protected_session.js index ebf4b998f..6b351320c 100644 --- a/src/services/protected_session.js +++ b/src/services/protected_session.js @@ -1,6 +1,7 @@ "use strict"; const utils = require('./utils'); +const log = require('./log'); const dataEncryptionService = require('./data_encryption'); const cls = require('./cls'); @@ -35,11 +36,16 @@ function isProtectedSessionAvailable() { } function decryptNotes(notes) { - for (const note of notes) { - if (note.isProtected) { - note.title = decryptString(note.title); + try { + for (const note of notes) { + if (note.isProtected) { + note.title = decryptString(note.title); + } } } + catch (e) { + log.error(`Could not decrypt protected notes: ${e.message} ${e.stack}`); + } } function encrypt(plainText) { From 6710476768a00e825705bf9782e0ca775f494614 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 25 Sep 2020 23:52:24 +0200 Subject: [PATCH 2/5] new saved search UI wip --- src/public/app/widgets/attribute_list.js | 26 ++--- src/public/app/widgets/similar_notes.js | 44 +------- src/public/app/widgets/type_widgets/search.js | 104 ++++++++++++++++-- src/public/stylesheets/style.css | 33 ++++++ 4 files changed, 148 insertions(+), 59 deletions(-) diff --git a/src/public/app/widgets/attribute_list.js b/src/public/app/widgets/attribute_list.js index 0999ff4f2..bdce31ffe 100644 --- a/src/public/app/widgets/attribute_list.js +++ b/src/public/app/widgets/attribute_list.js @@ -30,7 +30,7 @@ const TPL = ` border-color: red !important; } - .attr-expander { + .area-expander { display: flex; flex-direction: row; color: var(--muted-text-color); @@ -47,29 +47,29 @@ const TPL = ` margin-bottom: 0; } - .attr-expander-text { + .area-expander-text { padding-left: 20px; padding-right: 20px; white-space: nowrap; } - .attr-expander:hover { + .area-expander:hover { cursor: pointer; } - .attr-expander:hover hr { + .area-expander:hover hr { border-color: var(--main-text-color); } - .attr-expander:hover .attr-expander-text { + .area-expander:hover .area-expander-text { color: var(--main-text-color); } -
+

-
Promoted attributes
+
Promoted attributes

@@ -77,10 +77,10 @@ const TPL = `
-
+

-
+

@@ -90,10 +90,10 @@ const TPL = `
-
+

-
+

@@ -141,7 +141,7 @@ export default class AttributeListWidget extends TabAwareWidget { this.triggerEvent(`attributeListCollapsedStateChanged`, {collapse}); }); - this.$ownedExpanderText = this.$ownedExpander.find('.attr-expander-text'); + this.$ownedExpanderText = this.$ownedExpander.find('.area-expander-text'); this.$inheritedAttributesWrapper = this.$widget.find('.inherited-attributes-wrapper'); @@ -155,7 +155,7 @@ export default class AttributeListWidget extends TabAwareWidget { } }); - this.$inheritedExpanderText = this.$inheritedExpander.find('.attr-expander-text'); + this.$inheritedExpanderText = this.$inheritedExpander.find('.area-expander-text'); this.$inheritedEmptyExpander = this.$widget.find('.attr-inherited-empty-expander'); diff --git a/src/public/app/widgets/similar_notes.js b/src/public/app/widgets/similar_notes.js index 019c21aa1..23aa672a2 100644 --- a/src/public/app/widgets/similar_notes.js +++ b/src/public/app/widgets/similar_notes.js @@ -24,46 +24,12 @@ const TPL = ` white-space: nowrap; overflow: hidden; } - - .similar-notes-expander { - display: flex; - flex-direction: row; - color: var(--muted-text-color); - font-size: 90%; - m - } - - .similar-notes-expander hr { - height: 1px; - border-color: var(--main-border-color); - position: relative; - top: 4px; - margin-top: 5px; - } - - .similar-notes-expander-text { - padding-left: 20px; - padding-right: 20px; - white-space: nowrap; - } - - .similar-notes-expander:hover { - cursor: pointer; - } - - .similar-notes-expander:hover hr { - border-color: var(--main-text-color); - } - - .similar-notes-expander:hover .similar-notes-expander-text { - color: var(--main-text-color); - } -
+

-

@@ -83,9 +49,9 @@ export default class SimilarNotesWidget extends TabAwareWidget { this.overflowing(); this.$similarNotesWrapper = this.$widget.find(".similar-notes-wrapper"); - this.$similarNotesExpanderText = this.$widget.find(".similar-notes-expander-text"); + this.$expanderText = this.$widget.find(".area-expander-text"); - this.$expander = this.$widget.find('.similar-notes-expander'); + this.$expander = this.$widget.find('.area-expander'); this.$expander.on('click', async () => { const collapse = this.$similarNotesWrapper.is(":visible"); @@ -132,7 +98,7 @@ export default class SimilarNotesWidget extends TabAwareWidget { this.$similarNotesWrapper.show(); } - this.$similarNotesExpanderText.text(`${similarNotes.length} similar note${similarNotes.length === 1 ? '': "s"}`); + this.$expanderText.text(`${similarNotes.length} similar note${similarNotes.length === 1 ? '': "s"}`); const noteIds = similarNotes.flatMap(note => note.notePath); diff --git a/src/public/app/widgets/type_widgets/search.js b/src/public/app/widgets/type_widgets/search.js index 7a2698c28..5ce4d1d94 100644 --- a/src/public/app/widgets/type_widgets/search.js +++ b/src/public/app/widgets/type_widgets/search.js @@ -1,15 +1,90 @@ import TypeWidget from "./type_widget.js"; +import noteAutocompleteService from "../../services/note_autocomplete.js"; const TPL = ` -