Skip to content

Commit da03a25

Browse files
committed
fix tpmr.sh: use tpm_owner_passphrase from prompt function
The prompt_tpm_owner_password() function sets tpm_owner_passphrase variable, but tpm2_seal was using an unset tpm_owner_password variable instead. This caused evictcontrol to fail with auth error (0x9A2) since no passphrase was being passed to the TPM command. Also standardizes all user-facing strings and variables to use 'passphrase' instead of 'password' for TPM owner auth, including the cache file path. Fixes regression introduced in commit 16648ca.
1 parent ee07ae0 commit da03a25

File tree

6 files changed

+138
-149
lines changed

6 files changed

+138
-149
lines changed

initrd/bin/gui-init.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,7 @@ fi
956956

957957
# Detect dongle branding from USB VID:PID -- must run AFTER enable_usb so lsusb
958958
# can see the dongle (NK3 enumerates ~1 second after USB module load).
959-
DONGLE_BRAND="$(detect_usb_security_dongle_branding)"
960-
export DONGLE_BRAND
959+
detect_usb_security_dongle_branding
961960

962961
if detect_boot_device; then
963962
# /boot device with installed OS found

initrd/bin/oem-factory-reset.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,7 @@ usb_security_token_capabilities_check() {
10041004
enable_usb
10051005

10061006
# Always detect dongle branding from USB VID:PID — never read a stored file.
1007-
DONGLE_BRAND="$(detect_usb_security_dongle_branding)"
1008-
export DONGLE_BRAND
1007+
detect_usb_security_dongle_branding
10091008
DEBUG "USB Security dongle detected: $DONGLE_BRAND"
10101009
# Only show generic "Detected" if no specific brand was identified
10111010
if [ "$DONGLE_BRAND" = "USB Security dongle" ]; then

initrd/bin/seal-hotpkey.sh

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ counter_value=1
5151
enable_usb
5252

5353
# Detect branding after USB is up so lsusb can see the device.
54-
DONGLE_BRAND="$(detect_usb_security_dongle_branding)"
55-
export DONGLE_BRAND
54+
detect_usb_security_dongle_branding
5655
DEBUG "$DONGLE_BRAND detected via USB VID:PID"
5756

5857
TRACE_FUNC
@@ -72,8 +71,7 @@ if ! hotp_token_info="$(hotp_verification info)"; then
7271
fi
7372

7473
# Re-detect branding now that the dongle is confirmed present.
75-
DONGLE_BRAND="$(detect_usb_security_dongle_branding)"
76-
export DONGLE_BRAND
74+
detect_usb_security_dongle_branding
7775
DEBUG "$DONGLE_BRAND detected via USB VID:PID"
7876

7977
# Truncate the secret if it is longer than the maximum HOTP secret
@@ -109,13 +107,13 @@ hotpkey_fw_display "$hotp_token_info" "$DONGLE_BRAND"
109107
show_pin_retries() {
110108
local info
111109
info="$(hotp_verification info 2>/dev/null)" || true
112-
if [ "$prompt_message" = "Secrets app" ]; then
110+
if [ "$DONGLE_BRAND" = "Nitrokey 3" ]; then
113111
admin_pin_retries=$(echo "$info" | grep "Secrets app PIN counter:" | cut -d ':' -f 2 | tr -d ' ')
114112
else
115113
admin_pin_retries=$(echo "$info" | grep "Card counters: Admin" | grep -o 'Admin [0-9]*' | grep -o '[0-9]*')
116114
fi
117115
admin_pin_retries="${admin_pin_retries:-0}"
118-
STATUS "$DONGLE_BRAND $prompt_message PIN retries remaining: $(pin_color "$admin_pin_retries")${admin_pin_retries}\033[0m"
116+
STATUS "$DONGLE_BRAND GPG Admin PIN retries remaining: $(pin_color "$admin_pin_retries")${admin_pin_retries}\033[0m"
119117
}
120118

121119
# Try using factory default admin PIN for 1 month following OEM reset to ease
@@ -133,7 +131,7 @@ if [ "$((now_date - gpg_key_create_time))" -gt "$month_secs" ]; then
133131
elif [ "$admin_pin_retries" -lt 3 ]; then
134132
DEBUG "Not trying default PIN ($admin_pin): only $admin_pin_retries attempt(s) left"
135133
else
136-
STATUS "Trying $prompt_message PIN to seal HOTP secret on $DONGLE_BRAND"
134+
STATUS "Trying GPG Admin PIN to seal HOTP secret on $DONGLE_BRAND"
137135
# NK3 requires physical touch confirmation for the initialize operation
138136
if [ "$DONGLE_BRAND" = "Nitrokey 3" ]; then
139137
NOTE "Nitrokey 3 requires physical presence: touch the dongle when prompted"
@@ -151,9 +149,9 @@ if [ "$admin_pin_status" -ne 0 ]; then
151149
for tries in 1 2 3; do
152150
show_pin_retries
153151
if [ "$tries" -eq 1 ]; then
154-
INPUT "Enter your $DONGLE_BRAND $prompt_message PIN (attempt $tries/3):" -r -s admin_pin
152+
INPUT "Enter your $DONGLE_BRAND GPG Admin PIN (attempt $tries/3):" -r -s admin_pin
155153
else
156-
INPUT "Wrong PIN - re-enter your $DONGLE_BRAND $prompt_message PIN (attempt $tries/3):" -r -s admin_pin
154+
INPUT "Wrong PIN - re-enter your $DONGLE_BRAND GPG Admin PIN (attempt $tries/3):" -r -s admin_pin
157155
fi
158156
if hotp_initialize "$admin_pin" $HOTP_SECRET $counter_value "$DONGLE_BRAND"; then
159157
break
@@ -163,10 +161,10 @@ if [ "$admin_pin_status" -ne 0 ]; then
163161
shred -n 10 -z -u "$HOTP_SECRET" 2>/dev/null
164162
case "$DONGLE_BRAND" in
165163
"Nitrokey Pro" | "Nitrokey Storage" | "Nitrokey 3")
166-
DIE "Setting HOTP secret on $DONGLE_BRAND failed after 3 attempts. To reset $prompt_message PIN: redo Re-Ownership, or use Nitrokey App 2, or contact Nitrokey support."
164+
DIE "Setting HOTP secret on $DONGLE_BRAND failed after 3 attempts. To reset GPG Admin PIN: redo Re-Ownership, or use Nitrokey App 2, or contact Nitrokey support."
167165
;;
168166
"Librem Key")
169-
DIE "Setting HOTP secret on $DONGLE_BRAND failed after 3 attempts. To reset $prompt_message PIN: redo Re-Ownership or contact Purism support."
167+
DIE "Setting HOTP secret on $DONGLE_BRAND failed after 3 attempts. To reset GPG Admin PIN: redo Re-Ownership or contact Purism support."
170168
;;
171169
*)
172170
DIE "Setting HOTP secret failed after 3 attempts"
@@ -177,7 +175,7 @@ if [ "$admin_pin_status" -ne 0 ]; then
177175
else
178176
# Default PIN was accepted — security reminder, not a fatal error.
179177
# NOTE prints blank lines before/after and is always visible; no INPUT needed.
180-
NOTE "Default $prompt_message PIN detected. Change it via Options --> OEM Factory Reset / Re-Ownership."
178+
NOTE "Default GPG Admin PIN detected. Change it via Options --> OEM Factory Reset / Re-Ownership."
181179
fi
182180

183181
# HOTP key no longer needed

initrd/bin/seal-totp.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ DEBUG "Sealing TOTP without PCR6 involvement (LUKS header consistency is not fir
5050
# pcr 7 is containing measurements of user injected stuff in cbfs
5151
DEBUG "Sealing TOTP with actual state of PCR7 (User injected stuff in cbfs)"
5252
tpmr.sh pcrread -a 7 "$pcrf"
53-
#Make sure we clear the TPM Owner Password from memory in case it failed to be used to seal TOTP
53+
#Make sure we clear the TPM Owner Passphrase from memory in case it failed to be used to seal TOTP
5454

5555
# if the board has TPM2 tools, check for the primary handle before
5656
# attempting to seal; a missing handle is the most common reason for
@@ -61,9 +61,9 @@ fi
6161

6262
# perform sealing via tpmr.sh. Failures may indicate missing primary handle
6363
# or other TPM state issues. Avoid DO_WITH_DEBUG so interactive prompts
64-
# (TPM owner password on TPM1) are not hidden from the user.
64+
# (TPM owner passphrase on TPM1) are not hidden from the user.
6565
STATUS "Sealing TOTP secret to TPM NVRAM"
66-
if ! tpmr.sh seal "$TOTP_SECRET" "$TPM_NVRAM_SPACE" 0,1,2,3,4,7 "$pcrf" 312 "" "$TPM_PASSWORD"; then
66+
if ! tpmr.sh seal "$TOTP_SECRET" "$TPM_NVRAM_SPACE" 0,1,2,3,4,7 "$pcrf" 312 "" "$TPM_PASSPHRASE"; then
6767
# tpmr.sh already logged details; guide user generically to reset TPM
6868
DIE "Unable to seal TOTP secret to TPM NVRAM; reset the TPM (Options -> TPM/TOTP/HOTP Options -> Reset the TPM in the GUI) and try again."
6969
fi

0 commit comments

Comments
 (0)