mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	fix protecting files/images
This commit is contained in:
		| @@ -56,7 +56,8 @@ function decrypt(key, cipherText, ivLength = 13) { | ||||
|         return "[protected]"; | ||||
|     } | ||||
|  | ||||
|     const cipherTextBufferWithIv = Buffer.from(cipherText, 'base64'); | ||||
|     try { | ||||
|         const cipherTextBufferWithIv = Buffer.from(cipherText.toString(), 'base64'); | ||||
|         const iv = cipherTextBufferWithIv.slice(0, ivLength); | ||||
|  | ||||
|         const cipherTextBuffer = cipherTextBufferWithIv.slice(ivLength); | ||||
| @@ -76,6 +77,18 @@ function decrypt(key, cipherText, ivLength = 13) { | ||||
|  | ||||
|         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 cipherText; | ||||
|         } | ||||
|         else { | ||||
|             throw e; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| function decryptString(dataKey, cipherText) { | ||||
|     const buffer = decrypt(dataKey, cipherText); | ||||
|   | ||||
| @@ -346,6 +346,11 @@ async function updateNote(noteId, noteUpdates) { | ||||
|  | ||||
|     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; | ||||
|  | ||||
|     note.title = noteUpdates.title; | ||||
| @@ -357,6 +362,9 @@ async function updateNote(noteId, noteUpdates) { | ||||
|  | ||||
|         await note.setContent(noteUpdates.content); | ||||
|     } | ||||
|     else if (noteUpdates.content) { | ||||
|         await note.setContent(noteUpdates.content); | ||||
|     } | ||||
|  | ||||
|     if (noteTitleChanged) { | ||||
|         await triggerNoteTitleChanged(note); | ||||
|   | ||||
| @@ -59,7 +59,7 @@ function decryptNote(note) { | ||||
| function decryptNoteContent(note) { | ||||
|     try { | ||||
|         if (note.content != null) { | ||||
|             note.content = dataEncryptionService.decrypt(getDataKey(), note.content.toString()); | ||||
|             note.content = dataEncryptionService.decrypt(getDataKey(), note.content); | ||||
|         } | ||||
|     } | ||||
|     catch (e) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user