File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,15 +22,59 @@ tpm nv_readvalue \
2222 -of " $sealed_file " \
2323|| die " Unable to read key from TPM NVRAM"
2424
25- for tries in 1 2 3; do
26- tpm_password=
27- while [ -z " $tpm_password " ]; do
28- unseal-totp || die " TOTP code generation failed"
2925
30- read -s -p " Disk unlock password: " tpm_password
31- echo
26+ get_password ()
27+ {
28+ last_half=X
29+
30+ while true ; do
31+
32+ # update the TOTP code every thirty seconds
33+ date=` date " +%Y-%m-%d %H:%M:%S" `
34+ seconds=` date " +%s" `
35+ half=` expr \( $seconds % 60 \) / 30`
36+ if [ " $half " != " $last_half " ]; then
37+ last_half=$half ;
38+ TOTP=` unseal-totp` \
39+ || die " TOTP code generation failed"
40+ fi
41+
42+ echo -n " $date $TOTP : "
43+
44+ # read the first character, non-blocking
45+ read \
46+ -t 1 \
47+ -n 1 \
48+ -s \
49+ -p " Enter unlock password: " \
50+ tpm_password_1 \
51+ && break
52+
53+ # nothing typed, redraw the line
54+ echo -ne ' \r'
3255 done
3356
57+ # they have started typing, read the rest, blocking
58+ if [ -z " $tpm_password_1 " ]; then
59+ # they hit enter; we should exit gracefully
60+ tpm_password=" "
61+ else
62+ # they hit something else, read the rest of the line
63+ read \
64+ -s \
65+ -p ' ' \
66+ tpm_password_2
67+ tpm_password=" $tpm_password_1$tpm_password_2 "
68+ fi
69+
70+ # clean up with a newline
71+ echo
72+
73+ }
74+
75+ for tries in 1 2 3; do
76+ get_password
77+
3478 if tpm unsealfile \
3579 -if " $sealed_file " \
3680 -of " $key_file " \
Original file line number Diff line number Diff line change @@ -20,8 +20,7 @@ tpm unsealfile \
2020
2121rm -f " $TOTP_SEALED "
2222
23- # echo -n "`date`: "
24- if ! totp < " $TOTP_SECRET " ; then
23+ if ! totp -q < " $TOTP_SECRET " ; then
2524 rm -f " $TOTP_SECRET "
2625 die ' Unable to compute TOTP hash?'
2726fi
You can’t perform that action at this time.
0 commit comments