-
-
Save chr5tphr/f1dfba3072374087c063450fe92f6644 to your computer and use it in GitHub Desktop.
Tiny TOTP token management script using gnupg and oathtool, storing encrypted tokens
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
die(){ | |
echo "${@}" | |
exit 1 | |
} | |
list-targets(){ | |
find "${OTPDIR}" -type f -name '*.gpg' -printf '%P\n' | sed 's/.gpg$//g' | |
exit | |
} | |
parse_params(){ | |
OTPDIR="${HOME}/.config/oath" | |
while (($#)); do | |
case ${1:-} in | |
-l) list-targets ;; | |
-?*) die "Unknown option: ${1}" ;; | |
--) args+=("$@") ;; | |
*) args+=("${1:-}") ;; | |
esac | |
shift | |
done | |
(("${#args[@]}")) || list-targets | |
(("${#args[@]}" == 1)) || die "Too many arguments!" | |
TARGET="${OTPDIR}/${args[0]}.gpg" | |
} | |
parse_params "$@" | |
[ -f "$TARGET" ] || die "Target not found: ${TARGET}" | |
gpg -dq "$TARGET" | sed 's#^.\+[&?]secret=\([A-Z0-9]*\)\(&.\+\)\?$#\1#' | oathtool --base32 --totp - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment