From 6cc0c6633adba88c7e2398bc0ed27921d8dc3896 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Mon, 17 Dec 2018 14:12:06 -0600 Subject: [PATCH 1/3] Added TOTP time remaining calc and printout --- README.md | 1 + otp.bash | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index acd0b47..dcc6ea8 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ Generate a 2FA code using this token: ``` $ pass otp totp-secret 698816 +Expires in 26 seconds ``` Display a QR code for an OTP token: diff --git a/otp.bash b/otp.bash index d4c7756..e7a6639 100755 --- a/otp.bash +++ b/otp.bash @@ -334,9 +334,11 @@ cmd_otp_code() { local cmd case "$otp_type" in totp) + curr_time=$(date +%s) + totp_time_remaining=$((30 - ($curr_time % 30))) cmd="$OATH -b --totp" [[ -n "$otp_algorithm" ]] && cmd+=$(echo "=${otp_algorithm}"|tr "[:upper:]" "[:lower:]") - [[ -n "$otp_period" ]] && cmd+=" --time-step-size=$otp_period"s + [[ -n "$otp_period" ]] && cmd+=" --time-step-size=$otp_period"s && totp_time_remaining=$(($otp_period - ($curr_time % $otp_period))) [[ -n "$otp_digits" ]] && cmd+=" --digits=$otp_digits" cmd+=" $otp_secret" ;; @@ -369,8 +371,10 @@ cmd_otp_code() { if [[ $clip -ne 0 ]]; then clip "$out" "OTP code for $path" + [[ -n "$totp_time_remaining" ]] && echo "Expires in $totp_time_remaining seconds" else echo "$out" + [[ -n "$totp_time_remaining" ]] && echo "Expires in $totp_time_remaining seconds" fi } From 25e36499bb3135ba0f4f61862f3d82671b14b93e Mon Sep 17 00:00:00 2001 From: Drew Short Date: Mon, 17 Dec 2018 14:26:33 -0600 Subject: [PATCH 2/3] Fixed broken code test by asserting only the first line returned. --- test/code.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/code.t b/test/code.t index 39310fb..cd828be 100755 --- a/test/code.t +++ b/test/code.t @@ -15,7 +15,7 @@ test_expect_success 'Generates TOTP code' ' test_pass_init && "$PASS" otp insert passfile <<< "$uri" && - code=$("$PASS" otp passfile) && + code=$("$PASS" otp passfile | head -n 1) && [[ ${#code} -eq 6 ]] ' From 6d8926c542d4e8d23e199390128413e951621bd5 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Mon, 17 Dec 2018 14:43:50 -0600 Subject: [PATCH 3/3] Resolving shellcheck identified issues --- otp.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/otp.bash b/otp.bash index e7a6639..78115e2 100755 --- a/otp.bash +++ b/otp.bash @@ -335,10 +335,10 @@ cmd_otp_code() { case "$otp_type" in totp) curr_time=$(date +%s) - totp_time_remaining=$((30 - ($curr_time % 30))) + totp_time_remaining=$((30 - (curr_time % 30))) cmd="$OATH -b --totp" [[ -n "$otp_algorithm" ]] && cmd+=$(echo "=${otp_algorithm}"|tr "[:upper:]" "[:lower:]") - [[ -n "$otp_period" ]] && cmd+=" --time-step-size=$otp_period"s && totp_time_remaining=$(($otp_period - ($curr_time % $otp_period))) + [[ -n "$otp_period" ]] && cmd+=" --time-step-size=$otp_period"s && totp_time_remaining=$((otp_period - (curr_time % otp_period))) [[ -n "$otp_digits" ]] && cmd+=" --digits=$otp_digits" cmd+=" $otp_secret" ;;