server side encryption WIP

This commit is contained in:
azivner
2017-11-12 21:40:26 -05:00
parent ec49bf0cca
commit 50b789fc39
5 changed files with 12 additions and 84 deletions

View File

@@ -7,6 +7,8 @@ const sql = require('../../services/sql');
const options = require('../../services/options');
const utils = require('../../services/utils');
const notes = require('../../services/notes');
const protected_session = require('../../services/protected_session');
const data_encryption = require('../../services/data_encryption');
router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => {
let noteId = req.params.noteId;
@@ -20,6 +22,13 @@ router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => {
detail = sql.getSingleResult("select * from notes where note_id = ?", [noteId]);
}
if (detail.encryption > 0) {
const dataKey = protected_session.getDataKey(req);
detail.note_title = data_encryption.decrypt(dataKey, detail.note_title);
detail.note_text = data_encryption.decrypt(dataKey, detail.note_text);
}
res.send({
detail: detail,
images: await sql.getResults("select * from images where note_id = ? order by note_offset", [noteId]),