Skip to content

Commit 07f3710

Browse files
committed
WiP: add nk3 secret app reset function and call it following security dongle reset logic
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent 7db2790 commit 07f3710

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

initrd/bin/oem-factory-reset

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ mount_boot() {
138138
fi
139139
}
140140

141+
reset_nk3_secret_app() {
142+
TRACE_FUNC
143+
# Reset Nitrokey 3 secret app
144+
if lsusb | grep -q "20a0:42b2"; then
145+
echo
146+
echo "Resetting Nitrokey 3 secret app"
147+
# Reset Nitrokey 3 secret app
148+
/bin/hotp_verification reset
149+
fi
150+
}
151+
141152
#Generate a gpg master key: no expiration date, ${RSA_KEY_LENGTH} bits
142153
#This key will be used to sign 3 subkeys: encryption, authentication and signing
143154
#The master key and subkeys will be copied to backup, and the subkeys moved from memory keyring to the smartcard
@@ -533,13 +544,19 @@ gpg_key_factory_reset() {
533544
ERROR=$(cat /tmp/gpg_card_edit_output)
534545
whiptail_error_die "GPG Key factory reset failed!\n\n$ERROR"
535546
fi
547+
548+
#Reset Nitrokey 3 secret app
549+
reset_nk3_secret_app
550+
# Nk3 now ready to set secret app PIN on first use...
551+
536552
# If Nitrokey Storage is inserted, reset AES keys as well
537553
if lsusb | grep -q "20a0:4109" && [ -x /bin/hotp_verification ]; then
538554
DEBUG "Nitrokey Storage detected, resetting AES keys..."
539555
/bin/hotp_verification regenerate ${ADMIN_PIN_DEF}
540556
DEBUG "Restarting scdaemon to remove possible exclusive lock of dongle"
541557
killall -9 scdaemon
542558
fi
559+
543560
# Toggle forced sig (good security practice, forcing PIN request for each signature request)
544561
if gpg --card-status | grep "Signature PIN" | grep -q "not forced"; then
545562
DEBUG "GPG toggling forcesig on since off..."
@@ -554,6 +571,7 @@ gpg_key_factory_reset() {
554571
whiptail_error_die "GPG Key forcesig toggle on failed!\n\n$ERROR"
555572
fi
556573
fi
574+
557575
# use p256 for key generation if requested
558576
if [ "$GPG_ALGO" = "p256" ]; then
559577
{

0 commit comments

Comments
 (0)