]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/backup/crypt_config.rs - compute_digest: make it more secure
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 8 Jul 2020 10:49:21 +0000 (12:49 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 8 Jul 2020 10:53:04 +0000 (12:53 +0200)
src/backup/crypt_config.rs

index bdf936803b219a1da5b487dde776ea32f9389f88..72b56dd79da9089a29d47e58ebbb90908f92259c 100644 (file)
@@ -80,10 +80,9 @@ impl CryptConfig {
     /// chunk digest values do not clash with values computed for
     /// other sectret keys.
     pub fn compute_digest(&self, data: &[u8]) -> [u8; 32] {
-        // FIXME: use HMAC-SHA256 instead??
         let mut hasher = openssl::sha::Sha256::new();
-        hasher.update(&self.id_key);
         hasher.update(data);
+        hasher.update(&self.id_key); // at the end, to avoid length extensions attacks
         hasher.finish()
     }
 
@@ -220,7 +219,7 @@ impl CryptConfig {
         created: DateTime<Local>,
     ) -> Result<Vec<u8>, Error> {
 
-         let modified = Local.timestamp(Local::now().timestamp(), 0);
+        let modified = Local.timestamp(Local::now().timestamp(), 0);
         let key_config = super::KeyConfig { kdf: None, created, modified, data: self.enc_key.to_vec() };
         let data = serde_json::to_string(&key_config)?.as_bytes().to_vec();