From 4721ddc6b3bb8387ec8a08bba0be819952ff4bcb Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 27 Aug 2018 21:58:02 +0200 Subject: [PATCH] exceptions on decryption --- src/services/protected_session.js | 42 +++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/services/protected_session.js b/src/services/protected_session.js index 6a796e5b2..c698553b8 100644 --- a/src/services/protected_session.js +++ b/src/services/protected_session.js @@ -37,9 +37,15 @@ function isProtectedSessionAvailable() { function decryptNoteTitle(noteId, encryptedTitle) { const dataKey = getDataKey(); - const iv = dataEncryptionService.noteTitleIv(noteId); + try { + const iv = dataEncryptionService.noteTitleIv(noteId); - return dataEncryptionService.decryptString(dataKey, iv, encryptedTitle); + return dataEncryptionService.decryptString(dataKey, iv, encryptedTitle); + } + catch (e) { + e.message = `Cannot decrypt note title for noteId=${noteId}: ` + e.message; + throw e; + } } function decryptNote(note) { @@ -49,25 +55,29 @@ function decryptNote(note) { return; } - if (note.title) { - note.title = dataEncryptionService.decryptString(dataKey, dataEncryptionService.noteTitleIv(note.noteId), note.title); + try { + if (note.title) { + note.title = dataEncryptionService.decryptString(dataKey, dataEncryptionService.noteTitleIv(note.noteId), note.title); + } + + if (note.content) { + const contentIv = dataEncryptionService.noteContentIv(note.noteId); + + if (note.type === 'file') { + note.content = dataEncryptionService.decrypt(dataKey, contentIv, note.content); + } + else { + note.content = dataEncryptionService.decryptString(dataKey, contentIv, note.content); + } + } } - - if (note.content) { - const contentIv = dataEncryptionService.noteContentIv(note.noteId); - - if (note.type === 'file') { - note.content = dataEncryptionService.decrypt(dataKey, contentIv, note.content); - } - else { - note.content = dataEncryptionService.decryptString(dataKey, contentIv, note.content); - } + catch (e) { + e.message = `Cannot decrypt note for noteId=${note.noteId}: ` + e.message; + throw e; } } function decryptNotes(notes) { - const dataKey = getDataKey(); - for (const note of notes) { decryptNote(note); }