dotfiles/backups/authenticator.sh

34 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# adopted from https://wiki.archlinux.org/index.php/Google_Authenticator
# This is the path to the Google Authenticator app file. It's typically located
# in /data under Android. Copy it to your PC in a safe location and specify the
# path to it here.
#DB="/path/to/com.google.android.apps.authenticator/databases/databases"
DB="$1"
if [ $# -ne 1 ]; then
printf "authenticator\n"
printf "usage: authenticator <path/to/org.authenticator/databases/databases>\n"
printf "\tThis is the path to the Authenticator app owned SQLite db file.\n"
printf "\tCopy it to your PC to a safe location and specify the path to it here.\n"
exit 1
fi
# On most Android systems with sufficient user access, the Google Authenticator
# database can be copied off the device and accessed directly, as it is an
# sqlite3 database. This shell script will read a Google Authenticator database
# and generate live codes for each key found:
sqlite3 "$DB" 'SELECT email,secret FROM accounts;' | while read A
do
NAME=`echo "$A" | cut -d '|' -f 1`
KEY=`echo "$A" | cut -d '|' -f 2`
CODE=`oathtool --totp -b "$KEY"`
echo -e "\e[1;32m$CODE\e[0m - \e[1;33m$NAME\e[0m"
done