From 27247aceda7754a8803bbc107fa9a5a08be05c02 Mon Sep 17 00:00:00 2001 From: Jeremy Brubaker Date: Fri, 10 Jun 2022 09:49:08 -0400 Subject: Implement 'RESET' command Reset everything to defaults --- anypinentry | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/anypinentry b/anypinentry index d5e1a35..e17bab0 100755 --- a/anypinentry +++ b/anypinentry @@ -8,9 +8,10 @@ if [ -z "$DISPLAY" ]; then DISPLAY=":1"; export DISPLAY; fi +prompt_string_default="PIN: " title=""; -prompt_string="PIN: "; +prompt_string="$prompt_string_default"; description=""; keyinfo=""; repeat=""; @@ -46,7 +47,17 @@ not_implemented_error() { echo "ERR 536870981 Not implemented "; } - +reset() { + description= + prompt_string="$prompt_string_default" + keyinfo= + repeat= + error__password_mismatch= + setok= + setnotok= + setcancel= + title= +} save_option() { echo "OK"; @@ -134,7 +145,7 @@ interpret_command() { OPTION) save_option "$data" ;; BYE) echo "OK closing connection"; exit 0 ;; AUTH) not_implemented_error ;; - RESET) not_implemented_error ;; + RESET) reset ;; END) not_implemented_error ;; HELP) pinentry_help ;; SETDESC) description="$data"; echo "OK" ;; -- cgit v1.3.1 From adc0321b11107c9770ccc7a522ffca4b65b1729a Mon Sep 17 00:00:00 2001 From: Jeremy Brubaker Date: Fri, 10 Jun 2022 09:50:09 -0400 Subject: Reset 'REPEAT' after completing 'GETPIN' Calling 'SETREPEAT' applies only to the next call of 'GETPIN'. Once a PIN is successfully confiremd, the next call to 'GETPIN' is *not* confirmed by default --- anypinentry | 1 + 1 file changed, 1 insertion(+) diff --git a/anypinentry b/anypinentry index e17bab0..0742281 100755 --- a/anypinentry +++ b/anypinentry @@ -91,6 +91,7 @@ password_prompt() { else cancelled_error; fi; + repeat= } # :: OK | ERR -- cgit v1.3.1 From e7862d6a8e15d050ea9ecadd177e3111121819ff Mon Sep 17 00:00:00 2001 From: Jeremy Brubaker Date: Fri, 10 Jun 2022 09:51:32 -0400 Subject: % escape $, CR and LF per Assuan spec --- anypinentry | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/anypinentry b/anypinentry index 0742281..bad8057 100755 --- a/anypinentry +++ b/anypinentry @@ -84,7 +84,13 @@ password_prompt() { show_error "$error__password_mismatch"; password_prompt "$repeat"; else - [ -n "$pass" ] && echo "D $pass"; + if [ ! -z "$pass" ]; then + echo "D $pass" | + sed 's/%/%25/; s/\r/%0D/' | # % = 25 and CR = %0D + awk 'BEGIN {ORS="%0A"} /^..*$/ {print}' | # LF = %0A + sed 's/%0A$//' # Strip trailing %0A + echo + fi echo "OK"; fi; fi; -- cgit v1.3.1 From a2adf4a6040a40c8adc09d8fbeae1a7e3f008615 Mon Sep 17 00:00:00 2001 From: Jeremy Brubaker Date: Fri, 10 Jun 2022 09:52:17 -0400 Subject: Ignore commands that begin with '#' per the spec --- anypinentry | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anypinentry b/anypinentry index bad8057..9412a3a 100755 --- a/anypinentry +++ b/anypinentry @@ -175,7 +175,7 @@ interpret_command() { SETTITLE) title="$data"; echo "OK" ;; SETTIMEOUT) not_implemented_error ;; CLEARPASSPHRASE) not_implemented_error ;; - '') ;; + '' | \#*) ;; *) unknown_error ;; esac; } -- cgit v1.3.1 From d1f098d11e58e86b57541a776cf001d4f11488e1 Mon Sep 17 00:00:00 2001 From: Jeremy Brubaker Date: Fri, 10 Jun 2022 09:53:37 -0400 Subject: Ignore lines that are more than 1000 bytes Per the Assuan spec --- anypinentry | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/anypinentry b/anypinentry index 9412a3a..213fffe 100755 --- a/anypinentry +++ b/anypinentry @@ -143,6 +143,11 @@ END } interpret_command() { + # Refuse lines of more than 1000 bytes + newline + if [ $(echo "$1" | wc -c) -gt 1001 ]; then + echo "ERR too long" + return + fi cmd="$(echo "$1" | cut -d' ' -f1 | tr a-z A-Z)"; data="$(echo "$1" | cut -d' ' -f2-)"; -- cgit v1.3.1 From 30d8ac5669bf188dcd602f0dc93c6ba412f5662f Mon Sep 17 00:00:00 2001 From: Jeremy Brubaker Date: Fri, 10 Jun 2022 09:55:15 -0400 Subject: Do case-insensitive matching on 'GETINFO' argument --- anypinentry | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/anypinentry b/anypinentry index 213fffe..82ab571 100755 --- a/anypinentry +++ b/anypinentry @@ -65,8 +65,8 @@ save_option() { get_info() { case "$1" in - version) echo "D $VERSION" && echo "OK" ;; - pid) echo "D $$" && echo "OK" ;; + VERSION) echo "D $VERSION" && echo "OK" ;; + PID) echo "D $$" && echo "OK" ;; *) com_error ;; esac; } @@ -149,7 +149,7 @@ interpret_command() { return fi cmd="$(echo "$1" | cut -d' ' -f1 | tr a-z A-Z)"; - data="$(echo "$1" | cut -d' ' -f2-)"; + data="$(echo "$1" | cut -d' ' -f2- | tr a-z A-Z)"; case "${cmd}" in NOP) ;; -- cgit v1.3.1 From e4f7684a4211853b1c879c9847759960fe1adf1e Mon Sep 17 00:00:00 2001 From: Jeremy Brubaker Date: Fri, 10 Jun 2022 10:52:48 -0400 Subject: Fix case-changing of command argument Only change the case of a command argument when it needs to be matched (currently only in get_info). The previous method prevented things like setting a multi-case description with SETDESC --- anypinentry | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/anypinentry b/anypinentry index 82ab571..cd810a9 100755 --- a/anypinentry +++ b/anypinentry @@ -64,6 +64,7 @@ save_option() { } get_info() { + arg=$(echo "$1" | tr a-z A-Z) case "$1" in VERSION) echo "D $VERSION" && echo "OK" ;; PID) echo "D $$" && echo "OK" ;; @@ -149,7 +150,7 @@ interpret_command() { return fi cmd="$(echo "$1" | cut -d' ' -f1 | tr a-z A-Z)"; - data="$(echo "$1" | cut -d' ' -f2- | tr a-z A-Z)"; + data="$(echo "$1" | cut -d' ' -f2-)"; case "${cmd}" in NOP) ;; -- cgit v1.3.1