autocomplete supports encrypted notes now as well

This commit is contained in:
azivner
2018-04-20 00:12:01 -04:00
parent 8c54b62f07
commit 4ce5ea9886
7 changed files with 100 additions and 35 deletions

View File

@@ -6,7 +6,7 @@ const cls = require('./cls');
const dataKeyMap = {};
function setDataKey(req, decryptedDataKey) {
function setDataKey(decryptedDataKey) {
const protectedSessionId = utils.randomSecureToken(32);
dataKeyMap[protectedSessionId] = Array.from(decryptedDataKey); // can't store buffer in session
@@ -28,12 +28,20 @@ function getDataKey() {
return dataKeyMap[protectedSessionId];
}
function isProtectedSessionAvailable(req) {
const protectedSessionId = getProtectedSessionId(req);
function isProtectedSessionAvailable() {
const protectedSessionId = getProtectedSessionId();
return !!dataKeyMap[protectedSessionId];
}
function decryptNoteTitle(noteId, encryptedTitle) {
const dataKey = getDataKey();
const iv = dataEncryptionService.noteTitleIv(noteId);
return dataEncryptionService.decryptString(dataKey, iv, encryptedTitle);
}
function decryptNote(note) {
const dataKey = getDataKey();
@@ -99,6 +107,7 @@ module.exports = {
setDataKey,
getDataKey,
isProtectedSessionAvailable,
decryptNoteTitle,
decryptNote,
decryptNotes,
decryptNoteRevision,