From 5a64eed1ddc828ca7d9ef945cc5f0fae1500206b Mon Sep 17 00:00:00 2001 From: azivner Date: Wed, 6 Sep 2017 21:56:06 -0400 Subject: [PATCH] encryption key has now limited time to live if not used for 10 minutes --- static/js/note.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/static/js/note.js b/static/js/note.js index 77bcf525d..d44fcf436 100644 --- a/static/js/note.js +++ b/static/js/note.js @@ -290,7 +290,11 @@ function deriveEncryptionKey(password) { }); } +// currently not configurable +const globalEncryptionKeyTimeToLive = 10 * 60 * 1000; // in milliseconds + let globalEncryptionKey = null; +let globalLastEncryptionOperationDate = null; $("#encryptionPasswordForm").submit(function() { const password = $("#encryptionPassword").val(); @@ -313,6 +317,18 @@ $("#encryptionPasswordForm").submit(function() { }); function getAes() { + globalLastEncryptionOperationDate = new Date(); + + setTimeout(function() { + if (new Date().getTime() - globalLastEncryptionOperationDate.getTime() > globalEncryptionKeyTimeToLive) { + globalEncryptionKey = null; + + if (globalNote.detail.encryption > 0) { + loadNote(globalNote.detail.note_id); + } + } + }, globalEncryptionKeyTimeToLive + 1000); + return new aesjs.ModeOfOperation.ctr(globalEncryptionKey, new aesjs.Counter(5)); }