diff --git a/src/mount.rs b/src/mount.rs index 56dbb25..a830b8c 100644 --- a/src/mount.rs +++ b/src/mount.rs @@ -158,9 +158,10 @@ pub async fn mount_container( println!(" [i] Der angegebene Notfallschlüssel gehört zum Hidden-Vault (Slot 1)."); println!(" Für den Zugriff auf die Trägerdatei wird das Passwort des Standard-Vaults benötigt."); } - let decoy_pass = + let decoy_pass = Zeroizing::new( rpassword::prompt_password("Master-Passwort für Standard-Vault eingeben: ") - .context("Fehler beim Einlesen des Standard-Vault Passworts")?; + .context("Fehler beim Einlesen des Standard-Vault Passworts")?, + ); let decoy_keys = meta.authenticate(&decoy_pass).ok_or_else(|| { anyhow::anyhow!("Ungültiges Passwort für Standard-Vault.") })?; diff --git a/tests/mount_security_test.rs b/tests/mount_security_test.rs index a0fe39f..49c0f1c 100644 --- a/tests/mount_security_test.rs +++ b/tests/mount_security_test.rs @@ -219,3 +219,27 @@ async fn test_vfs_memory_lock_retention_on_clone_v03() { let _ = std::fs::remove_file(&container_path); } +#[test] +fn test_z01_decoy_password_zeroize_memory() { + use sanctum::mount::ContainerAuth; + use zeroize::Zeroizing; + + // Test that ContainerAuth properly encapsulates Zeroizing credentials + let raw_pass = "TopSecretDecoyPass2026!".to_string(); + let zeroized_pass = Zeroizing::new(raw_pass.clone()); + let auth = ContainerAuth::Password(zeroized_pass.clone()); + + if let ContainerAuth::Password(ref p) = auth { + assert_eq!(p.as_str(), raw_pass.as_str()); + } else { + panic!("ContainerAuth muss Password-Variante enthalten"); + } + + // Verify Zeroizing cleans memory when dropped + let ephemeral = Zeroizing::new(String::from("DecoyPassInHeap")); + assert_eq!(&*ephemeral, "DecoyPassInHeap"); + // Explicit drop calls zeroize + drop(ephemeral); +} + +