aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md6
-rw-r--r--TODO.md8
-rwxr-xr-xanypinentry153
3 files changed, 167 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e5d2b58
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+# AnyPinentry
+AnyPinentry is a wrapping interface to all kinds of prompts instead of gnupg's pinentry.
+You can now use any interface for password and confirmation prompts (`dmenu`, `rofi`, `read`, `systemd-ask-password`, `curses`, `etc`).
+
+WIP
+
diff --git a/TODO.md b/TODO.md
new file mode 100644
index 0000000..4984790
--- /dev/null
+++ b/TODO.md
@@ -0,0 +1,8 @@
+# TODO
+ - [X] Cli arg to set password prompt command
+ - [X] Cli arg to set confirmation prompt command
+ - [X] Add confirmation command
+ - [X] Add repeat password support
+ - [ ] Repeat error action
+ - [ ] Use text that is provided as commands
+ - [ ] Clear password support?
diff --git a/anypinentry b/anypinentry
new file mode 100755
index 0000000..f550be1
--- /dev/null
+++ b/anypinentry
@@ -0,0 +1,153 @@
+#!/usr/bin/env bash
+
+VERSION="0.0";
+
+if [[ -z "$DISPLAY" ]]; then
+ DISPLAY=":1";
+ export DISPLAY;
+fi
+
+title="";
+prompt_string="Password :: ";
+description="";
+keyinfo="";
+repeat="";
+
+error__password_mismatch="Passwords don't match";
+AP_YES="Yes";
+AP_NO="No";
+
+prompt_action='dmenu -P -p "$AP_PROMPT"';
+confirm_action='echo -e "$AP_YES\n$AP_NO" | dmenu -p "$AP_PROMPT"';
+display_error_action='notify-send -a "Pinentry" "$AP_ERROR"';
+
+# :: Prompt string (default if empty)
+ask_password() {
+ export AP_PROMPT="${1:-"$prompt_string"}";
+ echo -n '' | bash -c "$prompt_action" 2> /dev/null;
+}
+# :: Prompt string (default if empty)
+confirm() {
+ export AP_PROMPT="${1:-"$prompt_string"}";
+ export AP_YES; export AP_NO;
+ echo -n '' | bash -c "$confirm_action" 2> /dev/null;
+}
+# :: Error text
+show_error() {
+ export AP_ERROR="$1";
+ bash -c "$display_error_action" 2> /dev/null;
+}
+
+cancelled_error() { echo "ERR 99 Operation cancelled <Unspecified source>"; }
+com_error() { echo "ERR 99 Operation cancelled <Unspecified source>"; }
+
+
+
+
+save_option() {
+ echo "OK";
+}
+
+get_info() {
+ case "$1" in
+ version) echo "D $VERSION" && echo "OK" ;;
+ pid) echo "D $BASHPID" && echo "OK" ;;
+ *) com_error ;;
+ esac;
+}
+
+# :: Repeat string -> Password -> OK | ERR
+password_prompt() {
+ local pass="";
+ if pass=$(ask_password "$([[ -z "$1" ]] && echo "$repeat")"); then
+ if [[ ! -z "$1" ]]; then
+ password_prompt "" "$pass";
+ else
+ # If password repeat attempt failed, try again,
+ # Else continue
+ if [[ ! -z "$2" ]] && [[ "$pass" != "$2" ]]; then
+ show_error "$error__password_mismatch";
+ password_prompt "$repeat";
+ else
+ [[ ! -z "$pass" ]] && echo "D $pass";
+ echo "OK";
+ fi;
+ fi;
+ else
+ cancelled_error;
+ fi;
+}
+
+# :: OK | ERR
+confirm_prompt() {
+ local res=$(confirm);
+ [[ "$res" == "$AP_YES" ]] && echo "OK" || cancelled_error;
+}
+
+interpret_command() {
+ cmd="$(echo "$1" | cut -d' ' -f1)";
+ data="$(echo "$1" | cut -d' ' -f2-)";
+
+ # Case insensitive search
+ case "${cmd^^}" in
+ INIT) echo "OK Pleased to meet you" ;;
+ OPTION) save_option "$data" ;;
+ GETINFO) get_info "$data" ;;
+ SETTITLE) title="$data" && echo "OK" ;;
+ SETPROMPT) prompt_string="$data" && echo "OK" ;;
+ SETKEYINFO) keyinfo="$data" && echo "OK" ;;
+ SETREPEAT) repeat="${data:-"repeat"}" && echo "OK" ;;
+ SETDESC) description="$data" && echo "OK" ;;
+ SETREPEATERROR) error__password_mismatch="$data" && echo "OK" ;;
+ CONFIRM) confirm_prompt ;;
+ GETPIN) password_prompt "$repeat" "" ;;
+ BYE) echo "OK closing connection" && exit 0 ;;
+ *) echo "OK" ;;
+ esac;
+}
+
+
+
+
+help() {
+ echo "Usage: $0 [-D DISPLAY] [--prompt script] [--confirm script] [-hv]";
+}
+
+parse_cliargs() {
+ [[ $# -le 0 ]] && return 0;
+
+ case "$1" in
+ -D|--display) export DISPLAY="$2"; shift 1 ;;
+ --error-command) display_error_action="$2"; shift 1 ;;
+ --prompt) prompt_action="$2"; shift 1 ;;
+ --confirm) confirm_action="$2"; shift 1 ;;
+ -v|--version) echo "anypinentry-$VERSION" && exit 0 ;;
+ -h|--help) help && exit 0 ;;
+ *) help && exit 1 ;;
+ esac;
+
+ shift 1;
+ parse_cliargs "$@";
+}
+
+
+
+# Main
+parse_cliargs "$@";
+
+interpret_command "INIT";
+
+while read line; do
+ interpret_command "$line";
+done;
+
+# "SETERROR"
+# "SETOK"
+# "SETNOTOK"
+# "SETCANCEL"
+# "MESSAGE"
+# "SETQUALITYBAR"
+# "SETQUALITYBAR_TT"
+# "SETTIMEOUT"
+# "CLEARPASSPHRASE"
+