From 2318d615bbe399d3791b0dc42ba21add003c1cc0 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 3 Apr 2021 21:48:16 +0200 Subject: [PATCH] make note cache decryption more robust - one failure will not crash the whole process, #1810 --- src/entities/note.js | 7 ++++++- src/services/note_cache/entities/note.js | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/entities/note.js b/src/entities/note.js index 78173c582..07fcd644d 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -49,7 +49,12 @@ class Note extends Entity { this.isContentAvailable = protectedSessionService.isProtectedSessionAvailable(); if (this.isContentAvailable) { - this.title = protectedSessionService.decryptString(this.title); + try { + this.title = protectedSessionService.decryptString(this.title); + } + catch (e) { + throw new Error(`Could not decrypt title of note ${this.noteId}: ${e.message} ${e.stack}`) + } } else { this.title = "[protected]"; diff --git a/src/services/note_cache/entities/note.js b/src/services/note_cache/entities/note.js index 3adef3148..30831ebdb 100644 --- a/src/services/note_cache/entities/note.js +++ b/src/services/note_cache/entities/note.js @@ -1,6 +1,7 @@ "use strict"; const protectedSessionService = require('../../protected_session'); +const log = require('../../log'); class Note { constructor(noteCache, row) { @@ -416,9 +417,14 @@ class Note { decrypt() { if (this.isProtected && !this.isDecrypted && protectedSessionService.isProtectedSessionAvailable()) { - this.title = protectedSessionService.decryptString(this.title); + try { + this.title = protectedSessionService.decryptString(this.title); - this.isDecrypted = true; + this.isDecrypted = true; + } + catch (e) { + log.error(`Could not decrypt note ${this.noteId}: ${e.message} ${e.stack}`); + } } }