Use bash arrays to separate arguments to oathtool and otptool

Also use long version of oathtool -b/--base32 option.
This commit is contained in:
Paul Wise
2023-05-12 13:39:53 +08:00
committed by Tad Fisher
parent 1e269f4d6e
commit 214eeb0d8d

View File

@@ -364,20 +364,21 @@ cmd_otp_code() {
local cmd
case "$otp_type" in
totp)
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_digits" ]] && cmd+=" --digits=$otp_digits"
cmd+=" $otp_secret"
[[ -n "$OTPTOOL" ]] && cmd="$OTPTOOL $uri"
cmd=("$OATH" --base32)
[[ -z "$otp_algorithm" ]] && cmd+=(--totp)
[[ -n "$otp_algorithm" ]] && cmd+=(--totp="$(echo "${otp_algorithm}"|tr "[:upper:]" "[:lower:]")")
[[ -n "$otp_period" ]] && cmd+=(--time-step-size="$otp_period"s)
[[ -n "$otp_digits" ]] && cmd+=(--digits="$otp_digits")
cmd+=("$otp_secret")
[[ -n "$OTPTOOL" ]] && cmd=("$OTPTOOL" "$uri")
;;
hotp)
local counter=$((otp_counter+1))
cmd="$OATH -b --hotp --counter=$counter"
[[ -n "$otp_digits" ]] && cmd+=" --digits=$otp_digits"
cmd+=" $otp_secret"
[[ -n "$OTPTOOL" ]] && cmd="$OTPTOOL $uri"
cmd=("$OATH" --base32 --hotp --counter="$counter")
[[ -n "$otp_digits" ]] && cmd+=(--digits="$otp_digits")
cmd+=("$otp_secret")
[[ -n "$OTPTOOL" ]] && cmd=("$OTPTOOL" "$uri")
;;
*)
@@ -385,7 +386,7 @@ cmd_otp_code() {
;;
esac
local out; out=$($cmd) || die "$path: failed to generate OTP code."
local out; out=$("${cmd[@]}") || die "$path: failed to generate OTP code."
if [[ "$otp_type" == "hotp" ]]; then
# Increment HOTP counter in-place