From 4e67477c6bf61668a91a6d2f8fba9a1ebb7400c9 Mon Sep 17 00:00:00 2001 From: louib Date: Mon, 22 Jan 2024 20:51:24 -0500 Subject: [PATCH] feat: allow empty passwords for yk utilities --- src/bin/kp-yk-add.rs | 12 +++++++++++- src/bin/kp-yk-recover.rs | 12 +++++++++++- src/bin/kp-yk-remove.rs | 12 +++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/bin/kp-yk-add.rs b/src/bin/kp-yk-add.rs index 637756ca..77913734 100644 --- a/src/bin/kp-yk-add.rs +++ b/src/bin/kp-yk-add.rs @@ -25,6 +25,10 @@ struct Args { /// Provide a keyfile #[arg(short = 'k', long)] keyfile: Option, + + /// Do not use a password to decrypt the database + #[arg(long)] + no_password: bool, } pub fn main() -> Result<()> { @@ -37,7 +41,13 @@ pub fn main() -> Result<()> { key = key.with_keyfile(&mut File::open(f)?)?; } - key = key.with_password_from_prompt("Password (or blank for none): ")?; + if !args.no_password { + key = key.with_password_from_prompt("Password: ")?; + } + + if key.is_empty() { + return Err(anyhow::format_err!("No database key was provided.")); + } let db = Database::open(&mut source, key.clone())?; diff --git a/src/bin/kp-yk-recover.rs b/src/bin/kp-yk-recover.rs index 6b35059f..45188386 100644 --- a/src/bin/kp-yk-recover.rs +++ b/src/bin/kp-yk-recover.rs @@ -18,6 +18,10 @@ struct Args { /// Provide a keyfile #[arg(short = 'k', long)] keyfile: Option, + + /// Do not use a password to decrypt the database + #[arg(long)] + no_password: bool, } pub fn main() -> Result<()> { @@ -30,7 +34,13 @@ pub fn main() -> Result<()> { key = key.with_keyfile(&mut File::open(f)?)?; } - key = key.with_password_from_prompt("Password (or blank for none): ")?; + if !args.no_password { + key = key.with_password_from_prompt("Password: ")?; + } + + if key.is_empty() { + return Err(anyhow::format_err!("No database key was provided.")); + } let key_without_yubikey = key.clone(); diff --git a/src/bin/kp-yk-remove.rs b/src/bin/kp-yk-remove.rs index 4f4965dc..1a2776d6 100644 --- a/src/bin/kp-yk-remove.rs +++ b/src/bin/kp-yk-remove.rs @@ -25,6 +25,10 @@ struct Args { /// Provide a keyfile #[arg(short = 'k', long)] keyfile: Option, + + /// Do not use a password to decrypt the database + #[arg(long)] + no_password: bool, } pub fn main() -> Result<()> { @@ -37,7 +41,13 @@ pub fn main() -> Result<()> { key = key.with_keyfile(&mut File::open(f)?)?; } - key = key.with_password_from_prompt("Password (or blank for none): ")?; + if !args.no_password { + key = key.with_password_from_prompt("Password: ")?; + } + + if key.is_empty() { + return Err(anyhow::format_err!("No database key was provided.")); + } let key_without_yubikey = key.clone();