mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 19:49:01 +01:00 
			
		
		
		
	fix encrypting new notes
This commit is contained in:
		
							parent
							
								
									4721ddc6b3
								
							
						
					
					
						commit
						174d4e67af
					
				| @ -17,9 +17,7 @@ class Entity { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     beforeSaving() { |     beforeSaving() { | ||||||
|         if (!this[this.constructor.primaryKeyName]) { |         this.generateIdIfNecessary(); | ||||||
|             this[this.constructor.primaryKeyName] = utils.newEntityId(); |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         const origHash = this.hash; |         const origHash = this.hash; | ||||||
| 
 | 
 | ||||||
| @ -28,6 +26,12 @@ class Entity { | |||||||
|         this.isChanged = origHash !== this.hash; |         this.isChanged = origHash !== this.hash; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     generateIdIfNecessary() { | ||||||
|  |         if (!this[this.constructor.primaryKeyName]) { | ||||||
|  |             this[this.constructor.primaryKeyName] = utils.newEntityId(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     generateHash() { |     generateHash() { | ||||||
|         let contentToHash = ""; |         let contentToHash = ""; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -513,6 +513,9 @@ class Note extends Entity { | |||||||
|             this.content = JSON.stringify(this.jsonContent, null, '\t'); |             this.content = JSON.stringify(this.jsonContent, null, '\t'); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         // we do this here because encryption needs the note ID for the IV
 | ||||||
|  |         this.generateIdIfNecessary(); | ||||||
|  | 
 | ||||||
|         if (this.isProtected) { |         if (this.isProtected) { | ||||||
|             protectedSessionService.encryptNote(this); |             protectedSessionService.encryptNote(this); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -84,7 +84,7 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         catch (e) { |         catch (e) { | ||||||
|             log.info(`${method} ${path} threw exception: ` + e.stack); |             log.error(`${method} ${path} threw exception: ` + e.stack); | ||||||
| 
 | 
 | ||||||
|             res.sendStatus(500); |             res.sendStatus(500); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -85,10 +85,18 @@ function decryptString(dataKey, iv, cipherText) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function noteTitleIv(iv) { | function noteTitleIv(iv) { | ||||||
|  |     if (!iv) { | ||||||
|  |         throw new Error("Empty iv!"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     return "0" + iv; |     return "0" + iv; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function noteContentIv(iv) { | function noteContentIv(iv) { | ||||||
|  |     if (!iv) { | ||||||
|  |         throw new Error("Empty iv!"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     return "1" + iv; |     return "1" + iv; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner