Skip to content

Commit dd72313

Browse files
committed
WiP: add GPG Admin/User PIN output grabbing on confirm_gpg_card presence call, echo for now, warn to input GPG User PIN when asked to unlock GPG card
Mitigate misunderstands and show GPG User/Admin PIN counts until proper output exists under hotp_verification info to reduce global confusion Add TODO under initrd/bin/seal-hotpkey to not foget to fix output since now outputting counter of 8 for Admin PIN which makes no sense at all under hotp_verification 1.6 Nitrokey/nitrokey-hotp-verification#38 Signed-off-by: Thierry Laurion <[email protected]>
1 parent 40da4d3 commit dd72313

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

initrd/bin/seal-hotpkey

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ awk_get_admin_counter="$awk_admin_counter_regex"' { print gensub('"$awk_admin_co
105105
admin_pin_retries="$(echo "$hotp_token_info" | awk "$awk_get_admin_counter")"
106106
admin_pin_retries="${admin_pin_retries:-0}"
107107
DEBUG "Admin PIN retry counter is $admin_pin_retries"
108+
#TODO: as per hotp_verification 1.6: this is 8 for nk3 and wrong. FIX
108109

109110
# Try using factory default admin PIN for 1 month following OEM reset to ease
110111
# initial setup. But don't do it forever to encourage changing the PIN and

initrd/etc/ash_functions

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ confirm_gpg_card() {
154154
# ensure we don't exit without retrying
155155
errexit=$(set -o | grep errexit | awk '{print $2}')
156156
set +e
157-
gpg --card-status >/dev/null
157+
gpg_output=$(gpg --card-status 2>&1)
158158
if [ $? -ne 0 ]; then
159159
# prompt for reinsertion and try a second time
160160
read -n1 -r -p \
@@ -165,13 +165,25 @@ confirm_gpg_card() {
165165
set -e
166166
fi
167167
# retry card status
168-
gpg --card-status >/dev/null ||
168+
gpg_output=$(gpg --card-status 2>&1) ||
169169
die "gpg card read failed"
170170
fi
171171
# restore prev errexit state
172172
if [ "$errexit" = "on" ]; then
173173
set -e
174174
fi
175+
176+
# Extract and display GPG PIN retry counters
177+
# output excerpt: "PIN retry counter : 3 0 3"
178+
pin_retry_counters=$(echo "$gpg_output" | grep 'PIN retry counter' | awk -F': ' '{print $2}')
179+
user_pin_retries=$(echo "$pin_retry_counters" | awk '{print $1}')
180+
admin_pin_retries=$(echo "$pin_retry_counters" | awk '{print $3}')
181+
182+
echo ""
183+
echo "GPG User PIN retry attempts left before locking: $user_pin_retries"
184+
echo "GPG Admin PIN retry attempts left before locking: $admin_pin_retries"
185+
warn "Please input your GPG User PIN at 'Please unlock the card' next prompt..."
186+
echo ""
175187
}
176188

177189
gpg_auth() {

0 commit comments

Comments
 (0)