Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions initrd/bin/gui-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,19 @@ prompt_update_checksums() {
--yesno "You have chosen to update the checksums and sign all of the files in /boot.\n\nThis means that you trust that these files have not been tampered with.\n\nYou will need your GPG key available, and this change will modify your disk.\n\nDo you want to continue?" 0 80); then
if update_checksums; then
return 0
fi
# update_checksums may have set the TPM-reset-required marker
# during its execution (e.g. check_tpm_counter hit "out of
# resources"). Show the targeted TPM message instead of the
# generic failure so the user knows exactly what to do.
if tpm_reset_required; then
whiptail_error --title 'TPM Reset Required' \
--msgbox "Cannot sign /boot: TPM state is inconsistent.\n\nReset the TPM first (Options -> TPM/TOTP/HOTP Options -> Reset the TPM), then update checksums." 0 80
else
whiptail_error --title 'ERROR' \
--msgbox "Failed to update checksums / sign default config" 0 80
return 1
fi
return 1
fi
return 1
}
Expand Down Expand Up @@ -411,8 +419,13 @@ EOF
skip_to_menu="true"
return 1
;;
# "Reset the TPM" from the TOTP failure whiptail menu.
# The gate runs first to verify /boot integrity. If the gate
# fails *because* TPM reset is required (e.g. stale counters),
# the || tpm_reset_required bypass lets reset_tpm() proceed —
# it clears counters and creates a fresh one.
p)
if gate_reseal_with_integrity_report && reset_tpm && update_totp && BG_COLOR_MAIN_MENU="normal"; then
if { gate_reseal_with_integrity_report || tpm_reset_required; } && reset_tpm && update_totp && BG_COLOR_MAIN_MENU="normal"; then
reseal_tpm_disk_decryption_key || prompt_missing_gpg_key_action
fi
;;
Expand Down Expand Up @@ -806,8 +819,11 @@ show_tpm_totp_hotp_options_menu() {
update_totp && update_hotp || true
fi
;;
# "Reset the TPM" from the TPM/TOTP/HOTP options whiptail menu.
# Same gate-bypass pattern: if the gate fails because TPM
# reset is required, proceed to reset_tpm() anyway.
r)
if gate_reseal_with_integrity_report && reset_tpm; then
if { gate_reseal_with_integrity_report || tpm_reset_required; } && reset_tpm; then
reseal_tpm_disk_decryption_key || prompt_missing_gpg_key_action
fi
;;
Expand Down Expand Up @@ -837,7 +853,20 @@ reset_tpm() {
return 1
fi

tpmr.sh reset "$tpm_owner_passphrase"
# Verify TPM reset succeeded before proceeding to counter
# creation, signing, TOTP generation, and DUK resealing.
# A failed reset would leave the TPM in an inconsistent state
# (old passphrase with unknown PCRs), causing confusing errors
# downstream. Show the actual error to the user and return
# to the menu.
local reset_err_file=$(mktemp)
if ! tpmr.sh reset "$tpm_owner_passphrase" >"$reset_err_file" 2>&1; then
ERROR=$(tail -n 1 "$reset_err_file" | fold -s)
rm -f "$reset_err_file"
whiptail_error --title 'ERROR' \
--msgbox "Error resetting TPM:\n\n${ERROR}" 0 80
return 1
fi

# now that the TPM is reset, remove invalid TPM counter files
mount_boot
Expand Down
Loading