Prompt password
This commit is contained in:
parent
b5fbdb6fb0
commit
665cdd8b37
|
@ -520,6 +520,16 @@ version = "0.6.26"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
|
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]]
|
[[package]]
|
||||||
name = "rustcryptfs"
|
name = "rustcryptfs"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
|
@ -528,6 +538,7 @@ dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"log",
|
"log",
|
||||||
|
"rpassword",
|
||||||
"rustcryptfs-lib",
|
"rustcryptfs-lib",
|
||||||
"rustcryptfs-linux",
|
"rustcryptfs-linux",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -13,6 +13,7 @@ clap = { version = "3.1.18", features = ["derive"] }
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
rustcryptfs-lib = { path = "../rustcryptfs-lib" }
|
rustcryptfs-lib = { path = "../rustcryptfs-lib" }
|
||||||
env_logger = "0.9.0"
|
env_logger = "0.9.0"
|
||||||
|
rpassword = "7.0.0"
|
||||||
|
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
rustcryptfs-linux = { path = "../rustcryptfs-linux" }
|
rustcryptfs-linux = { path = "../rustcryptfs-linux" }
|
||||||
|
|
|
@ -26,12 +26,18 @@ fn main() -> anyhow::Result<()> {
|
||||||
fn ls(c: &LsCommand) -> anyhow::Result<()> {
|
fn ls(c: &LsCommand) -> anyhow::Result<()> {
|
||||||
let folder_path = Path::new(&c.folder_path);
|
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(
|
let fs = GocryptFs::open(
|
||||||
c.gocryptfs_path
|
c.gocryptfs_path
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|p| Path::new(p))
|
.map(|p| Path::new(p))
|
||||||
.unwrap_or(folder_path),
|
.unwrap_or(folder_path),
|
||||||
c.password.as_ref().expect("Please input a password"),
|
&password,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let filename_decoder = fs.filename_decoder();
|
let filename_decoder = fs.filename_decoder();
|
||||||
|
@ -66,12 +72,19 @@ fn ls(c: &LsCommand) -> anyhow::Result<()> {
|
||||||
|
|
||||||
fn decrypt_file(c: &DecryptCommand) -> anyhow::Result<()> {
|
fn decrypt_file(c: &DecryptCommand) -> anyhow::Result<()> {
|
||||||
let file_path = Path::new(&c.file_path);
|
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(
|
let fs = GocryptFs::open(
|
||||||
c.gocryptfs_path
|
c.gocryptfs_path
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|p| Path::new(p))
|
.map(|p| Path::new(p))
|
||||||
.unwrap_or_else(|| file_path.parent().unwrap()),
|
.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();
|
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<()> {
|
fn mount(mount: &MountCommand) -> anyhow::Result<()> {
|
||||||
use rustcryptfs_linux::EncryptedFs;
|
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);
|
fs.mount(&mount.mountpoint);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue