mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
Merge branch 'stable' into tabs
This commit is contained in:
commit
b21568806a
@ -2,7 +2,7 @@
|
|||||||
"name": "trilium",
|
"name": "trilium",
|
||||||
"productName": "Trilium Notes",
|
"productName": "Trilium Notes",
|
||||||
"description": "Trilium Notes",
|
"description": "Trilium Notes",
|
||||||
"version": "0.31.4",
|
"version": "0.31.5",
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"main": "electron.js",
|
"main": "electron.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
@ -1 +1 @@
|
|||||||
module.exports = { buildDate:"2019-05-02T22:25:48+02:00", buildRevision: "6d2eb7b187a5764b07e5bbf87b522d4141bed7e6" };
|
module.exports = { buildDate:"2019-05-04T20:25:14+02:00", buildRevision: "47d28b4eefc4f362d1ffefc205c85dab442edec1" };
|
||||||
|
@ -56,25 +56,38 @@ function decrypt(key, cipherText, ivLength = 13) {
|
|||||||
return "[protected]";
|
return "[protected]";
|
||||||
}
|
}
|
||||||
|
|
||||||
const cipherTextBufferWithIv = Buffer.from(cipherText, 'base64');
|
try {
|
||||||
const iv = cipherTextBufferWithIv.slice(0, ivLength);
|
const cipherTextBufferWithIv = Buffer.from(cipherText.toString(), 'base64');
|
||||||
|
const iv = cipherTextBufferWithIv.slice(0, ivLength);
|
||||||
|
|
||||||
const cipherTextBuffer = cipherTextBufferWithIv.slice(ivLength);
|
const cipherTextBuffer = cipherTextBufferWithIv.slice(ivLength);
|
||||||
|
|
||||||
const decipher = crypto.createDecipheriv('aes-128-cbc', pad(key), pad(iv));
|
const decipher = crypto.createDecipheriv('aes-128-cbc', pad(key), pad(iv));
|
||||||
|
|
||||||
const decryptedBytes = Buffer.concat([decipher.update(cipherTextBuffer), decipher.final()]);
|
const decryptedBytes = Buffer.concat([decipher.update(cipherTextBuffer), decipher.final()]);
|
||||||
|
|
||||||
const digest = decryptedBytes.slice(0, 4);
|
const digest = decryptedBytes.slice(0, 4);
|
||||||
const payload = decryptedBytes.slice(4);
|
const payload = decryptedBytes.slice(4);
|
||||||
|
|
||||||
const computedDigest = shaArray(payload).slice(0, 4);
|
const computedDigest = shaArray(payload).slice(0, 4);
|
||||||
|
|
||||||
if (!arraysIdentical(digest, computedDigest)) {
|
if (!arraysIdentical(digest, computedDigest)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload;
|
||||||
}
|
}
|
||||||
|
catch (e) {
|
||||||
|
// recovery from https://github.com/zadam/trilium/issues/510
|
||||||
|
if (e.message && e.message.includes("WRONG_FINAL_BLOCK_LENGTH")) {
|
||||||
|
log.info("Caught WRONG_FINAL_BLOCK_LENGTH, returning cipherText instead");
|
||||||
|
|
||||||
return payload;
|
return cipherText;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function decryptString(dataKey, cipherText) {
|
function decryptString(dataKey, cipherText) {
|
||||||
|
@ -186,8 +186,13 @@ async function protectNoteRecursively(note, protect) {
|
|||||||
|
|
||||||
async function protectNote(note, protect) {
|
async function protectNote(note, protect) {
|
||||||
if (protect !== note.isProtected) {
|
if (protect !== note.isProtected) {
|
||||||
|
const content = await note.getContent();
|
||||||
|
|
||||||
note.isProtected = protect;
|
note.isProtected = protect;
|
||||||
|
|
||||||
|
// this will force de/encryption
|
||||||
|
await note.setContent(content);
|
||||||
|
|
||||||
await note.save();
|
await note.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,6 +346,11 @@ async function updateNote(noteId, noteUpdates) {
|
|||||||
|
|
||||||
await saveNoteRevision(note);
|
await saveNoteRevision(note);
|
||||||
|
|
||||||
|
// if protected status changed, then we need to encrypt/decrypt the content anyway
|
||||||
|
if (['file', 'image'].includes(note.type) && note.isProtected !== noteUpdates.isProtected) {
|
||||||
|
noteUpdates.content = await note.getContent();
|
||||||
|
}
|
||||||
|
|
||||||
const noteTitleChanged = note.title !== noteUpdates.title;
|
const noteTitleChanged = note.title !== noteUpdates.title;
|
||||||
|
|
||||||
note.title = noteUpdates.title;
|
note.title = noteUpdates.title;
|
||||||
@ -352,6 +362,9 @@ async function updateNote(noteId, noteUpdates) {
|
|||||||
|
|
||||||
await note.setContent(noteUpdates.content);
|
await note.setContent(noteUpdates.content);
|
||||||
}
|
}
|
||||||
|
else if (noteUpdates.content) {
|
||||||
|
await note.setContent(noteUpdates.content);
|
||||||
|
}
|
||||||
|
|
||||||
if (noteTitleChanged) {
|
if (noteTitleChanged) {
|
||||||
await triggerNoteTitleChanged(note);
|
await triggerNoteTitleChanged(note);
|
||||||
|
@ -59,7 +59,7 @@ function decryptNote(note) {
|
|||||||
function decryptNoteContent(note) {
|
function decryptNoteContent(note) {
|
||||||
try {
|
try {
|
||||||
if (note.content != null) {
|
if (note.content != null) {
|
||||||
note.content = dataEncryptionService.decrypt(getDataKey(), note.content.toString());
|
note.content = dataEncryptionService.decrypt(getDataKey(), note.content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user