Skip to content

Instantly share code, notes, and snippets.

@chr5tphr
Last active August 23, 2023 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chr5tphr/f1dfba3072374087c063450fe92f6644 to your computer and use it in GitHub Desktop.
Save chr5tphr/f1dfba3072374087c063450fe92f6644 to your computer and use it in GitHub Desktop.
Tiny TOTP token management script using gnupg and oathtool, storing encrypted tokens
#!/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