eBPF-based security platform
testing: provision kernel writers in the register VM
Leonard Cohnenfa4efd6071ad
diff --git a/Documentation/requirements.rst b/Documentation/requirements.rstindex 65a34594..94a23bdd 100644--- a/Documentation/requirements.rst+++ b/Documentation/requirements.rst@@ -441,6 +441,11 @@ suites when validating a deployment.module installed, ``testing/tpm/t0033-tpm-wire.sh`` also cross-checksthe TPM credential blob it builds against an independent implementation;without it that one check is skipped.+* ``make -C testing test-tgt-register`` additionally needs libtpms+ development headers on the build host (``libtpms-dev`` on Debian and+ Ubuntu). The prepared guest installs libtpms and the command TCTI+ runtime. Signing uses the guest's real kernel keyring, not a software+ signing replacement.* ``make -C testing fuzz`` builds the parsers' libFuzzer targets with``clang`` and needs its fuzzer and sanitizer runtime(``libclang-rt-<version>-dev`` on Debian and Ubuntu).diff --git a/Documentation/tpm.rst b/Documentation/tpm.rstindex ac0dbea8..9b2d9dfc 100644--- a/Documentation/tpm.rst+++ b/Documentation/tpm.rst@@ -590,24 +590,30 @@ context and the deferred mitigations the plan.8) Testing----------+``make -C testing test-tgt-register`` runs ``testing/tpm/t0034-register.sh``+in a dedicated pre-init KVM guest. It provisions a real kernel signing+key and freezes its public metadata in a BPF identity map; no signing+or keyring implementation is replaced. The libtpms command transport+controls PCR phases and TPM resets while the guest kernel and writer+survive. This preserves lifecycle, attestation and credential-activation+coverage, including index recreation, the closed first-write window,+reset recovery and late binding. It is a protocol test before the LSM+attaches, not evidence of guard enforcement. The host suite skips it;+``test-tgt`` runs it before the normal target suite.+The same guest runs ``testing/t0048-config-attest.sh`` with a fresh native+writer to cover config-PCR evidence alongside the signed NV register.+The test-only ``test-register-cli`` invokes the attestation and status+commands before enforcement, without entering an authenticated runtime.+The production CLI rejects that synthetic identity map; protected-target+tests continue to invoke the installed runtime binary.+``testing/t0051-harden.sh`` checks process-wide locking, fail-closedstartup and the memory-lock limits of every shipped service.``testing/tpm/t0033-tpm-wire.sh`` checks the policy digests, names, wireparsers, the key derivations, the endorsement policy and thecredential blob against known vectors and an independent-implementation, without a TPM. ``testing/tpm/t0034-register.sh`` drives the-whole register and attestation path, the initrd phases simulated as-PCR 11 extensions, the credential challenge with an ECC and an RSA-endorsement key included, against libtpms:-``testing/helper/tpmsim-cmd`` is a ``cmd:`` TCTI driver around the simulator,-built when ``pkg-config libtpms`` succeeds, and ``testing/helper/test-register``-exercises binding, extending, replay, recreation, a TPM reset and-``attest`` evidence and verification through ``SHIRUDO_TPM_TCTI``,-``SHIRUDO_EVENTLOG_PATH`` and ``SHIRUDO_KEYS_DIR``. Deleting the-simulator's ``volatile`` state file is a TPM reset. The target suite-runs the same path against swtpm in the QEMU VM (``make -C testing test-tgt``);-``contrib/swtpm.sh`` starts a software TPM for a development target.+implementation, without a TPM.Configuration image measurementsdiff --git a/Makefile.shirudo b/Makefile.shirudoindex a42e1385..985f374b 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -604,6 +604,7 @@ TEST_HELPERS := $(VERITY_TEST_HELPERS) \testing/helper/test-chain \testing/helper/test-tpm-wire \testing/helper/test-register \+ testing/helper/test-register-cli \testing/helper/test-eventlog \testing/helper/test-keys \testing/helper/test-seal \@@ -654,8 +655,10 @@ REGISTER_OBJS := util/config_attest.o util/config_update.o util/config_measure.outil/hex.o util/crypto_openssl.o util/json.o util/string.o \util/io.o util/seal.o util/config.o util/image_config.o \util/log.o util/malloc.o \- util/initrd.o $(VERSION_OBJ)-REGISTER_LIBS := $(LIBCRYPTO_LIBS) $(LIBSSL_LIBS) $(TSS2_LIBS)+ util/initrd.o util/nv_writer.o util/identity.o \+ $(VERSION_OBJ) $(LIBBPF_A)+REGISTER_LIBS := $(LIBCRYPTO_LIBS) $(LIBSSL_LIBS) $(TSS2_LIBS) \+ $(LIBBPF_A) $(LIBELF_LIBS) $(ZLIB_LIBS)testing/helper/test-keys: testing/helper/test-keys.c util/keys.o \util/upatch.o $(REGISTER_OBJS)@@ -682,11 +685,16 @@ testing/helper/test-tpm-wire: testing/helper/test-tpm-wire.c util/tpm_wire.o uti@printf ' CC $@\n'$(Q)$(CC) $(CFLAGS) -o $@ $^ -lcrypto -lssl-testing/helper/test-register: testing/helper/test-register.c util/attest.o \+testing/helper/test-register: testing/helper/test-register.c util/attest.o util/keyring.o \$(REGISTER_OBJS)@printf ' CC $@\n'$(Q)$(CC) $(CFLAGS) -o $@ $^ $(REGISTER_LIBS)+testing/helper/test-register-cli: testing/helper/test-register-cli.c \+ $(BUILTIN_OBJS) $(UTIL_OBJS) $(VERSION_OBJ) $(LIBBPF_A)+ @printf ' CC $@\n'+ $(Q)$(CC) $(CFLAGS) -o $@ $^ $(STATIC_LIBS) $(DYNAMIC_LIBS)+testing/helper/tpmsim-cmd: testing/helper/tpmsim-cmd.c@printf ' CC $@\n'$(Q)$(CC) $(CFLAGS_BASE) -Iinclude $(TPMSIM_CFLAGS) -o $@ $< $(TPMSIM_LIBS) -lcryptodiff --git a/contrib/build-test-vm-bundle.sh b/contrib/build-test-vm-bundle.shindex b77b8309..78748d8e 100755--- a/contrib/build-test-vm-bundle.sh+++ b/contrib/build-test-vm-bundle.sh@@ -322,6 +322,12 @@ while IFS= read -r helper; dodone <<'EOF'testing/helper/test-json-parsertesting/helper/test-chain+testing/helper/test-register+testing/helper/test-register-cli+testing/helper/test-config-attest+testing/helper/test-config-update+testing/helper/tpmsim-cmd+testing/helper/test-tpm-wiretesting/helper/test-configtesting/helper/test-bpf-loadtesting/helper/test-bpf-cmddiff --git a/contrib/test-vm-guest.sh b/contrib/test-vm-guest.shindex 9571e217..699e4449 100755--- a/contrib/test-vm-guest.sh+++ b/contrib/test-vm-guest.sh@@ -341,6 +341,27 @@ if [[ "$VM_INITRD" == 1 ]]; thenlog "initrd Shirudo journal"journalctl -b -u shirudo-initrd.service --no-pager | tail -40 || truefi++if [[ "${TEST_VM_SUITE:-all}" == register ]]; then+ [[ "$VM_INITRD" == 0 ]] || {+ log "register protocol tests must precede production initialization"+ exit 1+ }+ log "running register protocol tests with a real kernel writer"+ : >/mnt/shirudo-out/failed-tests+ : >/mnt/shirudo-out/failed-suites+ (+ cd testing+ SHIRUDO_TEST_REGISTER_VM=1 \+ SHIRUDO_TEST_FAILURES_FILE=/mnt/shirudo-out/failed-tests \+ sh tpm/t0034-register.sh+ SHIRUDO_TEST_REGISTER_VM=1 \+ SHIRUDO_TEST_FAILURES_FILE=/mnt/shirudo-out/failed-tests \+ sh t0048-config-attest.sh+ )+ exit 0+fi+(cd "$BUNDLE/verity" && sha256sum -c manifest)mountpoint -q /run/shirudo/runtimemountpoint -q /run/shirudo/configdiff --git a/contrib/test-vm-runtime-packages b/contrib/test-vm-runtime-packagesindex 3aea1387..c95c1746 100644--- a/contrib/test-vm-runtime-packages+++ b/contrib/test-vm-runtime-packages@@ -4,7 +4,9 @@ keyutilslibelf1t64libjson-c5libluajit-5.1-2+libtpms0libtss2-esys-3.0.2-0t64+libtss2-tcti-cmd0t64libtss2-tctildr0t64netperfopenssh-serverdiff --git a/contrib/test-vm.sh b/contrib/test-vm.shindex d0bfbc99..5d150144 100755--- a/contrib/test-vm.sh+++ b/contrib/test-vm.sh@@ -156,10 +156,12 @@ valid_vm_name()validate_mode(){[[ "$TEST_MODE" == verity ]] || die "TEST_VM_MODE must be verity"- [[ "$VM_INITRD" == 1 && "$SKIP_SEAL" == 0 ]] ||- die "dm-verity requires TEST_VM_INITRD=1 and TEST_VM_SKIP_SEAL=0"- [[ "$VM_SUITE" == all || "$VM_SUITE" == obs ]] ||- die "dm-verity requires the complete test suite or obs"+ if [[ "$VM_SUITE" != register ]]; then+ [[ "$VM_INITRD" == 1 && "$SKIP_SEAL" == 0 ]] ||+ die "dm-verity requires TEST_VM_INITRD=1 and TEST_VM_SKIP_SEAL=0"+ [[ "$VM_SUITE" == all || "$VM_SUITE" == obs ]] ||+ die "dm-verity requires the complete test suite or obs"+ ficase "$VM_MODE" ininteractive|test) ;;*) die "VM_MODE must be 'interactive' or 'test'" ;;@@ -169,7 +171,11 @@ validate_mode()tree)[[ "$VM_MODE" == test ]] || die "tree suite requires VM_MODE=test";;- *) die "TEST_VM_SUITE must be 'all', 'obs', or 'tree'" ;;+ register)+ [[ "$VM_MODE" == test && "$VM_INITRD" == 0 && "$SKIP_SEAL" == 0 ]] ||+ die "register suite requires test mode without a production initrd"+ ;;+ *) die "TEST_VM_SUITE must be 'all', 'obs', 'tree', or 'register'" ;;esaccase "$SKIP_SEAL" in0|1) ;;diff --git a/testing/Makefile b/testing/Makefileindex 73e35dda..a67c7290 100644--- a/testing/Makefile+++ b/testing/Makefile@@ -21,7 +21,7 @@ test-vm-arch = $(shell TEST_VM_ARCH='$(TEST_VM_ARCH)'; \.DEFAULT_GOAL := help.PHONY: help clean test-helpers test-op fuzz test bundle test-vm-bundle kernel \bpf-next vm vm-console vm-ssh vm-stop vm-clean test-tgt test-tgt-obs \- test-vm test-vm-clean+ test-tgt-register test-vm test-vm-cleanKERNEL_PATCHES ?= $(if $(wildcard $(ROOT)/kernel/*.patch),$(ROOT)/kernel/,)override KERNEL_PATCHES := $(if $(strip $(KERNEL_PATCHES)),$(call root-path,$(KERNEL_PATCHES)),)@@ -224,8 +224,9 @@ vm-ssh:$(Q)VM_NAME="$(VM_NAME)" \TEST_VM_WORK_DIR="$(TEST_VM_WORK_DIR)" $(ROOT)/contrib/test-vm.sh --ssh-test-tgt: $(VM_KERNEL_DEP) test-vm-bundle- $(Q)VM_MODE=test TEST_VM_SUITE="$(TEST_VM_SUITE)" VM_VERBOSE="$(TEST_VM_VERBOSE)" VM_NAME="$(VM_NAME)" VM_TENANT="$(VM_TENANT)" \+define run-target-vm+VM_MODE=test TEST_VM_SUITE="$(1)" VM_VERBOSE="$(TEST_VM_VERBOSE)" VM_NAME="$(2)" VM_TENANT="$(VM_TENANT)" \+ TEST_VM_INITRD="$(3)" \TEST_VM_KERNEL="$(abspath $(VM_KERNEL_IMAGE))" \TEST_VM_KERNEL_ARTIFACT_DIR="$(abspath $(VM_KERNEL_ARTIFACT_DIR))" \TEST_VM_WORK_DIR="$(TEST_VM_WORK_DIR)" \@@ -237,9 +238,16 @@ test-tgt: $(VM_KERNEL_DEP) test-vm-bundleTEST_VM_OCI_CA="$(TEST_VM_OCI_CA)" \TEST_VM_BPM_OCI_REPOSITORY="$(TEST_VM_BPM_OCI_REPOSITORY)" \TEST_VM_BPM_OCI_INDEX_CERT="$(TEST_VM_BPM_OCI_INDEX_CERT)" \- TEST_VM_MODE="$(TEST_VM_MODE)" TEST_VM_INITRD="$(TEST_VM_INITRD)" \+ TEST_VM_MODE="$(TEST_VM_MODE)" \TEST_VM_HOST_BUNDLE="$(abspath $(TEST_VM_BUNDLE_DIR))" \$(ROOT)/contrib/test-vm.sh+endef++test-tgt-register: $(VM_KERNEL_DEP) test-vm-bundle+ $(Q)$(call run-target-vm,register,$(if $(VM_NAME),$(VM_NAME),shirudo)-register,0)++test-tgt: $(VM_KERNEL_DEP) test-vm-bundle test-tgt-register+ $(Q)$(call run-target-vm,$(TEST_VM_SUITE),$(VM_NAME),$(TEST_VM_INITRD))test-tgt-obs: $(VM_KERNEL_DEP) test-vm-bundle$(Q)VM_MODE=test TEST_VM_SUITE=obs VM_VERBOSE="$(TEST_VM_VERBOSE)" VM_NAME="$(VM_NAME)" VM_TENANT="$(VM_TENANT)" \@@ -304,6 +312,7 @@ help:' make -C testing test-helpers' \' make -C testing fuzz [FUZZ_SECONDS=60]' \' make -C testing test-tgt (dm-verity, dracut initrd, root required)' \+ ' make -C testing test-tgt-register' \' make -C testing test-tgt-obs' \' make -C testing vm, vm-console, vm-ssh, vm-stop, or vm-clean' \' make -C testing vm KERNEL=7.4' \diff --git a/testing/helper/test-register-cli.c b/testing/helper/test-register-cli.cnew file mode 100644index 00000000..d2e7b7f8--- /dev/null+++ b/testing/helper/test-register-cli.c@@ -0,0 +1,29 @@+// SPDX-License-Identifier: BSD-2-Clause+/* Copyright (c) 2026 Authors of shirudo */++#include <stdio.h>+#include <string.h>++#include "builtin.h"+#include "harden.h"+#include "identity.h"+#include "log.h"++/* Protocol fixtures precede authenticated runtime initialization. */+int main(int argc, const char **argv)+{+ harden_stdio();+ log_init();+ if (harden_self())+ return 1;+ if (shirudo_enforcement_active() != 0) {+ fputs("register CLI fixture requires an uninitialized target\n", stderr);+ return 1;+ }+ if (argc > 1 && !strcmp(argv[1], "attest"))+ return cmd_attest(argc - 1, argv + 1);+ if (argc > 1 && !strcmp(argv[1], "status"))+ return cmd_status(argc - 1, argv + 1);+ fputs("usage: test-register-cli attest|status [options]\n", stderr);+ return 2;+}diff --git a/testing/helper/test-register.c b/testing/helper/test-register.cindex 904a8b39..97cbe31b 100644--- a/testing/helper/test-register.c+++ b/testing/helper/test-register.c@@ -8,9 +8,14 @@*/#include <errno.h>+#include <linux/keyctl.h>#include <stdio.h>#include <stdlib.h>#include <string.h>+#include <sys/syscall.h>+#include <unistd.h>++#include <bpf/bpf.h>#include <shirudo/misc.h>@@ -19,12 +24,78 @@#include "config.h"#include "eventlog.h"#include "hex.h"+#include "identity.h"#include "json.h"#include "malloc.h"+#include "nv_writer.h"#include "paths.h"#include "tpm.h"#include "version.h"+/* Provision real kernel signing authority before the VM attaches its LSM. */+static int writer_create(void)+{+ struct bpf_map_create_opts opts = { .sz = sizeof(opts) };+ struct shirudo_identity id = {};+ int fd, rc, unlink_rc;+ __u32 zero = 0;+ long ret;++ rc = nv_writer_create(&id.nv_writer_ring, &id.nv_writer_key,+ id.nv_writer_public);+ if (rc)+ goto out;+ errno = 0;+ ret = syscall(__NR_keyctl, KEYCTL_SETPERM, id.nv_writer_ring, 0x3f3f0000L, 0, 0);+ if (ret != -1 || errno != EACCES) {+ fprintf(stderr, "writer keyring permissions were not sealed: %ld/%d\n",+ ret, errno);+ rc = ret < 0 ? -errno : -EPROTO;+ goto out;+ }+ fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "shirudo_test_id", sizeof(zero),+ sizeof(id), 1, &opts);+ if (fd < 0) {+ rc = -errno;+ goto out;+ }+ if (bpf_map_update_elem(fd, &zero, &id, BPF_ANY) ||+ bpf_map_freeze(fd) || bpf_obj_pin(fd, SHIRUDO_IDENTITY_PIN))+ rc = -errno;+ close(fd);+ if (!rc)+ return 0;+out:+ if (id.nv_writer_ring > 0) {+ unlink_rc = keyring_unlink_key(KEY_SPEC_USER_KEYRING, id.nv_writer_ring);+ if (unlink_rc)+ fprintf(stderr, "unlink protocol-test writer: %s\n",+ strerror(-unlink_rc));+ }+ fprintf(stderr, "kernel writer setup: %s\n", strerror(-rc));+ return 1;+}++static int writer_remove(void)+{+ struct shirudo_identity id = {};+ int rc;++ rc = identity_read(&id);+ if (rc) {+ fprintf(stderr, "kernel writer identity: %s\n", strerror(-rc));+ return 1;+ }+ if (unlink(SHIRUDO_IDENTITY_PIN)) {+ perror("unlink protocol-test identity");+ return 1;+ }+ rc = keyring_unlink_key(KEY_SPEC_USER_KEYRING, id.nv_writer_ring);+ if (rc)+ fprintf(stderr, "unlink protocol-test writer: %s\n", strerror(-rc));+ return rc ? 1 : 0;+}+static void puthex(const __u8 *b, size_t n){char h[2 * 1024 + 1];@@ -148,6 +219,19 @@ int main(int argc, char **argv)if (argc < 2)return 2;+ if (!strcmp(argv[1], "writer-create") && argc == 2)+ return writer_create();+ if (!strcmp(argv[1], "writer-remove") && argc == 2)+ return writer_remove();+ if (!strcmp(argv[1], "writer-public") && argc == 2) {+ __u8 public[SHIRUDO_TPM_NV_RSA_BYTES];++ if (nv_writer_read(public))+ return 1;+ puthex(public, sizeof(public));+ return 0;+ }+if (strcmp(argv[1], "init") == 0 && argc == 3) {struct shirudo_chain_init_info info;diff --git a/testing/t0015-test-vm-cli.sh b/testing/t0015-test-vm-cli.shindex a2dc0200..25497f12 100755--- a/testing/t0015-test-vm-cli.sh+++ b/testing/t0015-test-vm-cli.sh@@ -16,6 +16,19 @@ test_expect_success 'test-vm rejects a missing local kernel before boot' 'grep -q "kernel image not found" "$WORK/missing.out"'+test_expect_success 'register protocols run only in an isolated pre-init test VM' '+ ! TEST_VM_SUITE=register VM_MODE=test TEST_VM_INITRD=0 \+ TEST_VM_WORK_DIR="$WORK/register" TEST_VM_KERNEL="$WORK/no-bzImage" \+ "$RUNNER" >"$WORK/register.out" 2>&1 &&+ grep -q "kernel image not found" "$WORK/register.out" &&+ ! TEST_VM_SUITE=register VM_MODE=interactive TEST_VM_INITRD=0 \+ "$RUNNER" >"$WORK/register-interactive.out" 2>&1 &&+ grep -q "register suite requires test mode" "$WORK/register-interactive.out" &&+ ! TEST_VM_SUITE=register VM_MODE=test TEST_VM_INITRD=1 \+ "$RUNNER" >"$WORK/register-initrd.out" 2>&1 &&+ grep -q "register suite requires test mode" "$WORK/register-initrd.out"+'+test_expect_success 'test-vm requires a SHA-256 for a remote kernel' '! TEST_VM_WORK_DIR="$WORK/no-sha" \TEST_VM_KERNEL_URL=https://example.invalid/bzImage "$RUNNER" \diff --git a/testing/t0048-config-attest.sh b/testing/t0048-config-attest.shindex 5aae8eb7..95c62ce3 100755--- a/testing/t0048-config-attest.sh+++ b/testing/t0048-config-attest.sh@@ -9,13 +9,21 @@ H=${SHIRUDO_TEST_CONFIG_ATTEST_HELPER:-$(pwd)/helper/test-config-attest}U=${SHIRUDO_TEST_CONFIG_HELPER:-$(pwd)/helper/test-config-update}R=$(pwd)/helper/test-registerSIM=$(pwd)/helper/tpmsim-cmd-S=${SHIRUDO_IMAGE_TEST_SHIRUDO:-../shirudo}+S=${SHIRUDO_IMAGE_TEST_SHIRUDO:-$(pwd)/helper/test-register-cli}+. ./tpm/register-lib.shfor helper in "$H" "$U" "$R" "$SIM" "$S"; do[ -x "$helper" ] || test_skip_all "missing helper: $helper"donecommand -v python3 >/dev/null 2>&1 || test_skip_all "no python3"WORK=$(mktemp -d)-trap 'rm -rf "$WORK"' EXIT HUP INT TERM+cleanup() {+ result=$?+ register_writer_stop || result=1+ rm -rf "$WORK"+ exit "$result"+}+trap cleanup EXIT HUP INT TERM+register_writer_start || exit 1mkdir -m 700 "$WORK/config" "$WORK/keys"head -c 700 /dev/urandom >"$WORK/keys/cert.der": >"$WORK/initrd-release"diff --git a/testing/tpm/register-lib.sh b/testing/tpm/register-lib.shnew file mode 100644index 00000000..dedfaeb6--- /dev/null+++ b/testing/tpm/register-lib.sh@@ -0,0 +1,40 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++[ "${SHIRUDO_TEST_REGISTER_VM:-0}" = 1 ] ||+ test_skip_all "run with make -C testing test-tgt-register (real kernel signer required)"+[ "$(id -u)" = 0 ] && [ -x "$R" ] || {+ echo "register VM requires root and the built register helper" >&2+ exit 1+}+[ ! -e /run/shirudo/bpffs/identity ] && [ ! -e /run/shirudo/bpffs/lsm_link ] || {+ echo "register protocol tests must run before shirudo init" >&2+ exit 1+}++WRITER_CREATED=0+MOUNTED=0++register_writer_start() {+ mkdir -p /run/shirudo/bpffs+ if mountpoint -q /run/shirudo/bpffs; then+ echo "register protocol tests require an unused private bpffs" >&2+ return 1+ fi+ mount -t bpf -o nosuid,nodev,noexec bpf /run/shirudo/bpffs || return 1+ MOUNTED=1+ "$R" writer-create || return 1+ WRITER_CREATED=1+}++register_writer_stop() {+ writer_result=0+ if [ "$WRITER_CREATED" = 1 ]; then+ "$R" writer-remove || writer_result=1+ fi+ if [ "$MOUNTED" = 1 ]; then+ umount /run/shirudo/bpffs || writer_result=1+ fi+ return "$writer_result"+}diff --git a/testing/tpm/t0034-register.sh b/testing/tpm/t0034-register.shindex 6e2a1a69..a6b4c49d 100644--- a/testing/tpm/t0034-register.sh+++ b/testing/tpm/t0034-register.sh@@ -2,25 +2,28 @@# SPDX-License-Identifier: BSD-2-Clause# Copyright (c) 2026 Authors of shirudo#-# t0034 -- the measurement register against a software TPM: binding-# from the initrd, the anchor, extends, the recreate and replay attacks,-# a reset and a late binding, the credential challenge, and the evidence-# a verifier accepts or refuses. Needs the libtpms-backed-# helper/tpmsim-cmd; skipped where libtpms is not installed.+# t0034 -- register lifecycle with a real kernel writer in a pre-init VM.cd "$(dirname "$0")/..". ./test-lib.sh-R=helper/test-register+R=./helper/test-registerSIM=$(pwd)/helper/tpmsim-cmd-S=../shirudo-[ -x "$SIM" ] || test_skip_all "helper/tpmsim-cmd not built (libtpms-dev missing)"-[ -x "$R" ] || test_skip_all "helper/test-register not built"-[ -x "$S" ] || test_skip_all "shirudo not built"-command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"--WORK=$(mktemp -d)-trap 'rm -rf "$WORK"' EXIT HUP INT TERM+S=./helper/test-register-cli+. ./tpm/register-lib.sh+[ "$(id -u)" = 0 ] && [ -x "$SIM" ] && [ -x "$R" ] && [ -x "$S" ] || {+ echo "register VM requires root and the built TPM helpers" >&2+ exit 1+}+WORK=$(mktemp -d) || exit 1+cleanup() {+ result=$?+ register_writer_stop || result=1+ rm -rf "$WORK"+ exit "$result"+}+trap cleanup EXIT HUP INT TERM+register_writer_start || exit 1mkdir -p "$WORK/keys"head -c 700 /dev/urandom >"$WORK/keys/cert.der": >"$WORK/initrd-release"