-
Notifications
You must be signed in to change notification settings - Fork 10
/
hotp_initialize
executable file
·51 lines (44 loc) · 1.06 KB
/
hotp_initialize
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
#!/bin/sh
usage()
{
echo "This command initializes the HOTP counter of the HOTP USB Security Dongle to the specified value"
echo "usage: $0 <admin_pin> <HOTP_secret> <HOTP_counter>"
}
if [ "$3" == "" ]; then
usage
exit 1
fi
PIN=$1
SECRET=$2
COUNTER=$3
SECRET_B32=$(cat $SECRET | base32)
# You can add a branding as forth argument (used in Heads)
if [ -n "$4" ]; then
BRANDING="$4"
else
BRANDING="HOTP USB Security Dongle"
fi
hotp_verification set $SECRET_B32 "$PIN"
if [ $? -ne 0 ]; then
echo "ERROR: Setting HOTP secret on $BRANDING failed!"
exit 1
fi
i=9
while [ "$i" -lt "$COUNTER" ]; do
echo "Updating counter to $i"
HOTP_CODE=$(hotp $i < $SECRET)
hotp_verification check $HOTP_CODE > /dev/null
if [ $? -ne 0 ]; then
echo "HOTP check failed for counter=$i, code=$HOTP_CODE"
exit 1
fi
let "i += 10"
done
HOTP_CODE=$(hotp $COUNTER < $SECRET)
hotp_verification check $HOTP_CODE > /dev/null
if [ $? -ne 0 ]; then
echo "HOTP check failed for counter=$COUNTER, code=$HOTP_CODE"
exit 1
else
echo "$BRANDING initialized at counter $COUNTER"
fi