From 604e09e6ae098350bffe18bde26e1c62f7e88a00 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 2 Mar 2021 22:13:21 -0500 Subject: make the pinentry program configurable --- CHANGELOG.md | 4 ++++ README.md | 3 +++ src/bin/rbw-agent/actions.rs | 8 ++++++++ src/bin/rbw/commands.rs | 2 ++ src/config.rs | 7 +++++++ src/pinentry.rs | 3 ++- 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 664b165..08b6bed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Added +* You can now `rbw config set pinentry pinentry-curses` to change the pinentry + program used by `rbw` (#39, djmattyg007) + ### Changed * On Linux, the `rbw-agent` process can no longer be attached to by debuggers, diff --git a/README.md b/README.md index 0df94bc..8e30f7f 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,9 @@ configuration options: * `lock_timeout`: The number of seconds to keep the master keys in memory for before requiring the password to be entered again. Defaults to `3600` (one hour). +* `pinentry`: The + [pinentry](https://www.gnupg.org/related_software/pinentry/index.html) + executable to use. Defaults to `pinentry`. ## Usage diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs index 1a5a3c5..4f4096e 100644 --- a/src/bin/rbw-agent/actions.rs +++ b/src/bin/rbw-agent/actions.rs @@ -32,6 +32,7 @@ pub async fn login( None }; let password = rbw::pinentry::getpin( + &config_pinentry().await?, "Master Password", &format!("Log in to {}", host), err.as_deref(), @@ -134,6 +135,7 @@ async fn two_factor( None }; let code = rbw::pinentry::getpin( + &config_pinentry().await?, "Authenticator App", "Enter the 6 digit verification code from your authenticator app.", err.as_deref(), @@ -293,6 +295,7 @@ pub async fn unlock( None }; let password = rbw::pinentry::getpin( + &config_pinentry().await?, "Master Password", "Unlock the local database", err.as_deref(), @@ -532,3 +535,8 @@ async fn config_base_url() -> anyhow::Result { let config = rbw::config::Config::load_async().await?; Ok(config.base_url()) } + +async fn config_pinentry() -> anyhow::Result { + let config = rbw::config::Config::load_async().await?; + Ok(config.pinentry) +} diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index 3f11174..2da06a2 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -425,6 +425,7 @@ pub fn config_set(key: &str, value: &str) -> anyhow::Result<()> { config.lock_timeout = timeout; } } + "pinentry" => config.pinentry = value.to_string(), _ => return Err(anyhow::anyhow!("invalid config key: {}", key)), } config.save()?; @@ -449,6 +450,7 @@ pub fn config_unset(key: &str) -> anyhow::Result<()> { "lock_timeout" => { config.lock_timeout = rbw::config::default_lock_timeout() } + "pinentry" => config.pinentry = rbw::config::default_pinentry(), _ => return Err(anyhow::anyhow!("invalid config key: {}", key)), } config.save()?; diff --git a/src/config.rs b/src/config.rs index 418da45..9bb4696 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,6 +10,8 @@ pub struct Config { pub identity_url: Option, #[serde(default = "default_lock_timeout")] pub lock_timeout: u64, + #[serde(default = "default_pinentry")] + pub pinentry: String, } impl Default for Config { @@ -19,6 +21,7 @@ impl Default for Config { base_url: Default::default(), identity_url: Default::default(), lock_timeout: default_lock_timeout(), + pinentry: default_pinentry(), } } } @@ -27,6 +30,10 @@ pub fn default_lock_timeout() -> u64 { 3600 } +pub fn default_pinentry() -> String { + "pinentry".to_string() +} + impl Config { pub fn new() -> Self { Self::default() diff --git a/src/pinentry.rs b/src/pinentry.rs index 69bf92c..9711585 100644 --- a/src/pinentry.rs +++ b/src/pinentry.rs @@ -3,12 +3,13 @@ use crate::prelude::*; use tokio::io::AsyncWriteExt as _; pub async fn getpin( + pinentry: &str, prompt: &str, desc: &str, err: Option<&str>, tty: Option<&str>, ) -> Result { - let mut opts = tokio::process::Command::new("pinentry"); + let mut opts = tokio::process::Command::new(pinentry); opts.stdin(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped()); if let Some(tty) = tty { -- cgit v1.2.3-54-g00ecf