aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRasmus Steinke <rasi@xssn.at>2017-12-22 23:20:34 +0100
committerGitHub <noreply@github.com>2017-12-22 23:20:34 +0100
commit3abb5ec3240127de1cfaf92086da6f861c3bea1c (patch)
tree6f3ec6a19331de4f3e13d3ff1312e5d28eb2bafc
parentb5df582f22a75aca900ea7858a22dd39ee6ba7b1 (diff)
parent856611e2f89dc71da8d10f26e18c9fa2b12474eb (diff)
downloadrofi-pass-3abb5ec3240127de1cfaf92086da6f861c3bea1c.tar.gz
Merge pull request #101 from moviuro/otp
Integrate OTPs into rofi-pass
-rw-r--r--README.md16
-rwxr-xr-xrofi-pass45
2 files changed, 55 insertions, 6 deletions
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 <kbd>Tab</kbd>,
<kbd>Enter</kbd>, or <kbd>Space</kbd> (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
diff --git a/rofi-pass b/rofi-pass
index 0835265..2da3578 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
@@ -81,6 +82,7 @@ autopass () {
":space") xdotool key space;;
":delay") sleep "${delay}";;
":enter") xdotool key Return;;
+ ":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
@@ -142,14 +144,36 @@ 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="$(generateOTP)" ;;
+ *) 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
+}
+
+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
}
@@ -317,15 +341,26 @@ mainMenu () {
mapfile -t password_temp < <(PASSWORD_STORE_DIR="${root}" pass show "${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#* }"
- stuff["${_id}"]=${_val}
+ unset _id _val
+ case "$LINE" in
+ "otpauth://"*|"${OTPmethod_field}"*)
+ _id="OTP"
+ _val=""
+ ;;
+ *)
+ _id="${LINE%%: *}"
+ _val="${LINE#* }"
+ ;;
+ esac
+ if [[ -n "$_id" ]]; then
+ stuff["${_id}"]=${_val}
+ fi
done < <(printf '%s\n' "${fields}")
if test "${stuff['autotype']+autotype}"
then