#!/usr/bin/env bash # SPDX-License-Identifier: LGPL-2.1-or-later set -eux set -o pipefail # shellcheck source=test/units/util.sh . "$(dirname "$0")"/util.sh export SYSTEMD_LOG_LEVEL=debug SD_PCREXTEND="/usr/lib/systemd/systemd-pcrextend" if [[ ! -x "${SD_PCREXTEND:?}" ]] || ! tpm_has_pcr sha256 11 || ! tpm_has_pcr sha256 15; then echo "$SD_PCREXTEND or PCR sysfs files not found, skipping PCR extension tests" exit 0 fi at_exit() { if [[ $? -ne 0 ]]; then # Dump the event log on fail, to make debugging a bit easier jq --seq --slurp /etc/machine-id SYSTEMD_FORCE_MEASURE=1 "$SD_PCREXTEND" --machine-id mv /etc/machine-id.save /etc/machine-id tpm2_pcrread sha256:15 -Q -o /tmp/newpcr15 # And check it matches expectations diff /tmp/newpcr15 \ <(cat /tmp/oldpcr15 <(echo -n "machine-id:994013bf23864ee7992eab39a96dd3bb" | openssl dgst -binary -sha256) | openssl dgst -binary -sha256) # Check that the event log record was properly written test "$(jq --seq --slurp ".[$RECORD_COUNT].pcr" /run/systemd/system/systemd-pcrextend.socket.d/50-no-condition.conf <