Skip to content

Commit c1ed061

Browse files
authored
Merge pull request #2114 from tlaurion/gpg_inject_on_clean_firmware_flash
initrd/etc/gpg_functions.sh: check flash.sh exit status before reboot
2 parents dc0cd70 + e0f0fea commit c1ed061

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

initrd/bin/gui-init.sh

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export BG_COLOR_MAIN_MENU="normal"
77

88
. /etc/functions.sh
99
. /etc/gui_functions.sh
10+
. /etc/gpg_functions.sh
1011
. /etc/luks-functions.sh
1112
. /tmp/config
1213

@@ -427,12 +428,16 @@ EOF
427428
return 1
428429
;;
429430
# "Reset the TPM" from the TOTP failure whiptail menu.
430-
# The gate runs first to verify /boot integrity. If the gate
431-
# fails *because* TPM reset is required (e.g. stale counters),
432-
# the || tpm_reset_required bypass lets reset_tpm() proceed —
433-
# it clears counters and creates a fresh one.
431+
# Show the integrity report so the user can see the state,
432+
# but do not force the investigation / signing path —
433+
# that would attempt TPM counter operations requiring the
434+
# current owner password, which is unknown (that is why
435+
# we are resetting). reset_tpm() handles everything:
436+
# new password, counter create, /boot signing, TOTP/HOTP
437+
# generation, DUK reseal, and reboot.
434438
p)
435-
if { gate_reseal_with_integrity_report || tpm_reset_required; } && reset_tpm && update_totp && BG_COLOR_MAIN_MENU="normal"; then
439+
report_integrity_measurements
440+
if reset_tpm && update_totp && BG_COLOR_MAIN_MENU="normal"; then
436441
reseal_tpm_disk_decryption_key || prompt_missing_gpg_key_action
437442
fi
438443
;;
@@ -829,10 +834,16 @@ show_tpm_totp_hotp_options_menu() {
829834
fi
830835
;;
831836
# "Reset the TPM" from the TPM/TOTP/HOTP options whiptail menu.
832-
# Same gate-bypass pattern: if the gate fails because TPM
833-
# reset is required, proceed to reset_tpm() anyway.
837+
# Show the integrity report so the user can see the state,
838+
# but do not force the investigation / signing path —
839+
# that would attempt TPM counter operations requiring the
840+
# current owner password, which is unknown (that is why
841+
# we are resetting). reset_tpm() handles everything:
842+
# new password, counter create, /boot signing, TOTP/HOTP
843+
# generation, DUK reseal, and reboot.
834844
r)
835-
if { gate_reseal_with_integrity_report || tpm_reset_required; } && reset_tpm; then
845+
report_integrity_measurements
846+
if reset_tpm; then
836847
reseal_tpm_disk_decryption_key || prompt_missing_gpg_key_action
837848
fi
838849
;;
@@ -942,6 +953,7 @@ reset_tpm() {
942953
if [ -s /boot/kexec_key_devices.txt ] || [ -s /boot/kexec_key_lvm.txt ]; then
943954
reseal_tpm_disk_decryption_key || prompt_missing_gpg_key_action
944955
fi
956+
/bin/reboot.sh
945957
fi
946958
fi
947959
}

initrd/etc/gpg_functions.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ gpg_flash_rom() {
4444
if [ -e /etc/config.user ]; then
4545
cbfs.sh -o /tmp/gpg-gui.rom -a "heads/initrd/etc/config.user" -f /etc/config.user
4646
fi
47-
/bin/flash.sh /tmp/gpg-gui.rom
47+
if /bin/flash.sh /tmp/gpg-gui.rom; then
48+
whiptail_type $BG_COLOR_MAIN_MENU --title 'ROM Flashed Successfully' \
49+
--msgbox "The GPG key has been added and the BIOS flashed successfully.\n\nPress Enter to reboot" 0 80
50+
/bin/reboot.sh
51+
else
52+
whiptail_error --title 'ROM Flash Failed' \
53+
--msgbox "Failed to flash the BIOS.\n\nYour system may be in an inconsistent state." 0 80
54+
fi
4855
}
4956

5057
gpg_post_gen_mgmt() {

0 commit comments

Comments
 (0)