Make TPM dependency optional and controlled by flag CONFIG_TPM

if "CONFIG_TPM=y" is not present in the config file, functionalities
needing TPM could be disabled, while leaving other functionalities intact.

This will make Heads a more general-usage bootloader payload atop coreboot.
This commit is contained in:
persmule 2017-12-05 16:29:07 +08:00 committed by Francis Lam
parent ffa857d087
commit b5072390ee
No known key found for this signature in database
GPG Key ID: 0A59C698920806EB
5 changed files with 94 additions and 78 deletions

View File

@ -17,6 +17,7 @@ CONFIG_TPMTOTP=y
CONFIG_XEN=y
CONFIG_XEN_VERSION=4.8
CONFIG_DROPBEAR=y
CONFIG_TPM=y
CONFIG_LINUX_USB=y
CONFIG_LINUX_E1000E=y

View File

@ -1,6 +1,7 @@
#!/bin/sh
# Save these options to be the persistent default
set -e -o pipefail
. /etc/config
. /etc/functions
while getopts "b:d:p:i:" arg; do
@ -44,6 +45,7 @@ fi
KEY_DEVICES="$paramsdir/kexec_key_devices.txt"
KEY_LVM="$paramsdir/kexec_key_lvm.txt"
save_key="n"
if [ "$CONFIG_TPM" = "y" ]; then
if [ ! -r "$KEY_DEVICES" ]; then
read \
-n 1 \
@ -52,8 +54,7 @@ if [ ! -r "$KEY_DEVICES" ]; then
echo
if [ "$add_key_confirm" = "y" \
-o "$add_key_confirm" = "Y" ] \
; then
-o "$add_key_confirm" = "Y" ]; then
lvm_suggest="e.g. qubes_dom0 or blank"
devices_suggest="e.g. /dev/sda2 or blank"
save_key="y"
@ -66,15 +67,17 @@ else
echo
if [ "$change_key_confirm" = "y" \
-o "$change_key_confirm" = "Y" ] \
; then
-o "$change_key_confirm" = "Y" ]; then
old_lvm_volume_group=""
if [ -r "$KEY_LVM" ]; then
old_lvm_volume_group=`cat $KEY_LVM` || true
old_key_devices=`cat $KEY_DEVICES | cut -d\ -f1 \
| grep -v "$old_lvm_volume_group" | xargs` || true
old_key_devices=`cat $KEY_DEVICES \
| cut -d\ -f1 \
| grep -v "$old_lvm_volume_group" \
| xargs` || true
else
old_key_devices=`cat $KEY_DEVICES | cut -d\ -f1 | xargs` || true
old_key_devices=`cat $KEY_DEVICES \
| cut -d\ -f1 | xargs` || true
fi
lvm_suggest="was '$old_lvm_volume_group'"
@ -108,6 +111,7 @@ if [ "$save_key" = "y" ]; then
kexec-save-key $save_key_params \
|| die "Failed to save the disk key"
fi
fi
# try to switch to rw mode
mount -o rw,remount $paramsdev
@ -126,7 +130,11 @@ if [ ! -r $ENTRY_FILE -o ! -r $HASH_FILE ]; then
fi
# sign and auto-roll config counter
kexec-sign-config -p $paramsdir -u \
extparam=
if [ "$CONFIG_TPM" = "y" ]; then
extparam=-u
fi
kexec-sign-config -p $paramsdir $extparam \
|| die "Failed to sign default config"
# switch back to ro mode

View File

@ -232,7 +232,8 @@ do_boot()
die "!!! Missing required boot hashes"
fi
if [ -r "$TMP_KEY_DEVICES" ]; then
if [ "$CONFIG_TPM" = "y" \
-a -r "$TMP_KEY_DEVICES" ]; then
INITRD=`kexec-boot -b "$bootdir" -e "$option" -i` \
|| die "!!! Failed to extract the initrd from boot option"
if [ -z "$INITRD" ]; then
@ -261,7 +262,8 @@ while true; do
TMP_KEY_DEVICES="/tmp/kexec/kexec_key_devices.txt"
TMP_KEY_LVM="/tmp/kexec/kexec_key_lvm.txt"
if [ ! -r "$TMP_KEY_DEVICES" ]; then
if [ "$CONFIG_TPM" = "y" \
-a ! -r "$TMP_KEY_DEVICES" ]; then
# Extend PCR4 as soon as possible
tpm extend -ix 4 -ic generic \
|| die "Failed to extend PCR 4"
@ -272,6 +274,7 @@ while true; do
scan_options
fi
if [ "$CONFIG_TPM" = "y" ]; then
# Optionally enforce device file hashes
if [ -r "$TMP_HASH_FILE" ]; then
valid_global_hash="n"
@ -289,6 +292,7 @@ while true; do
verify_rollback_counter
fi
fi
if [ "$default_failed" != "y" \
-a "$force_menu" = "n" \

View File

@ -4,8 +4,10 @@
. /etc/functions
. /etc/config
if [ "$CONFIG_TPM" = "y" ]; then
# Extend PCR4 as soon as possible
tpm extend -ix 4 -ic usb
fi
usb-scan
recovery "Something failed during USB boot"

View File

@ -17,8 +17,9 @@ recovery() {
# but recreate the directory so that new tools can use it.
rm -rf /tmp/secret
mkdir -p /tmp/secret
if [ "$CONFIG_TPM" = y ]; then
tpm extend -ix 4 -ic recovery
fi
echo >&2 "!!!!! Starting recovery shell"
sleep 1
exec /bin/ash
@ -41,7 +42,7 @@ confirm_totp()
date=`date "+%Y-%m-%d %H:%M:%S"`
seconds=`date "+%s"`
half=`expr \( $seconds % 60 \) / 30`
if [ "$CONFIG_TPM" = n ]; then
if [ "$CONFIG_TPM" != y ]; then
TOTP="NO TPM"
elif [ "$half" != "$last_half" ]; then
last_half=$half;