]> git.proxmox.com Git - proxmox-backup.git/commitdiff
cleanup: KeyConfig::decrypt - show password hint on error
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 21 Jan 2021 06:13:56 +0000 (07:13 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 21 Jan 2021 09:31:49 +0000 (10:31 +0100)
src/api2/tape/drive.rs
src/backup/key_derivation.rs

index 016e3092a1dbcac711a37df705f0e33684ea3e71..d7a87480079a112ec63b2858ccee7fc6999ba96c 100644 (file)
@@ -484,19 +484,7 @@ pub async fn restore_key(
 
         if let Some(key_config) = key_config {
             let password_fn = || { Ok(password.as_bytes().to_vec()) };
-            let key = match key_config.decrypt(&password_fn) {
-                Ok((key, ..)) => key,
-                Err(_) => {
-                    match key_config.hint {
-                        Some(hint) => {
-                            bail!("decrypt key failed (password hint: {})", hint);
-                        }
-                        None => {
-                            bail!("decrypt key failed (wrong password)");
-                        }
-                    }
-                }
-            };
+            let (key, ..) = key_config.decrypt(&password_fn)?;
             config::tape_encryption_keys::insert_key(key, key_config)?;
         } else {
             bail!("media does not contain any encryption key configuration");
index 065a527e01bc6e086710c44c174ffb2586553b85..0b561b07d5dadae1be1558fe2ba8e373a96500a5 100644 (file)
@@ -216,7 +216,7 @@ impl KeyConfig  {
             let derived_key = kdf.derive_key(&passphrase)?;
 
             if raw_data.len() < 32 {
-                bail!("Unable to encode key - short data");
+                bail!("Unable to decrypt key - short data");
             }
             let iv = &raw_data[0..16];
             let tag = &raw_data[16..32];
@@ -231,7 +231,16 @@ impl KeyConfig  {
                 b"",
                 &enc_data,
                 &tag,
-            ).map_err(|err| format_err!("Unable to decrypt key (wrong password?) - {}", err))?
+            ).map_err(|err| {
+                match self.hint {
+                    Some(ref hint) => {
+                        format_err!("Unable to decrypt key (password hint: {})", hint)
+                    }
+                    None => {
+                        format_err!("Unable to decrypt key (wrong password?) - {}", err)
+                    }
+                }
+            })?
 
         } else {
             raw_data.clone()