2018-02-20 23:35:37 +00:00
#!/bin/sh
# Boot from a local disk installation
2020-10-23 22:18:20 +00:00
BOARD_NAME=${CONFIG_BOARD_NAME:-${CONFIG_BOARD}}
MAIN_MENU_TITLE="${BOARD_NAME} | Heads Boot Menu"
2021-09-23 17:56:17 +00:00
export BG_COLOR_MAIN_MENU=""
2018-02-21 23:58:54 +00:00
2018-02-20 23:35:37 +00:00
. /etc/functions
2022-04-06 21:25:40 +00:00
. /etc/luks-functions
2018-12-06 23:24:28 +00:00
. /tmp/config
2018-02-20 23:35:37 +00:00
2022-11-23 18:55:09 +00:00
# skip_to_menu is set if the user selects "continue to the main menu" from any
# error, so we will indeed go to the main menu even if other errors occur. It's
# reset when we reach the main menu so the user can retry from the main menu and
# # see errors again.
skip_to_menu="false"
2018-02-20 23:35:37 +00:00
mount_boot()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:mount_boot"
2018-02-23 20:13:21 +00:00
# Mount local disk if it is not already mounted
2019-07-08 01:47:04 +00:00
while ! grep -q /boot /proc/mounts ; do
2020-10-23 23:35:39 +00:00
# try to mount if CONFIG_BOOT_DEV exists
if [ -e "$CONFIG_BOOT_DEV" ]; then
mount -o ro $CONFIG_BOOT_DEV /boot
[[ $? -eq 0 ]] && continue
2019-07-08 01:47:04 +00:00
fi
2020-10-23 23:35:39 +00:00
# CONFIG_BOOT_DEV doesn't exist or couldn't be mounted, so give user options
2021-09-23 17:56:17 +00:00
BG_COLOR_MAIN_MENU=$BG_COLOR_ERROR
2022-11-15 20:11:58 +00:00
whiptail $BG_COLOR_ERROR --title "ERROR: No Bootable OS Found!" \
2020-10-23 23:35:39 +00:00
--menu " No bootable OS was found on the default boot device $CONFIG_BOOT_DEV.
2022-11-09 16:51:27 +00:00
How would you like to proceed?" 0 80 4 \
2020-10-23 23:35:39 +00:00
'b' ' Select a new boot device' \
'u' ' Boot from USB' \
'm' ' Continue to the main menu' \
'x' ' Exit to recovery shell' \
2>/tmp/whiptail || recovery "GUI menu failed"
option=$(cat /tmp/whiptail)
case "$option" in
b )
2019-07-09 03:27:40 +00:00
config-gui.sh boot_device_select
2020-10-23 23:35:39 +00:00
if [ $? -eq 0 ]; then
# update CONFIG_BOOT_DEV
. /tmp/config
2021-09-23 17:56:17 +00:00
BG_COLOR_MAIN_MENU=""
2020-10-23 23:35:39 +00:00
fi
;;
u )
exec /bin/usb-init
;;
m )
2022-11-23 18:55:09 +00:00
skip_to_menu="true"
2020-10-23 23:35:39 +00:00
break
;;
* )
recovery "User requested recovery shell"
;;
esac
2019-07-08 01:47:04 +00:00
done
2018-02-20 23:35:37 +00:00
}
2021-09-22 16:42:07 +00:00
2018-04-03 22:20:34 +00:00
verify_global_hashes()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:verify_global_hashes"
2018-04-03 22:20:34 +00:00
# Check the hashes of all the files, ignoring signatures for now
check_config /boot force
TMP_HASH_FILE="/tmp/kexec/kexec_hashes.txt"
2022-12-31 17:41:24 +00:00
TMP_TREE_FILE="/tmp/kexec/kexec_tree.txt"
2018-04-03 22:20:34 +00:00
TMP_PACKAGE_TRIGGER_PRE="/tmp/kexec/kexec_package_trigger_pre.txt"
TMP_PACKAGE_TRIGGER_POST="/tmp/kexec/kexec_package_trigger_post.txt"
2022-12-31 17:41:24 +00:00
if verify_checksums /boot ; then
2018-04-03 22:20:34 +00:00
return 0
2022-12-31 17:41:24 +00:00
elif [[ ! -f "$TMP_HASH_FILE" || ! -f "$TMP_TREE_FILE" ]] ; then
2023-01-08 13:01:12 +00:00
if (whiptail $BG_COLOR_ERROR --title 'ERROR: Missing File!' \
--yesno "One of the files containing integrity information for /boot is missing!\n\nIf you are setting up heads for the first time or upgrading from an\nolder version, select Yes to create the missing files.\n\nOtherwise this could indicate a compromise and you should select No to\nreturn to the main menu.\n\nWould you like to create the missing files now?" 0 80) then
2021-09-24 20:05:14 +00:00
if update_checksums ; then
BG_COLOR_MAIN_MENU=""
return 0;
else
whiptail $BG_COLOR_ERROR --title 'ERROR' \
2022-11-09 16:51:27 +00:00
--msgbox "Failed to update checksums / sign default config" 0 80
2021-09-24 20:05:14 +00:00
fi
2018-04-03 22:20:34 +00:00
fi
2021-09-23 17:56:17 +00:00
BG_COLOR_MAIN_MENU=$BG_COLOR_ERROR
2018-04-03 22:20:34 +00:00
return 1
else
2021-10-29 18:26:02 +00:00
CHANGED_FILES=$(grep -v 'OK$' /tmp/hash_output | cut -f1 -d ':' | tee -a /tmp/hash_output_mismatches)
CHANGED_FILES_COUNT=$(wc -l /tmp/hash_output_mismatches | cut -f1 -d ' ')
2018-04-03 22:20:34 +00:00
# if files changed before package manager started, show stern warning
if [ -f "$TMP_PACKAGE_TRIGGER_PRE" ]; then
PRE_CHANGED_FILES=$(grep '^CHANGED_FILES' $TMP_PACKAGE_TRIGGER_POST | cut -f 2 -d '=' | tr -d '"')
2018-05-01 21:23:56 +00:00
TEXT="The following files failed the verification process BEFORE package updates ran:\n${PRE_CHANGED_FILES}\n\nCompare against the files Heads has detected have changed:\n${CHANGED_FILES}\n\nThis could indicate a compromise!\n\nWould you like to update your checksums anyway?"
2018-04-03 22:20:34 +00:00
# if files changed after package manager started, probably caused by package manager
elif [ -f "$TMP_PACKAGE_TRIGGER_POST" ]; then
LAST_PACKAGE_LIST=$(grep -E "^(Install|Remove|Upgrade|Reinstall):" $TMP_PACKAGE_TRIGGER_POST)
UPDATE_INITRAMFS_PACKAGE=$(grep '^UPDATE_INITRAMFS_PACKAGE' $TMP_PACKAGE_TRIGGER_POST | cut -f 2 -d '=' | tr -d '"')
if [ "$UPDATE_INITRAMFS_PACKAGE" != "" ]; then
TEXT="The following files failed the verification process AFTER package updates ran:\n${CHANGED_FILES}\n\nThis is likely due to package triggers in$UPDATE_INITRAMFS_PACKAGE.\n\nYou will need to update your checksums for all files in /boot.\n\nWould you like to update your checksums now?"
else
TEXT="The following files failed the verification process AFTER package updates ran:\n${CHANGED_FILES}\n\nThis might be due to the following package updates:\n$LAST_PACKAGE_LIST.\n\nYou will need to update your checksums for all files in /boot.\n\nWould you like to update your checksums now?"
fi
else
2021-10-29 18:26:02 +00:00
if [ $CHANGED_FILES_COUNT -gt 10 ]; then
# drop to console to show full file list
whiptail $ERROR_BG_COLOR --title 'ERROR: Boot Hash Mismatch' \
--msgbox "${CHANGED_FILES_COUNT} files failed the verification process!\\n\nThis could indicate a compromise!\n\nHit OK to review the list of files.\n\nType \"q\" to exit the list and return." 16 60
echo "Type \"q\" to exit the list and return." >> /tmp/hash_output_mismatches
less /tmp/hash_output_mismatches
#move outdated hash mismatch list
mv /tmp/hash_output_mismatches /tmp/hash_output_mismatch_old
TEXT="Would you like to update your checksums now?"
else
TEXT="The following files failed the verification process:\n\n${CHANGED_FILES}\n\nThis could indicate a compromise!\n\nWould you like to update your checksums now?"
fi
2018-04-03 22:20:34 +00:00
fi
2022-11-15 20:11:58 +00:00
if (whiptail $BG_COLOR_ERROR --title 'ERROR: Boot Hash Mismatch' --yesno "$TEXT" 0 80) then
2021-09-24 20:05:14 +00:00
if update_checksums ; then
BG_COLOR_MAIN_MENU=""
return 0;
else
whiptail $BG_COLOR_ERROR --title 'ERROR' \
2022-11-09 16:51:27 +00:00
--msgbox "Failed to update checksums / sign default config" 0 80
2021-09-24 20:05:14 +00:00
fi
2018-04-03 22:20:34 +00:00
fi
2021-09-23 17:56:17 +00:00
BG_COLOR_MAIN_MENU=$BG_COLOR_ERROR
2018-04-03 22:20:34 +00:00
return 1
fi
}
2021-09-22 16:42:07 +00:00
2019-07-05 22:04:00 +00:00
prompt_update_checksums()
2018-04-03 22:20:34 +00:00
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:prompt_update_checksums"
2021-09-23 17:56:17 +00:00
if (whiptail $BG_COLOR_WARNING --title 'Update Checksums and sign all files in /boot' \
2022-11-09 16:51:27 +00:00
--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
2021-09-24 20:05:14 +00:00
if ! update_checksums ; then
whiptail $BG_COLOR_ERROR --title 'ERROR' \
2022-11-09 16:51:27 +00:00
--msgbox "Failed to update checksums / sign default config" 0 80
2021-09-24 20:05:14 +00:00
fi
2018-04-03 22:20:34 +00:00
fi
}
2021-09-22 16:42:07 +00:00
2021-09-22 16:32:19 +00:00
generate_totp_htop()
2018-06-19 19:27:27 +00:00
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:generate_totp_htop"
2018-06-19 19:27:27 +00:00
echo "Scan the QR code to add the new TOTP secret"
2023-01-19 19:58:21 +00:00
if /bin/seal-totp "$BOARD_NAME"; then
if [ -x /bin/hotp_verification ]; then
echo "Once you have scanned the QR code, hit Enter to configure your HOTP USB Security Dongle (e.g. Librem Key or Nitrokey)"
read
/bin/seal-hotpkey
else
echo "Once you have scanned the QR code, hit Enter to continue"
read
fi
# clear screen
printf "\033c"
2018-06-19 19:27:27 +00:00
else
2023-01-19 19:58:21 +00:00
warn "Sealing of measurements inside of TPM failed. You might want to take ownership of TPM by resetting it."
2018-06-19 19:27:27 +00:00
fi
}
2018-02-20 23:35:37 +00:00
2021-09-22 17:17:04 +00:00
update_totp()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:update_totp"
2021-09-27 19:22:45 +00:00
# update the TOTP code
2022-03-23 20:02:59 +00:00
date=`date "+%Y-%m-%d %H:%M:%S %Z"`
2021-09-22 17:17:04 +00:00
if [ "$CONFIG_TPM" = n ]; then
TOTP="NO TPM"
2021-09-27 19:22:45 +00:00
else
2021-09-22 17:17:04 +00:00
TOTP=`unseal-totp`
if [ $? -ne 0 ]; then
2021-09-23 17:56:17 +00:00
BG_COLOR_MAIN_MENU=$BG_COLOR_ERROR
2022-11-23 18:55:09 +00:00
if [ "$skip_to_menu" = "true" ]; then
return 1 # Already asked to skip to menu from a prior error
fi
2022-08-25 18:43:31 +00:00
echo "DEBUG: CONFIG_TPM: $CONFIG_TPM"
echo "DEBUG: CONFIG_TPM2_TOOLS: $CONFIG_TPM2_TOOLS"
echo "DEBUG: Show PCRs"
pcrs
2022-11-15 20:11:58 +00:00
whiptail $BG_COLOR_ERROR --title "ERROR: TOTP Generation Failed!" \
2021-09-22 17:17:04 +00:00
--menu " ERROR: Heads couldn't generate the TOTP code.\n
If you have just completed a Factory Reset, or just reflashed
your BIOS, you should generate a new HOTP/TOTP secret.\n
If this is the first time the system has booted, you should
reset the TPM and set your own password.\n
If you have not just reflashed your BIOS, THIS COULD INDICATE TAMPERING!\n
2022-11-09 16:51:27 +00:00
How would you like to proceed?" 0 80 4 \
2021-09-22 17:17:04 +00:00
'g' ' Generate new HOTP/TOTP secret' \
'i' ' Ignore error and continue to main menu' \
'p' ' Reset the TPM' \
'x' ' Exit to recovery shell' \
2>/tmp/whiptail || recovery "GUI menu failed"
2021-09-23 17:07:28 +00:00
option=$(cat /tmp/whiptail)
case "$option" in
g )
2021-09-23 17:56:17 +00:00
if (whiptail $BG_COLOR_WARNING --title 'Generate new TOTP/HOTP secret' \
2022-11-09 16:51:27 +00:00
--yesno "This will erase your old secret and replace it with a new one!\n\nDo you want to proceed?" 0 80) then
2021-09-29 21:32:18 +00:00
generate_totp_htop && update_totp && BG_COLOR_MAIN_MENU=""
2021-09-23 17:07:28 +00:00
fi
;;
i )
2022-11-23 18:55:09 +00:00
skip_to_menu="true"
2021-09-23 17:07:28 +00:00
return 1
;;
p )
2021-09-29 21:32:18 +00:00
reset_tpm && update_totp && BG_COLOR_MAIN_MENU=""
2021-09-23 17:07:28 +00:00
;;
x )
recovery "User requested recovery shell"
;;
esac
2021-09-22 17:17:04 +00:00
fi
fi
}
update_hotp()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:update_hotp"
2021-09-22 17:17:04 +00:00
if [ -x /bin/hotp_verification ]; then
HOTP=`unseal-hotp`
if ! hotp_verification info ; then
2022-11-23 18:55:09 +00:00
if [ "$skip_to_menu" = "true" ]; then
return 1 # Already asked to skip to menu from a prior error
fi
2022-11-15 20:11:58 +00:00
if ! whiptail $BG_COLOR_WARNING \
2021-09-27 19:21:38 +00:00
--title "WARNING: Please Insert Your $HOTPKEY_BRANDING" \
--yes-button "Retry" --no-button "Skip" \
2022-11-09 16:51:27 +00:00
--yesno "Your $HOTPKEY_BRANDING was not detected.\n\nPlease insert your $HOTPKEY_BRANDING" 0 80 ; then
2021-09-27 19:21:38 +00:00
HOTP="Error checking code, Insert $HOTPKEY_BRANDING and retry"
BG_COLOR_MAIN_MENU=$BG_COLOR_WARNING
return
2021-09-22 17:17:04 +00:00
fi
2021-09-27 19:21:38 +00:00
fi
2021-09-22 17:17:04 +00:00
# Don't output HOTP codes to screen, so as to make replay attacks harder
2022-11-23 18:55:09 +00:00
hotp_verification check "$HOTP"
2021-09-22 17:17:04 +00:00
case "$?" in
0 )
HOTP="Success"
2021-09-23 17:56:17 +00:00
BG_COLOR_MAIN_MENU=""
2021-09-22 17:17:04 +00:00
;;
2022-11-23 18:55:09 +00:00
4|7 ) # 4: code was incorrect, 7: code was not a valid HOTP code at all
2021-09-22 17:17:04 +00:00
HOTP="Invalid code"
2021-09-23 17:56:17 +00:00
BG_COLOR_MAIN_MENU=$BG_COLOR_ERROR
2021-09-22 17:17:04 +00:00
;;
* )
HOTP="Error checking code, Insert $HOTPKEY_BRANDING and retry"
2021-09-23 17:56:17 +00:00
BG_COLOR_MAIN_MENU=$BG_COLOR_WARNING
2021-09-22 17:17:04 +00:00
;;
esac
else
HOTP='N/A'
fi
}
2019-08-19 22:09:42 +00:00
clean_boot_check()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:mount_boot"
2019-08-19 22:09:42 +00:00
# assume /boot mounted
if ! grep -q /boot /proc/mounts ; then
return
fi
# check for any kexec files in /boot
kexec_files=`find /boot -name kexec*.txt`
[ ! -z "$kexec_files" ] && return
#check for GPG key in keyring
GPG_KEY_COUNT=`gpg -k 2>/dev/null | wc -l`
[ $GPG_KEY_COUNT -ne 0 ] && return
# check for USB security token
2022-03-03 23:42:28 +00:00
if [ -x /bin/hotp_verification ]; then
2020-02-19 22:27:57 +00:00
if ! gpg --card-status > /dev/null ; then
return
fi
2019-08-19 22:09:42 +00:00
fi
# OS is installed, no kexec files present, no GPG keys in keyring, security token present
# prompt user to run OEM factory reset
oem-factory-reset \
2022-03-10 14:55:08 +00:00
"Clean Boot Detected - Perform OEM Factory Reset / Re-Ownership?" "$BG_COLOR_WARNING"
2019-08-19 22:09:42 +00:00
}
2021-09-22 17:17:04 +00:00
check_gpg_key()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:check_gpg_key"
2021-09-22 17:17:04 +00:00
GPG_KEY_COUNT=`gpg -k 2>/dev/null | wc -l`
if [ $GPG_KEY_COUNT -eq 0 ]; then
2021-09-23 17:56:17 +00:00
BG_COLOR_MAIN_MENU=$BG_COLOR_ERROR
2022-11-23 18:55:09 +00:00
if [ "$skip_to_menu" = "true" ]; then
return 1 # Already asked to skip to menu from a prior error
fi
2022-11-15 20:11:58 +00:00
whiptail $BG_COLOR_ERROR --title "ERROR: GPG keyring empty!" \
2022-11-09 16:51:27 +00:00
--menu "ERROR: Heads couldn't find any GPG keys in your keyring.\n\nIf this is the first time the system has booted,\nyou should add a public GPG key to the BIOS now.\n\nIf you just reflashed a new BIOS, you'll need to add at least one\npublic key to the keyring.\n\nIf you have not just reflashed your BIOS, THIS COULD INDICATE TAMPERING!\n\nHow would you like to proceed?" 0 80 4 \
2021-09-23 17:07:28 +00:00
'g' ' Add a GPG key to the running BIOS' \
2022-03-23 19:50:58 +00:00
'F' ' OEM Factory Reset / Re-Ownership' \
2021-09-22 17:17:04 +00:00
'i' ' Ignore error and continue to main menu' \
'x' ' Exit to recovery shell' \
2>/tmp/whiptail || recovery "GUI menu failed"
2021-09-23 17:07:28 +00:00
option=$(cat /tmp/whiptail)
case "$option" in
g )
2021-09-23 17:56:17 +00:00
gpg-gui.sh && BG_COLOR_MAIN_MENU=""
2021-09-23 17:07:28 +00:00
;;
i )
2022-11-23 18:55:09 +00:00
skip_to_menu="true"
2021-09-23 17:07:28 +00:00
return 1
;;
2022-03-23 19:50:58 +00:00
F )
oem-factory-reset
;;
2021-09-23 17:07:28 +00:00
x )
recovery "User requested recovery shell"
;;
esac
2021-09-22 17:17:04 +00:00
fi
}
prompt_auto_default_boot()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:prompt_auto_default_boot"
2021-09-22 17:17:04 +00:00
# save IFS before changing, restore after read
IFS_DEF=$IFS
IFS=''
first_pass=false
echo -e "\nHOTP verification success\n\n"
read -t $CONFIG_AUTO_BOOT_TIMEOUT -s -n 1 -p "Automatic boot in $CONFIG_AUTO_BOOT_TIMEOUT seconds unless interrupted by keypress... "
if [[ $? -ne 0 ]]; then
IFS=$IFS_DEF
echo -e "\n\nAttempting default boot...\n\n"
2021-09-23 17:07:28 +00:00
attempt_default_boot
2021-09-22 17:17:04 +00:00
fi
IFS=$IFS_DEF
}
show_main_menu()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:show_main_menu"
2022-03-23 20:02:59 +00:00
date=`date "+%Y-%m-%d %H:%M:%S %Z"`
2022-11-15 20:11:58 +00:00
whiptail $BG_COLOR_MAIN_MENU --title "$MAIN_MENU_TITLE" \
2022-11-09 16:51:27 +00:00
--menu "$date\nTOTP: $TOTP | HOTP: $HOTP" 0 80 10 \
2021-09-23 17:07:28 +00:00
'd' ' Default boot' \
2021-09-22 17:17:04 +00:00
'r' ' Refresh TOTP/HOTP' \
2021-09-23 17:07:28 +00:00
'o' ' Options -->' \
's' ' System Info' \
'p' ' Power Off' \
2021-09-22 17:17:04 +00:00
2>/tmp/whiptail || recovery "GUI menu failed"
2021-09-23 17:07:28 +00:00
option=$(cat /tmp/whiptail)
case "$option" in
d )
attempt_default_boot
;;
r )
2022-11-23 18:55:09 +00:00
update_totp
update_hotp
2021-09-23 17:07:28 +00:00
;;
o )
show_options_menu
;;
s )
show_system_info
;;
p )
poweroff
;;
esac
2021-09-22 17:17:04 +00:00
}
show_options_menu()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:show_options_menu"
2022-11-15 20:11:58 +00:00
whiptail $BG_COLOR_MAIN_MENU --title "HEADS Options" \
2022-11-09 16:51:27 +00:00
--menu "" 0 80 10 \
2021-09-23 17:07:28 +00:00
'b' ' Boot Options -->' \
2021-09-22 17:17:04 +00:00
't' ' TPM/TOTP/HOTP Options -->' \
2021-09-23 17:07:28 +00:00
'u' ' Update checksums and sign all files in /boot' \
2021-09-22 17:17:04 +00:00
'c' ' Change configuration settings -->' \
'f' ' Flash/Update the BIOS -->' \
2021-09-23 17:07:28 +00:00
'g' ' GPG Options -->' \
2022-03-10 14:55:08 +00:00
'F' ' OEM Factory Reset / Re-Ownership -->' \
2022-03-23 19:50:58 +00:00
'R' ' Reencrypt LUKS container -->' \
'C' ' Change LUKS Disk Recovery Key passphrase ->' \
2021-09-22 17:17:04 +00:00
'x' ' Exit to recovery shell' \
'r' ' <-- Return to main menu' \
2>/tmp/whiptail || recovery "GUI menu failed"
2021-09-23 17:07:28 +00:00
option=$(cat /tmp/whiptail)
case "$option" in
b )
show_boot_options_menu
;;
t )
show_tpm_totp_hotp_options_menu
;;
u )
prompt_update_checksums
;;
c )
config-gui.sh
;;
f )
flash-gui.sh
;;
g )
gpg-gui.sh
;;
F )
oem-factory-reset
;;
2022-03-23 19:50:58 +00:00
R )
luks_reencrypt
luks_secrets_cleanup
;;
C )
luks_change_passphrase
luks_secrets_cleanup
;;
2021-09-23 17:07:28 +00:00
x )
recovery "User requested recovery shell"
;;
r )
;;
esac
2021-09-22 17:17:04 +00:00
}
show_boot_options_menu()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:show_boot_options_menu"
2022-11-15 20:11:58 +00:00
whiptail $BG_COLOR_MAIN_MENU --title "Boot Options" \
2022-11-09 16:51:27 +00:00
--menu "Select A Boot Option" 0 80 10 \
2021-09-22 17:17:04 +00:00
'm' ' Show OS boot menu' \
'u' ' USB boot' \
'i' ' Ignore tampering and force a boot (Unsafe!)' \
'r' ' <-- Return to main menu' \
2>/tmp/whiptail || recovery "GUI menu failed"
2021-09-23 17:07:28 +00:00
option=$(cat /tmp/whiptail)
case "$option" in
m )
# select a kernel from the menu
select_os_boot_option
;;
u )
exec /bin/usb-init
;;
i )
force_unsafe_boot
;;
r )
;;
esac
2021-09-22 17:17:04 +00:00
}
show_tpm_totp_hotp_options_menu()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:show_tpm_totp_hotp_options_menu"
2022-11-15 20:11:58 +00:00
whiptail $BG_COLOR_MAIN_MENU --title "TPM/TOTP/HOTP Options" \
2022-11-09 16:51:27 +00:00
--menu "Select An Option" 0 80 10 \
2021-09-22 17:17:04 +00:00
'g' ' Generate new TOTP/HOTP secret' \
2021-09-23 17:07:28 +00:00
'r' ' Reset the TPM' \
't' ' TOTP/HOTP does not match after refresh, troubleshoot' \
'm' ' <-- Return to main menu' \
2021-09-22 17:17:04 +00:00
2>/tmp/whiptail || recovery "GUI menu failed"
2021-09-23 17:07:28 +00:00
option=$(cat /tmp/whiptail)
case "$option" in
g )
generate_totp_htop
;;
r )
reset_tpm
;;
t )
prompt_totp_mismatch
;;
m )
;;
esac
2021-09-22 17:17:04 +00:00
}
prompt_totp_mismatch()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:prompt_totp_mismatch"
2021-09-22 17:17:04 +00:00
if (whiptail $BG_COLOR_WARNING --title "TOTP/HOTP code mismatched" \
2023-01-04 21:07:38 +00:00
--yesno "TOTP/HOTP code mismatches could indicate either TPM tampering or clock drift:\n\nTo correct clock drift: 'date -s yyyy-MM-DD hh:mm:ss' in UTC timezone\nand save it to the RTC: 'hwclock -w'\nthen reboot and try again.\n\nWould you like to exit to a recovery console?" 0 80) then
2021-09-22 17:17:04 +00:00
echo ""
2023-01-04 21:07:38 +00:00
echo "To correct clock drift: 'date -s yyyy-MM-DD hh:mm:ss' in UTC timezone"
2021-09-22 17:17:04 +00:00
echo "and save it to the RTC: 'hwclock -w'"
2023-01-04 21:07:38 +00:00
echo ""
echo "Alternatively you could do this automatically with an Ethernet cable connected to a functional network: 'network-init-recovery'"
echo ""
echo "Then reboot and try again"
2021-09-22 17:17:04 +00:00
echo ""
recovery "TOTP/HOTP mismatch"
fi
}
reset_tpm()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:reset_tpm"
2022-08-25 18:43:31 +00:00
if [ "$CONFIG_TPM" = "y" -o "$CONFIG_TPM2_TOOLS" = "y" ]; then
2021-09-23 17:56:17 +00:00
if (whiptail $BG_COLOR_WARNING --title 'Reset the TPM' \
2022-11-09 16:51:27 +00:00
--yesno "This will clear the TPM and TPM password, replace them with new ones!\n\nDo you want to proceed?" 0 80) then
2021-09-22 17:17:04 +00:00
/bin/tpm-reset
# now that the TPM is reset, remove invalid TPM counter files
mount_boot
mount -o rw,remount /boot
rm -f /boot/kexec_rollback.txt
# create Heads TPM counter before any others
check_tpm_counter /boot/kexec_rollback.txt \
|| die "Unable to find/create tpm counter"
counter="$TPM_COUNTER"
increment_tpm_counter $counter \
|| die "Unable to increment tpm counter"
sha256sum /tmp/counter-$counter > /boot/kexec_rollback.txt \
|| die "Unable to create rollback file"
mount -o ro,remount /boot
generate_totp_htop
else
echo "Returning to the main menu"
fi
else
2022-11-15 20:11:58 +00:00
whiptail $BG_COLOR_ERROR --title 'ERROR: No TPM Detected' --msgbox "This device does not have a TPM.\n\nPress OK to return to the Main Menu" 0 80
2021-09-22 17:17:04 +00:00
fi
}
show_system_info()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:show_system_info"
2021-10-19 18:48:03 +00:00
battery_charge="$(print_battery_charge)"
battery_health="$(print_battery_health)"
if [ -n $battery_charge -a -n $battery_health ];then
battery_status="\nBattery charge: $battery_charge%\nBattery health: $battery_health%\n"
fi
2021-09-22 17:17:04 +00:00
memtotal=$(cat /proc/meminfo | grep 'MemTotal' | tr -s ' ' | cut -f2 -d ' ')
memtotal=$((${memtotal} / 1024 / 1024 + 1))
cpustr=$(cat /proc/cpuinfo | grep 'model name' | uniq | sed -r 's/\(R\)//;s/\(TM\)//;s/CPU //;s/model name.*: //')
kernel=$(uname -s -r)
2021-10-19 18:48:03 +00:00
2021-09-23 17:56:17 +00:00
whiptail $BG_COLOR_MAIN_MENU --title 'System Info' \
2021-10-19 18:48:03 +00:00
--msgbox "${BOARD_NAME}\n\nFW_VER: ${FW_VER}\nKernel: ${kernel}\n\nCPU: ${cpustr}\nRAM: ${memtotal} GB\n$battery_status\n$(fdisk -l | grep -e '/dev/sd.:' -e '/dev/nvme.*:' | sed 's/B,.*/B/')" 16 60
2021-09-22 17:17:04 +00:00
}
select_os_boot_option()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:select_os_boot_option"
2021-09-22 17:17:04 +00:00
mount_boot
if verify_global_hashes ; then
kexec-select-boot -m -b /boot -c "grub.cfg" -g
fi
}
attempt_default_boot()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:attempt_default_boot"
2021-09-22 17:17:04 +00:00
mount_boot
if ! verify_global_hashes; then
return
fi
DEFAULT_FILE=`find /boot/kexec_default.*.txt 2>/dev/null | head -1`
if [ -r "$DEFAULT_FILE" ]; then
kexec-select-boot -b /boot -c "grub.cfg" -g \
|| recovery "Failed default boot"
2021-09-23 17:56:17 +00:00
elif (whiptail $BG_COLOR_WARNING --title 'No Default Boot Option Configured' \
2022-11-09 16:51:27 +00:00
--yesno "There is no default boot option configured yet.\nWould you like to load a menu of boot options?\nOtherwise you will return to the main menu." 0 80) then
2021-09-22 17:17:04 +00:00
kexec-select-boot -m -b /boot -c "grub.cfg" -g
fi
}
force_unsafe_boot()
{
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init:force_unsafe_boot"
2021-09-22 17:17:04 +00:00
# Run the menu selection in "force" mode, bypassing hash checks
if (whiptail $BG_COLOR_WARNING --title 'Unsafe Forced Boot Selected!' \
2022-11-09 16:51:27 +00:00
--yesno "WARNING: You have chosen to skip all tamper checks and boot anyway.\n\nThis is an unsafe option!\n\nDo you want to proceed?" 0 80) then
2021-09-22 17:17:04 +00:00
mount_boot && kexec-select-boot -m -b /boot -c "grub.cfg" -g -f
fi
}
# gui-init start
2023-02-20 16:01:17 +00:00
TRACE "Under /bin/gui-init, start"
2021-09-22 17:17:04 +00:00
2021-09-23 18:20:25 +00:00
# Use stored HOTP key branding
if [ -r /boot/kexec_hotp_key ]; then
HOTPKEY_BRANDING="$(cat /boot/kexec_hotp_key)"
else
HOTPKEY_BRANDING="HOTP USB Security Dongle"
fi
2022-03-03 23:42:28 +00:00
if [ -x /bin/hotp_verification ]; then
2022-03-01 02:03:26 +00:00
enable_usb
fi
2019-08-19 22:09:42 +00:00
if detect_boot_device ; then
# /boot device with installed OS found
clean_boot_check
else
# can't determine /boot device or no OS installed,
# so fall back to interactive selection
mount_boot
fi
2019-05-27 16:45:09 +00:00
2021-09-23 17:13:40 +00:00
# detect whether any GPG keys exist in the keyring, if not, initialize that first
2022-11-23 18:55:09 +00:00
check_gpg_key
# Even if GPG init fails, still try to update TOTP/HOTP so the main menu can
# show the correct status.
update_totp
update_hotp
2018-02-23 20:13:21 +00:00
2023-02-18 20:52:32 +00:00
if [ "$HOTP" = "Success" -a -n "$CONFIG_AUTO_BOOT_TIMEOUT" ]; then
2021-09-23 17:13:40 +00:00
prompt_auto_default_boot
fi
2018-02-20 23:35:37 +00:00
2021-09-23 17:13:40 +00:00
while true; do
2023-02-20 16:01:17 +00:00
TRACE "Under gui-init:while true loop"
2022-11-23 18:55:09 +00:00
skip_to_menu="false"
2021-09-23 17:07:28 +00:00
show_main_menu
2018-02-20 23:35:37 +00:00
done
recovery "Something failed during boot"