diff --git a/Cargo.lock b/Cargo.lock index d86c2fc..6c681c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -520,6 +520,16 @@ version = "0.6.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" +[[package]] +name = "rpassword" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b763cb66df1c928432cc35053f8bd4cec3335d8559fc16010017d16b3c1680" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "rustcryptfs" version = "0.0.1" @@ -528,6 +538,7 @@ dependencies = [ "clap", "env_logger", "log", + "rpassword", "rustcryptfs-lib", "rustcryptfs-linux", "serde", diff --git a/rustcryptfs/Cargo.toml b/rustcryptfs/Cargo.toml index 4445f85..189b0bb 100644 --- a/rustcryptfs/Cargo.toml +++ b/rustcryptfs/Cargo.toml @@ -13,6 +13,7 @@ clap = { version = "3.1.18", features = ["derive"] } log = "0.4.17" rustcryptfs-lib = { path = "../rustcryptfs-lib" } env_logger = "0.9.0" +rpassword = "7.0.0" [target.'cfg(target_os = "linux")'.dependencies] rustcryptfs-linux = { path = "../rustcryptfs-linux" } diff --git a/rustcryptfs/src/main.rs b/rustcryptfs/src/main.rs index 86f6c46..a4660f9 100644 --- a/rustcryptfs/src/main.rs +++ b/rustcryptfs/src/main.rs @@ -26,12 +26,18 @@ fn main() -> anyhow::Result<()> { fn ls(c: &LsCommand) -> anyhow::Result<()> { let folder_path = Path::new(&c.folder_path); + let password = if let Some(password) = &c.password { + password.clone() + } else { + rpassword::prompt_password("Your password: ")? + }; + let fs = GocryptFs::open( c.gocryptfs_path .as_ref() .map(|p| Path::new(p)) .unwrap_or(folder_path), - c.password.as_ref().expect("Please input a password"), + &password, )?; let filename_decoder = fs.filename_decoder(); @@ -66,12 +72,19 @@ fn ls(c: &LsCommand) -> anyhow::Result<()> { fn decrypt_file(c: &DecryptCommand) -> anyhow::Result<()> { let file_path = Path::new(&c.file_path); + + let password = if let Some(password) = &c.password { + password.clone() + } else { + rpassword::prompt_password("Your password: ")? + }; + let fs = GocryptFs::open( c.gocryptfs_path .as_ref() .map(|p| Path::new(p)) .unwrap_or_else(|| file_path.parent().unwrap()), - c.password.as_ref().expect("Please input a password"), + &password, )?; let mut file = File::open(file_path).unwrap(); @@ -108,7 +121,13 @@ fn decrypt_file(c: &DecryptCommand) -> anyhow::Result<()> { fn mount(mount: &MountCommand) -> anyhow::Result<()> { use rustcryptfs_linux::EncryptedFs; - let fs = EncryptedFs::new(&mount.path, mount.password.as_ref().unwrap())?; + let password = if let Some(password) = &mount.password { + password.clone() + } else { + rpassword::prompt_password("Your password: ")? + }; + + let fs = EncryptedFs::new(&mount.path, &password)?; fs.mount(&mount.mountpoint); Ok(())