From 0ab35cdcdcb003a29d2488f4fda22d06e6e8a187 Mon Sep 17 00:00:00 2001 From: Moviuro Date: Sun, 12 Nov 2017 15:28:36 +0100 Subject: rofi-pass: first integration of pass-otp(1) --- rofi-pass | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/rofi-pass b/rofi-pass index 0f3edc2..a2d173c 100755 --- a/rofi-pass +++ b/rofi-pass @@ -318,14 +318,22 @@ mainMenu () { mapfile -t password_temp < <(PASSWORD_STORE_DIR="${root}" pass "${pass_file}") password=${password_temp[0]} fi - fields=$(printf '%s\n' "${password_temp[@]:1}" | awk '$1 ~ /:$/{$1=$1;print}') + fields=$(printf '%s\n' "${password_temp[@]:1}" | awk '$1 ~ /:$/ || /otpauth:\/\// {$1=$1;print}') declare -A stuff stuff["pass"]=${password} if [[ -n $fields ]]; then while read -r LINE; do - _id="${LINE%%: *}" - _val="${LINE#* }" + case "$LINE" in + "otpauth://"*) + _id="OTP" + _val="$(PASSWORD_STORE_DIR="${root}" pass otp "$selected_password")" + ;; + *) + _id="${LINE%%: *}" + _val="${LINE#* }" + ;; + esac stuff["${_id}"]=${_val} done < <(printf '%s\n' "${fields}") if test "${stuff['autotype']+autotype}" -- cgit From 82215fe119597a159d0141c8143aabcd1613243a Mon Sep 17 00:00:00 2001 From: Moviuro Date: Sun, 12 Nov 2017 15:43:26 +0100 Subject: rofi-pass: now, we only use pass-otp(1) when we type the OTP This prevents: * increasing the counter for HOTP * generating a TOTP too far in the past --- rofi-pass | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rofi-pass b/rofi-pass index a2d173c..db6aded 100755 --- a/rofi-pass +++ b/rofi-pass @@ -143,14 +143,21 @@ typePass () { typeField () { checkIfPass + local to_type x_repeat_enabled=$(xset q | awk '/auto repeat:/ {print $3}') xset r off - printf '%s' "${stuff[${typefield}]}" | xdotool type --clearmodifiers --file - + case $typefield in + "OTP") to_type="$(PASSWORD_STORE_DIR="${root}" pass otp "$selected_password")" ;; + *) to_type="${stuff[${typefield}]}" ;; + esac + + printf '%s' "$to_type" | xdotool type --clearmodifiers --file - xset r "$x_repeat_enabled" unset x_repeat_enabled + unset to_type clearUp } @@ -327,7 +334,7 @@ mainMenu () { case "$LINE" in "otpauth://"*) _id="OTP" - _val="$(PASSWORD_STORE_DIR="${root}" pass otp "$selected_password")" + _val="" ;; *) _id="${LINE%%: *}" -- cgit From 450f6efd081947120f6f2b603a786497f8edbd5b Mon Sep 17 00:00:00 2001 From: Moviuro Date: Wed, 29 Nov 2017 20:04:26 +0100 Subject: rofi-pass: add the ":otp" keyword to autopass() --- rofi-pass | 1 + 1 file changed, 1 insertion(+) diff --git a/rofi-pass b/rofi-pass index db6aded..56d59c7 100755 --- a/rofi-pass +++ b/rofi-pass @@ -82,6 +82,7 @@ autopass () { ":space") xdotool key space;; ":delay") sleep "${delay}";; ":enter") xdotool key Return;; + ":otp") printf '%s' "$(PASSWORD_STORE_DIR="${root}" pass otp ${selected_password})" | xdotool type --clearmodifiers --file -;; "pass") printf '%s' "${password}" | xdotool type --clearmodifiers --file -;; *) printf '%s' "${stuff[${word}]}" | xdotool type --clearmodifiers --file -;; esac -- cgit From 826683903393ea98209668ac920cb4365586ccb5 Mon Sep 17 00:00:00 2001 From: Moviuro Date: Tue, 5 Dec 2017 19:45:10 +0100 Subject: rofi-pass: introduce the otp_method field --- rofi-pass | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/rofi-pass b/rofi-pass index 56d59c7..36e8ba3 100755 --- a/rofi-pass +++ b/rofi-pass @@ -13,6 +13,7 @@ _rofi () { URL_field='url' USERNAME_field='user' AUTOTYPE_field='autotype' +OTPmethod_field='otp_method' default_autotype="user :tab pass" delay=2 @@ -82,7 +83,7 @@ autopass () { ":space") xdotool key space;; ":delay") sleep "${delay}";; ":enter") xdotool key Return;; - ":otp") printf '%s' "$(PASSWORD_STORE_DIR="${root}" pass otp ${selected_password})" | xdotool type --clearmodifiers --file -;; + ":otp") printf '%s' "$(generateOTP)" | xdotool type --clearmodifiers --file -;; "pass") printf '%s' "${password}" | xdotool type --clearmodifiers --file -;; *) printf '%s' "${stuff[${word}]}" | xdotool type --clearmodifiers --file -;; esac @@ -150,7 +151,7 @@ typeField () { xset r off case $typefield in - "OTP") to_type="$(PASSWORD_STORE_DIR="${root}" pass otp "$selected_password")" ;; + "OTP") to_type="$(generateOTP)" ;; *) to_type="${stuff[${typefield}]}" ;; esac @@ -163,6 +164,21 @@ typeField () { clearUp } +generateOTP () { + checkIfPass + + # First, we check if there is a non-conventional OTP command in the pass file + if PASSWORD_STORE_DIR="${root}" pass "$selected_password" | grep -q "${OTPmethod_field}: "; then + # We execute the commands after otp_method: AS-IS + bash -c "$(PASSWORD_STORE_DIR="${root}" pass "$selected_password" | grep "${OTPmethod_field}: " | cut -d' ' -f2-)" + else + # If there is no method defined, fallback to pass-otp + PASSWORD_STORE_DIR="${root}" pass otp "$selected_password" + fi + + clearUp +} + copyUser () { checkIfPass printf '%s' "${stuff[${USERNAME_field}]}" | doClip -- cgit From c7d4c16b0dca2c611a9951fd462529f650d99885 Mon Sep 17 00:00:00 2001 From: Moviuro Date: Tue, 5 Dec 2017 20:12:28 +0100 Subject: rofi-pass: we don't show otp_method among the fields that we can type --- rofi-pass | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rofi-pass b/rofi-pass index 36e8ba3..96e043b 100755 --- a/rofi-pass +++ b/rofi-pass @@ -348,17 +348,23 @@ mainMenu () { stuff["pass"]=${password} if [[ -n $fields ]]; then while read -r LINE; do + unset _id _val case "$LINE" in "otpauth://"*) _id="OTP" _val="" ;; + "${OTPmethod_field}"*) + # We don't show otp_method as a field that we can type + ;; *) _id="${LINE%%: *}" _val="${LINE#* }" ;; esac - stuff["${_id}"]=${_val} + if [[ -n "$_id" ]]; then + stuff["${_id}"]=${_val} + fi done < <(printf '%s\n' "${fields}") if test "${stuff['autotype']+autotype}" then -- cgit From 9b3cafc678dce43558d57ebe7164e6e330e9e0ee Mon Sep 17 00:00:00 2001 From: Moviuro Date: Tue, 5 Dec 2017 20:20:15 +0100 Subject: rofi-pass: the "OTP" field will appear in rofi when applicable * when there is an otpauth:// line * when there is an otp_method: line --- rofi-pass | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/rofi-pass b/rofi-pass index 96e043b..9c395b4 100755 --- a/rofi-pass +++ b/rofi-pass @@ -350,13 +350,10 @@ mainMenu () { while read -r LINE; do unset _id _val case "$LINE" in - "otpauth://"*) + "otpauth://"*|"${OTPmethod_field}"*) _id="OTP" _val="" ;; - "${OTPmethod_field}"*) - # We don't show otp_method as a field that we can type - ;; *) _id="${LINE%%: *}" _val="${LINE#* }" -- cgit From 856611e2f89dc71da8d10f26e18c9fa2b12474eb Mon Sep 17 00:00:00 2001 From: Moviuro Date: Tue, 5 Dec 2017 20:57:13 +0100 Subject: README.md: add documentation for OTPs --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 27c4ce9..fe1f407 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,24 @@ in a convenient way using [rofi](https://github.com/DaveDavenport/rofi). url: http://my.url.foo autotype: SomeField :tab UserName :tab AnotherField :tab pass ``` - You can use `:tab`, `:enter`, or `:space` here to type Tab, Enter, or Space (useful for toggling checkboxes) respectively. `:delay` will trigger a delay (2 seconds by default). + `:otp` will generate an OTP, either `pass-otp(1)` style, or according to the + `otp_method:`, if it is defined. +* Generating OTPs. + The format for OTPs should either be `pass-otp(1)`-compatible + ``` + [...] + otpauth://[...] + ``` + Or it should define a method for generating OTPs: + ``` + [...] + otp_method: /opt/obscure-otp-generator/oog --some-option some args + ``` + * All hotkeys are configurable in the config file * The field names for `user`, `url` and `autotype` are configurable * Bookmarks mode (open stored URLs in browser, default: Alt+x) @@ -55,6 +68,7 @@ in a convenient way using [rofi](https://github.com/DaveDavenport/rofi). * gawk * bash * pwgen +* pass-otp(1) (https://github.com/tadfisher/pass-otp) (optional: for OTPs) ### BSD -- cgit