Prompt password

This commit is contained in:
oupson 2022-10-06 15:55:07 +02:00
parent b5fbdb6fb0
commit 665cdd8b37
Signed by: oupson
GPG Key ID: 3BD88615552EFCB7
3 changed files with 34 additions and 3 deletions

11
Cargo.lock generated
View File

@ -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",

View File

@ -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" }

View File

@ -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(())