Skip to content

Commit fd24b6b

Browse files
committed
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent 0166533 commit fd24b6b

File tree

9 files changed

+148
-102
lines changed

9 files changed

+148
-102
lines changed

initrd/bin/gui-init

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ generate_totp_hotp()
162162
echo
163163
if [ -x /bin/hotp_verification ]; then
164164
if [ "$CONFIG_TOTP_SKIP_QRCODE" != y ]; then
165-
echo "Once you have scanned the QR code, hit Enter to configure your HOTP USB Security Dongle (e.g. Librem Key or Nitrokey)"
165+
echo "Once you have scanned the QR code, hit Enter to configure your HOTP USB Security dongle (e.g. Librem Key or Nitrokey)"
166166
read
167167
fi
168168
/bin/seal-hotpkey
@@ -644,7 +644,7 @@ TRACE_FUNC
644644
if [ -r /boot/kexec_hotp_key ]; then
645645
HOTPKEY_BRANDING="$(cat /boot/kexec_hotp_key)"
646646
else
647-
HOTPKEY_BRANDING="HOTP USB Security Dongle"
647+
HOTPKEY_BRANDING="HOTP USB Security dongle"
648648
fi
649649

650650
if [ -x /bin/hotp_verification ]; then

initrd/bin/kexec-insert-key

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ echo '+++ Building initrd'
9292
# pad the initramfs (dracut doesn't pad the last gz blob)
9393
# without this the kernel init/initramfs.c fails to read
9494
# the subsequent uncompressed/compressed cpio
95-
dd if="$INITRD" of="$SECRET_CPIO" bs=512 conv=sync ||
95+
dd if="$INITRD" of="$SECRET_CPIO" bs=512 conv=sync > /dev/null 2>&1 ||
9696
die "Failed to copy initrd to /tmp"
9797

9898
if [ "$unseal_failed" = "n" ]; then

initrd/bin/oem-factory-reset

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,26 @@ mount_boot() {
143143

144144
reset_nk3_secret_app() {
145145
TRACE_FUNC
146-
# Reset Nitrokey 3 Secrets App
146+
# Reset Nitrokey 3 Secrets app with $ADMIN_PIN (default 12345678, or customised)
147147
if lsusb | grep -q "20a0:42b2"; then
148148
echo
149-
warn "Resetting Nitrokey 3 Secrets App PIN. Physical presence (touch) will be required"
150-
#TODO, change message when https://github.com/Nitrokey/nitrokey-hotp-verification/issues/41 is fixed
149+
warn "Resetting Nitrokey 3 Secrets App with PIN. Physical presence (touch) will be required"
150+
# TODO: change message when https://github.com/Nitrokey/nitrokey-hotp-verification/issues/41 is fixed
151151
# Reset Nitrokey 3 secret app with PIN
152-
if ! /bin/hotp_verification reset "${ADMIN_PIN}"; then
153-
whiptail_error_die "Failed to reset Nitrokey 3 Secrets App with error code $?, contact Nitrokey support"
154-
fi
152+
# Do 3 attempts to reset Nitrokey 3 Secrets App if return code is 3 (no touch)
153+
for attempt in 1 2 3; do
154+
if /bin/hotp_verification reset "${ADMIN_PIN}"; then
155+
return 0
156+
else
157+
error_code=$?
158+
if [ $error_code -eq 3 ] && [ $attempt -lt 3 ]; then
159+
whiptail --msgbox "Nitrokey 3 requires physical presence: touch the dongle when requested" $HEIGHT $WIDTH --title "Nk3 cecrets app reset attempt: $attempt/3"
160+
else
161+
whiptail_error_die "Nitrokey 3 secrets app reset failed with error:$error_code. Contact Nitrokey support"
162+
fi
163+
fi
164+
done
165+
echo
155166
fi
156167
}
157168

@@ -323,7 +334,7 @@ generate_inmemory_p256_master_and_subkeys() {
323334
keytocard_subkeys_to_smartcard() {
324335
TRACE_FUNC
325336

326-
#make sure usb ready and USB Security Dongle ready to communicate with
337+
#make sure usb ready and USB Security dongle ready to communicate with
327338
enable_usb
328339
enable_usb_storage
329340
gpg --card-status >/dev/null 2>&1 || die "Error getting GPG card status"
@@ -541,7 +552,7 @@ gpg_key_factory_reset() {
541552
reset_nk3_secret_app
542553

543554
# Factory reset GPG card
544-
echo "GPG factory reset of USB Security Dongle's smartcard..."
555+
echo "GPG factory reset of USB Security dongle's OpenPGP smartcard..."
545556
{
546557
echo admin # admin menu
547558
echo factory-reset # factory reset smartcard
@@ -595,7 +606,7 @@ gpg_key_factory_reset() {
595606
>/tmp/gpg_card_edit_output 2>&1
596607
if [ $? -ne 0 ]; then
597608
ERROR=$(cat /tmp/gpg_card_edit_output)
598-
whiptail_error_die "Setting key to NIST-P256 in USB Security Dongle failed."
609+
whiptail_error_die "Setting key to NIST-P256 in USB Security dongle failed."
599610
fi
600611
# fallback to RSA key generation by default
601612
elif [ "$GPG_ALGO" = "RSA" ]; then
@@ -617,7 +628,7 @@ gpg_key_factory_reset() {
617628
>/tmp/gpg_card_edit_output 2>&1
618629
if [ $? -ne 0 ]; then
619630
ERROR=$(cat /tmp/gpg_card_edit_output)
620-
whiptail_error_die "Setting key attributed to RSA ${RSA_KEY_LENGTH} bits in USB Security Dongle failed."
631+
whiptail_error_die "Setting key attributed to RSA ${RSA_KEY_LENGTH} bits in USB Security dongle failed."
621632
fi
622633
else
623634
#Unknown GPG_ALGO
@@ -631,7 +642,7 @@ generate_OEM_gpg_keys() {
631642
TRACE_FUNC
632643

633644
#This function simply generates subkeys in smartcard following smarcard config from gpg_key_factory_reset
634-
echo "Generating GPG keys in USB Security Dongle's smartcard..."
645+
echo "Generating GPG keys in USB Security dongle's OpenPGP smartcard..."
635646
{
636647
echo admin # admin menu
637648
echo generate # generate keys
@@ -645,6 +656,11 @@ generate_OEM_gpg_keys() {
645656
echo ${USER_PIN_DEF} # Default user PIN since we just factory reset
646657
} | DO_WITH_DEBUG gpg --command-fd=0 --status-fd=2 --pinentry-mode=loopback --card-edit \
647658
>/tmp/gpg_card_edit_output 2>&1
659+
#This outputs to console \
660+
# "gpg: checking the trustdb"
661+
# "gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model"
662+
# "gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u"
663+
#TODO: Suppress this output to console (stdout shown in DEBUG mode)?
648664
if [ $? -ne 0 ]; then
649665
ERROR=$(cat /tmp/gpg_card_edit_output)
650666
whiptail_error_die "GPG Key automatic keygen failed!\n\n$ERROR"
@@ -704,7 +720,7 @@ generate_checksums() {
704720
tpmr counter_create \
705721
-pwdc '' \
706722
-la -3135106223 |
707-
tee /tmp/counter ||
723+
tee /tmp/counter >/dev/null 2>&1 ||
708724
whiptail_error_die "Unable to create TPM counter"
709725
TPM_COUNTER=$(cut -d: -f1 </tmp/counter)
710726

@@ -850,14 +866,14 @@ report_integrity_measurements() {
850866
enable_usb
851867
for attempt in 1 2 3; do
852868
if ! hotp_verification info >/dev/null 2>&1; then
853-
whiptail_warning --title "WARNING: Please insert your HOTP enabled USB Security Dongle (Attempt $attempt/3)" --msgbox "Your HOTP enabled USB Security Dongle was not detected.\n\nPlease remove it and insert it again." 0 80
869+
whiptail_warning --title "WARNING: Please insert your HOTP enabled USB Security dongle (Attempt $attempt/3)" --msgbox "Your HOTP enabled USB Security dongle was not detected.\n\nPlease remove it and insert it again." 0 80
854870
else
855871
break
856872
fi
857873
done
858874

859875
if [ $attempt -eq 3 ]; then
860-
die "No HOTP enabled USB Security Dongle detected. Please disable 'CONFIG_HOTPKEY' in the board config and rebuild."
876+
die "No HOTP enabled USB Security dongle detected. Please disable 'CONFIG_HOTPKEY' in the board config and rebuild."
861877
fi
862878

863879
# Don't output HOTP codes to screen, so as to make replay attacks harder
@@ -872,7 +888,7 @@ report_integrity_measurements() {
872888
BG_COLOR_MAIN_MENU="error"
873889
;;
874890
*)
875-
HOTP="Error checking code, Insert USB Security Dongle and retry"
891+
HOTP="Error checking code, Insert USB Security dongle and retry"
876892
BG_COLOR_MAIN_MENU="warning"
877893
;;
878894
esac
@@ -997,21 +1013,21 @@ if [ "$use_defaults" == "n" -o "$use_defaults" == "N" ]; then
9971013
; then
9981014
GPG_GEN_KEY_IN_MEMORY="y"
9991015
echo " ++++ Master key and subkeys will be generated in memory, backed up to dedicated LUKS container +++"
1000-
echo -e -n "Would you like in-memory generated subkeys to be copied to USB Security Dongle's smartcard?\n (Highly recommended so the smartcard is used on daily basis and backup is kept safe, but not required) [Y/n]: "
1016+
echo -e -n "Would you like in-memory generated subkeys to be copied to USB Security dongle's OpenPGP smartcard?\n (Highly recommended so the smartcard is used on daily basis and backup is kept safe, but not required) [Y/n]: "
10011017
read -n 1 prompt_output
10021018
echo
10031019
if [ "$prompt_output" == "n" \
10041020
-o "$prompt_output" == "N" ]; then
1005-
warn "Subkeys will NOT be copied to USB Security Dongle's smartcard"
1021+
warn "Subkeys will NOT be copied to USB Security dongle's OpenPGP smartcard"
10061022
warn "Your GPG key material backup thumb drive should be cloned to a second thumb drive for redundancy for production environements"
10071023
GPG_GEN_KEY_IN_MEMORY_COPY_TO_SMARTCARD="n"
10081024
else
1009-
echo "++++ Subkeys will be copied to USB Security Dongle's smartcard ++++"
1025+
echo "++++ Subkeys will be copied to USB Security dongle's OpenPGP smartcard ++++"
10101026
warn "Please keep your GPG key material backup thumb drive safe"
10111027
GPG_GEN_KEY_IN_MEMORY_COPY_TO_SMARTCARD="y"
10121028
fi
10131029
else
1014-
echo "GPG key material will be generated on USB Security Dongle's smartcard without backup"
1030+
echo "GPG key material will be generated on USB Security dongle's OpenPGP smartcard without backup"
10151031
GPG_GEN_KEY_IN_MEMORY="n"
10161032
GPG_GEN_KEY_IN_MEMORY_COPY_TO_SMARTCARD="n"
10171033
fi
@@ -1177,24 +1193,24 @@ if [ "$GPG_GEN_KEY_IN_MEMORY" = "n" ]; then
11771193
fi
11781194
else
11791195
GPG_EXPORT=0
1180-
# needed for USB Security Dongle below and is ensured via mount-usb in case of GPG_EXPORT=1
1196+
# needed for USB Security dongle below and is ensured via mount-usb in case of GPG_EXPORT=1
11811197
enable_usb
11821198
fi
11831199
fi
11841200

1185-
# ensure USB Security Dongle connected if GPG_GEN_KEY_IN_MEMORY=n or if GPG_GEN_KEY_IN_MEMORY_COPY_TO_SMARTCARD=y
1201+
# ensure USB Security dongle connected if GPG_GEN_KEY_IN_MEMORY=n or if GPG_GEN_KEY_IN_MEMORY_COPY_TO_SMARTCARD=y
11861202
if [ "$GPG_GEN_KEY_IN_MEMORY" = "n" -o "$GPG_GEN_KEY_IN_MEMORY_COPY_TO_SMARTCARD" = "y" ]; then
1187-
echo -e "\nChecking for USB Security Dongle...\n"
1203+
echo -e "\nChecking for USB Security dongle...\n"
11881204
enable_usb
11891205
if ! gpg --card-status >/dev/null 2>&1; then
1190-
local_whiptail_error "Can't access USB Security Dongle; \nPlease remove and reinsert, then press Enter."
1206+
local_whiptail_error "Can't access USB Security dongle; \nPlease remove and reinsert, then press Enter."
11911207
if ! gpg --card-status >/dev/null 2>/tmp/error; then
11921208
ERROR=$(tail -n 1 /tmp/error | fold -s)
1193-
whiptail_error_die "Unable to detect USB Security Dongle:\n\n${ERROR}"
1209+
whiptail_error_die "Unable to detect USB Security dongle:\n\n${ERROR}"
11941210
fi
11951211
fi
11961212

1197-
#Now that USB Security Dongle is detected, we can check its capabilities and limitations
1213+
#Now that USB Security dongle is detected, we can check its capabilities and limitations
11981214
usb_security_token_capabilities_check
11991215
fi
12001216

@@ -1266,7 +1282,7 @@ if [ "$GPG_GEN_KEY_IN_MEMORY" = "y" ]; then
12661282
fi
12671283
else
12681284
#Generate GPG key and subkeys on smartcard only
1269-
echo -e "\nResetting USB Security Dongle's GPG smartcard...\n(this will take around 3 minutes...)\n"
1285+
echo -e "\nResetting USB Security dongle's GPG smartcard...\n(this will take around 3 minutes...)\n"
12701286
gpg_key_factory_reset
12711287
generate_OEM_gpg_keys
12721288
fi
@@ -1389,7 +1405,7 @@ fi
13891405

13901406
#if nk3 detected, we add the NK3 Secre App PIN. Detect by product ID
13911407
if lsusb | grep -q "20a0:42b2"; then
1392-
passphrases+="Nitrokey 3 Secrets App PIN: ${ADMIN_PIN}\n"
1408+
passphrases+="Nitrokey 3 Secrets app PIN: ${ADMIN_PIN}\n"
13931409
fi
13941410

13951411
#GPG PINs output

initrd/bin/seal-hotpkey

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Retrieve the sealed TOTP secret and initialize a USB Security Dongle with it
2+
# Retrieve the sealed TOTP secret and initialize a USB Security dongle with it
33

44
. /etc/functions
55
. /etc/gui_functions
@@ -34,7 +34,7 @@ fatal_error() {
3434
if [ -r /boot/kexec_hotp_key ]; then
3535
HOTPKEY_BRANDING="$(cat /boot/kexec_hotp_key)"
3636
else
37-
HOTPKEY_BRANDING="HOTP USB Security Dongle"
37+
HOTPKEY_BRANDING="HOTP USB Security dongle"
3838
fi
3939

4040
if [ "$CONFIG_TPM" = "y" ]; then
@@ -77,13 +77,13 @@ if ! hotp_token_info="$(hotp_verification info)"; then
7777
fi
7878
fi
7979

80-
# Set HOTP USB Security Dongle branding based on VID
80+
# Set HOTP USB Security dongle branding based on VID
8181
if lsusb | grep -q "20a0:"; then
8282
HOTPKEY_BRANDING="Nitrokey"
8383
elif lsusb | grep -q "316d:"; then
8484
HOTPKEY_BRANDING="Librem Key"
8585
else
86-
HOTPKEY_BRANDING="HOTP USB Security Dongle"
86+
HOTPKEY_BRANDING="HOTP USB Security dongle"
8787
fi
8888

8989
# Truncate the secret if it is longer than the maximum HOTP secret
@@ -175,7 +175,7 @@ counter_value=$(expr $counter_value + 1)
175175
echo $counter_value >$HOTP_COUNTER ||
176176
fatal_error "Unable to create hotp counter file"
177177

178-
# Store/overwrite HOTP USB Security Dongle branding found out beforehand
178+
# Store/overwrite HOTP USB Security dongle branding found out beforehand
179179
echo $HOTPKEY_BRANDING >$HOTP_KEY ||
180180
die "Unable to store hotp key file"
181181

0 commit comments

Comments
 (0)