Skip to content

Instantly share code, notes, and snippets.

@savaged
Last active October 9, 2023 14:08
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 savaged/8c08b4b4ba2ffa82c00a2bf2bfb11b35 to your computer and use it in GitHub Desktop.
Save savaged/8c08b4b4ba2ffa82c00a2bf2bfb11b35 to your computer and use it in GitHub Desktop.
Fun with a very basic implementation of TOTP
#!/bin/sh
# generate shared secret for TOTP
secret='never gonna give you up'
# take only the last 16 characters less padding
# apply standard formatting (see https://github.com/google/google-authenticator/wiki/Key-Uri-Format )
# generate the QR code (remember to apply percent encoding for the url)
echo -n $secret | base32 | sed 's/=//g' | tail -c 16 | xargs -I $ echo 'otpauth://totp/savaged%20info:alice@test.com?secret=$&issuer=Savaged' | xargs qrencode -o ~/Downloads/savaged-qr-code.png
#finally, generate TOTP
#`echo -n $secret | base32 | sed 's/=//g' | tail -c 16 | xargs oathtool -b --totp`
zbarimg -q savaged-qr-code.png | sed -n -e 's/^.*secret=//p' | sed -E 's/^(.*)\&issuer\=\w+/\1/g' | xargs oathtool -b --totp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment