Skip to content

Commit

Permalink
WiP: add nk3 secret app reset function and call it following security…
Browse files Browse the repository at this point in the history
… dongle reset logic

Signed-off-by: Thierry Laurion <[email protected]>
  • Loading branch information
tlaurion committed Nov 28, 2024
1 parent 7db2790 commit 07f3710
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions initrd/bin/oem-factory-reset
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ mount_boot() {
fi
}

reset_nk3_secret_app() {
TRACE_FUNC
# Reset Nitrokey 3 secret app
if lsusb | grep -q "20a0:42b2"; then
echo
echo "Resetting Nitrokey 3 secret app"
# Reset Nitrokey 3 secret app
/bin/hotp_verification reset
fi
}

#Generate a gpg master key: no expiration date, ${RSA_KEY_LENGTH} bits
#This key will be used to sign 3 subkeys: encryption, authentication and signing
#The master key and subkeys will be copied to backup, and the subkeys moved from memory keyring to the smartcard
Expand Down Expand Up @@ -533,13 +544,19 @@ gpg_key_factory_reset() {
ERROR=$(cat /tmp/gpg_card_edit_output)
whiptail_error_die "GPG Key factory reset failed!\n\n$ERROR"
fi

#Reset Nitrokey 3 secret app
reset_nk3_secret_app
# Nk3 now ready to set secret app PIN on first use...

# If Nitrokey Storage is inserted, reset AES keys as well
if lsusb | grep -q "20a0:4109" && [ -x /bin/hotp_verification ]; then
DEBUG "Nitrokey Storage detected, resetting AES keys..."
/bin/hotp_verification regenerate ${ADMIN_PIN_DEF}
DEBUG "Restarting scdaemon to remove possible exclusive lock of dongle"
killall -9 scdaemon
fi

# Toggle forced sig (good security practice, forcing PIN request for each signature request)
if gpg --card-status | grep "Signature PIN" | grep -q "not forced"; then
DEBUG "GPG toggling forcesig on since off..."
Expand All @@ -554,6 +571,7 @@ gpg_key_factory_reset() {
whiptail_error_die "GPG Key forcesig toggle on failed!\n\n$ERROR"
fi
fi

# use p256 for key generation if requested
if [ "$GPG_ALGO" = "p256" ]; then
{
Expand Down

0 comments on commit 07f3710

Please sign in to comment.