mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	fixed password change (broken since migration to CBC encryption)
This commit is contained in:
		
							parent
							
								
									b96e434345
								
							
						
					
					
						commit
						c1fca4764b
					
				@ -16,12 +16,10 @@ async function changePassword(currentPassword, newPassword, req) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const newPasswordVerificationKey = utils.toBase64(await my_scrypt.getVerificationHash(newPassword));
 | 
					    const newPasswordVerificationKey = utils.toBase64(await my_scrypt.getVerificationHash(newPassword));
 | 
				
			||||||
    const newPasswordDerivedKey = await my_scrypt.getPasswordDerivedKey(newPassword);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const decryptedDataKey = await password_encryption.getDataKey(currentPassword);
 | 
					    const decryptedDataKey = await password_encryption.getDataKey(currentPassword);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await sql.doInTransaction(async () => {
 | 
					    await sql.doInTransaction(async () => {
 | 
				
			||||||
        await password_encryption.setDataKey(newPasswordDerivedKey, decryptedDataKey);
 | 
					        await password_encryption.setDataKey(newPassword, decryptedDataKey);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await options.setOption('password_verification_hash', newPasswordVerificationKey);
 | 
					        await options.setOption('password_verification_hash', newPasswordVerificationKey);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -11,14 +11,14 @@ async function verifyPassword(password) {
 | 
				
			|||||||
    return givenPasswordHash === dbPasswordHash;
 | 
					    return givenPasswordHash === dbPasswordHash;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function setDataKey(password, plainText) {
 | 
					async function setDataKey(password, plainTextDataKey) {
 | 
				
			||||||
    const passwordDerivedKey = await my_scrypt.getPasswordDerivedKey(password);
 | 
					    const passwordDerivedKey = await my_scrypt.getPasswordDerivedKey(password);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const encryptedDataKeyIv = utils.randomSecureToken(16).slice(0, 16);
 | 
					    const encryptedDataKeyIv = utils.randomSecureToken(16).slice(0, 16);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await options.setOption('encrypted_data_key_iv', encryptedDataKeyIv);
 | 
					    await options.setOption('encrypted_data_key_iv', encryptedDataKeyIv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const buffer = Buffer.from(plainText);
 | 
					    const buffer = Buffer.from(plainTextDataKey);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const newEncryptedDataKey = data_encryption.encrypt(passwordDerivedKey, encryptedDataKeyIv, buffer);
 | 
					    const newEncryptedDataKey = data_encryption.encrypt(passwordDerivedKey, encryptedDataKeyIv, buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user