-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtotp
More file actions
executable file
·53 lines (45 loc) · 1.24 KB
/
totp
File metadata and controls
executable file
·53 lines (45 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Generate TOTP codes using oathtool
#
# Requires the "oathtool" package.
#
# To extract the base32 key out of a QR code, install the "zbar-tools"
# package and use "zbarimg qr.png".
#
# Then put all of the keys in the ~/.totp/ directory.
#
# based on https://superuser.com/questions/462478/is-there-a-google-authenticator-desktop-client/826339#826339
# Create the key directory if it doesn't exist
KEYDIR="$HOME/.totp"
if [ ! -e "$KEYDIR" ] ; then
mkdir "$KEYDIR"
chmod go-rwx "$KEYDIR"
fi
# Check the permissions on the .totp directory
if [ -z "$(find "$KEYDIR" -type d -perm 0700)" ]; then
echo "The permissions of the $KEYDIR directory must be exactly 0700"
exit 1
fi
if [ "z$1" = "z" ] ; then
echo "Usage: $0 provider"
exit 2
fi
# Mount the LUKS partition
cryptmount totp || exit 4
PROVIDER="$1"
KEY="$KEYDIR/$PROVIDER"
FOUND=
if [ -r "$KEY" ] ; then
FOUND="yes"
CODE="$(/usr/bin/oathtool --totp --base32 "$(<"$KEY")")"
if [ "z$DISPLAY" != "z" ] ; then
echo -n "$CODE" | xsel --clipboard
fi
echo "$CODE"
fi
# Unmount the LUKS partition
cryptmount -u totp
if [ "$FOUND" != "yes" ] ; then
echo "Key '$KEY' not found"
exit 3
fi