2017-07-03 03:01:04 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Sign a valid directory of kexec params
|
2017-07-12 04:17:45 +00:00
|
|
|
set -e -o pipefail
|
2018-12-06 23:24:28 +00:00
|
|
|
. /tmp/config
|
2017-07-03 03:01:04 +00:00
|
|
|
. /etc/functions
|
|
|
|
|
2017-07-08 20:59:37 +00:00
|
|
|
rollback="n"
|
|
|
|
update_counter="n"
|
|
|
|
while getopts "p:c:u" arg; do
|
|
|
|
case $arg in
|
|
|
|
p) paramsdir="$OPTARG" ;;
|
|
|
|
c) counter="$OPTARG"; rollback="y" ;;
|
|
|
|
u) update_counter="y"; rollback="y" ;;
|
|
|
|
esac
|
|
|
|
done
|
2017-07-03 03:01:04 +00:00
|
|
|
|
2017-07-08 20:59:37 +00:00
|
|
|
if [ -z "$paramsdir" ]; then
|
2017-07-17 16:43:14 +00:00
|
|
|
die "Usage: $0 -p /boot [ -u | -c counter ]"
|
2017-07-03 03:01:04 +00:00
|
|
|
fi
|
|
|
|
|
2017-07-22 18:25:39 +00:00
|
|
|
paramsdir="${paramsdir%%/}"
|
|
|
|
|
2017-07-04 23:49:14 +00:00
|
|
|
confirm_gpg_card
|
2017-07-03 03:01:04 +00:00
|
|
|
|
2017-07-08 20:59:37 +00:00
|
|
|
if [ "$rollback" = "y" ]; then
|
|
|
|
rollback_file="$paramsdir/kexec_rollback.txt"
|
|
|
|
|
|
|
|
if [ -n "$counter" ]; then
|
|
|
|
# use existing counter
|
|
|
|
read_tpm_counter $counter \
|
|
|
|
|| die "$paramsdir: Unable to read tpm counter '$counter'"
|
|
|
|
else
|
|
|
|
# increment counter
|
|
|
|
check_tpm_counter $rollback_file \
|
|
|
|
|| die "$paramsdir: Unable to find/create tpm counter"
|
|
|
|
counter="$TPM_COUNTER"
|
|
|
|
|
|
|
|
increment_tpm_counter $counter \
|
|
|
|
|| die "$paramsdir: Unable to increment tpm counter"
|
|
|
|
fi
|
|
|
|
|
|
|
|
sha256sum /tmp/counter-$counter > $rollback_file \
|
|
|
|
|| die "$paramsdir: Unable to create rollback file"
|
|
|
|
fi
|
|
|
|
|
|
|
|
param_files=`find $paramsdir/kexec*.txt`
|
|
|
|
if [ -z "$param_files" ]; then
|
|
|
|
die "$paramsdir: No kexec parameter files to sign"
|
|
|
|
fi
|
|
|
|
|
2017-07-03 03:01:04 +00:00
|
|
|
for tries in 1 2 3; do
|
2017-07-08 20:59:37 +00:00
|
|
|
if sha256sum $param_files | gpg \
|
2017-07-03 03:01:04 +00:00
|
|
|
--digest-algo SHA256 \
|
|
|
|
--detach-sign \
|
|
|
|
-a \
|
2017-07-08 20:59:37 +00:00
|
|
|
> $paramsdir/kexec.sig \
|
2017-07-03 03:01:04 +00:00
|
|
|
; then
|
2017-07-22 20:32:10 +00:00
|
|
|
# successful - update the validated params
|
|
|
|
check_config $paramsdir
|
2017-07-03 03:01:04 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2017-07-08 20:59:37 +00:00
|
|
|
die "$paramsdir: Unable to sign kexec hashes"
|