-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmk-totp-func.sh
executable file
·40 lines (35 loc) · 1.15 KB
/
mk-totp-func.sh
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
#!/bin/bash
#
# dwf -- initial
# Thu Oct 19 14:35:36 MDT 2023
#
# OpenSSL options (openssl enc -help)
# aes-256-cbc ciphername
# -e,-d encrypt,decrypt
# -pbkdf2 password-based key derivation function 2
# -a output Base-64
QR_ImageDir=${1:-~/Saved/QR_Codes/}
if [ ! -d $QR_ImageDir ]; then
echo "Edit this script and set 'QR_ImageDir' or supply one"
echo "Usage: `basename $0` [image_directory]"
exit 1
fi
#########################################
# extract otpauth uri's from saved images
#########################################
totp-qr --uri ${QR_ImageDir}/* | \
#
#########################################
# encrypt uri's (prompted for a password)
# outputs a Base-64 payload
#########################################
openssl aes-256-cbc -e -pbkdf2 -a | \
#
###############################################
# emit a bash function: totp()
# 1. decrypt the data (prompted for a password)
# 2. send uri's to totp-qr to generate codes
# 3. sort output by issuer
###############################################
perl -0 -ne 'print "\ntotp() {\nopenssl aes-256-cbc -d -pbkdf2 -a << EOF | totp-qr \$1 | sort -t, -k2\n${_}EOF\n}\n"'
exit 0