Skip to content

eBPF-based security platform

attest: verify config history against the TPM quote

KP Singh2473b1cebd24
diff --git a/Makefile.shirudo b/Makefile.shirudo
index 5e52cf19..df75646c 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -201,6 +201,7 @@ UTIL_SRCS := \
util/dm_verity.c \
util/config_update.c \
util/config_measure.c \
+ util/config_attest.c \
util/bpm_source_config.c \
util/eventlog.c \
util/json.c \
@@ -625,7 +626,7 @@ testing/helper/test-conditions: testing/helper/test-conditions.c util/conditions
# util/config.o resolves config_load(), called by tpm.o.
# The register code pulls in the eventlog, which pulls in the seal
# label writer and the JSON codec.
-REGISTER_OBJS := util/config_update.o util/config_measure.o util/config_image.o \
+REGISTER_OBJS := util/config_attest.o util/config_update.o util/config_measure.o util/config_image.o \
util/chain.o util/tpm.o util/tpm_wire.o util/eventlog.o \
util/timefmt.o \
util/hex.o util/crypto_openssl.o util/json.o util/string.o \
diff --git a/builtin-attest.c b/builtin-attest.c
index 58616e6b..61df73f4 100644
--- a/builtin-attest.c
+++ b/builtin-attest.c
@@ -23,6 +23,8 @@
#include "util/attest.h"
#include "util/chain.h"
#include "util/crypto.h"
+#include "util/config_measure.h"
+#include "util/image_runtime.h"
#include "util/help.h"
#include "util/hex.h"
#include "util/io.h"
@@ -59,6 +61,8 @@ static const struct shirudo_help_item verify_options[] = {
{ "--expect=<name>=<hex>", "an installed upatch by name and payload digest" },
{ "--tree-root=<hex>", "the upatch tree projection root at boot" },
{ "--expect-chain=<hex>", "the register value after the expected events" },
+ { "--expect-config-root=<hex>", "approved config image hash" },
+ { "--expect-config-pcr=<n>", "reserved config PCR number" },
{ "--expect-pcr=<n>=<hex>", "a PCR value the quote must carry (repeatable)" },
{ "--allow-runtime-events", "accept loads, unloads and revocations after boot" },
{ "--strict-anchor", "require the anchoring PCR to hold only the anchor" },
@@ -508,6 +512,21 @@ static int cmd_attest_verify(int argc, const char **argv)
if (parse_hex32("--tree-root", a + 12, tree_root))
goto out;
have_tree_root = true;
+ } else if (!strncmp(a, "--expect-config-root=", 21)) {
+ if (x.have_config_root ||
+ parse_hex32("--expect-config-root", a + 21,
+ x.config_root))
+ goto out;
+ x.have_config_root = true;
+ } else if (!strncmp(a, "--expect-config-pcr=", 20)) {
+ __u64 pcr;
+
+ if (parse_u64(a + 20, strlen(a + 20), 15, &pcr) ||
+ x.have_config_pcr ||
+ shirudo_config_measure_pcr_valid(pcr))
+ goto out;
+ x.config_pcr = pcr;
+ x.have_config_pcr = true;
} else if (!strncmp(a, "--expect-chain=", 15)) {
if (parse_hex32("--expect-chain", a + 15, x.chain))
goto out;
@@ -560,6 +579,11 @@ static int cmd_attest_verify(int argc, const char **argv)
goto out;
}
}
+ if (x.have_config_root && !x.have_config_pcr) {
+ pr_err("attest verify: --expect-config-root requires "
+ "--expect-config-pcr");
+ goto out;
+ }
if (!evidence_path || !have_nonce) {
pr_err("attest verify: --evidence and --nonce are required");
goto out;
@@ -700,6 +724,7 @@ out:
static int cmd_attest_evidence(int argc, const char **argv)
{
+ const struct shirudo_attest_challenge *request;
struct shirudo_attest_challenge challenge = {};
__u8 nonce[SHIRUDO_ATTEST_NONCE_MAX];
__u32 mask = SHIRUDO_ATTEST_PCR_DEFAULT;
@@ -745,9 +770,10 @@ static int cmd_attest_evidence(int argc, const char **argv)
return 2;
}
- rc = attest_evidence(nonce, nonce_len, mask,
- challenge_path ? &challenge : NULL, &doc,
- &len, &cap);
+ request = challenge_path ? &challenge : NULL;
+ rc = shirudo_attest_evidence_config(nonce, nonce_len, mask, request,
+ shirudo_image_update_context(),
+ &doc, &len, &cap);
if (rc == -ENXIO) {
pr_err("attest: no TPM answered (tpm_error)");
return 1;
diff --git a/util/attest.c b/util/attest.c
index 3594f3a8..c124645b 100644
--- a/util/attest.c
+++ b/util/attest.c
@@ -23,6 +23,7 @@
#include "attest.h"
#include "chain.h"
#include "crypto.h"
+#include "config_attest.h"
#include "eventlog.h"
#include "hex.h"
#include "io.h"
@@ -141,14 +142,18 @@ static bool quote_covers(const struct shirudo_tpm_attestation *quote,
return ct_eq(digest, a.pcr_digest, 32);
}
-int attest_evidence(const __u8 *nonce, size_t nonce_len,
- __u32 pcr_mask,
- const struct shirudo_attest_challenge *challenge,
- char **out, size_t *len, size_t *cap)
+int shirudo_attest_evidence_config(const __u8 *nonce, size_t nonce_len,
+ __u32 pcr_mask,
+ const struct shirudo_attest_challenge *c,
+ struct shirudo_config_update *update,
+ char **out, size_t *len, size_t *cap)
{
+ const struct shirudo_attest_challenge *challenge = c;
struct shirudo_tpm_key ak = { .handle = 0 }, ek = { .handle = 0 };
struct shirudo_tpm_key ak_copy = {}, ek_copy = {};
struct shirudo_tpm_attestation quote = {}, certify = {};
+ struct shirudo_config_evidence config = {};
+ struct shirudo_tpm_attest quoted;
struct tpm_nv_info nv;
struct shirudo_tpm *tpm = NULL;
struct shirudo_json_emit e;
@@ -170,9 +175,16 @@ int attest_evidence(const __u8 *nonce, size_t nonce_len,
(pcr_mask & ~0x00FFFFFFu))
return -EINVAL;
- rc = tpm_open(&tpm);
+ rc = shirudo_config_evidence_collect(update, &config);
if (rc)
- return -ENXIO;
+ return rc;
+ if (config.present)
+ pcr_mask |= 1u << config.pcr;
+ rc = tpm_open(&tpm);
+ if (rc) {
+ rc = -ENXIO;
+ goto out;
+ }
rc = tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
if (rc)
goto out;
@@ -206,6 +218,16 @@ int attest_evidence(const __u8 *nonce, size_t nonce_len,
rc = -EAGAIN;
goto out;
}
+ if (config.present &&
+ (tpm_attest_parse(quote.attest, quote.attest_len,
+ &quoted) ||
+ quoted.reset_count != config.reset_count ||
+ quoted.restart_count != config.restart_count ||
+ memcmp(values[config.pcr],
+ config.value, 32))) {
+ rc = -EUCLEAN;
+ goto out;
+ }
rc = tpm_nv_certify(tpm, &ak, SHIRUDO_NV_INDEX, nonce,
nonce_len, &certify);
if (rc)
@@ -267,7 +289,8 @@ int attest_evidence(const __u8 *nonce, size_t nonce_len,
read_file_base64(FIRMWARE_LOG_PATH, &fw, &fw_cap);
read_file_base64(SYSTEMD_LOG_PATH, &sd, &sd_cap);
- need = 64 * 1024 + fw_cap + sd_cap + ek_b64_cap;
+ need = 64 * 1024 + fw_cap + sd_cap + ek_b64_cap +
+ config.n_events * 160;
if (stat(eventlog_path(), &st) == 0 && st.st_size > 0)
need += 2 * (size_t)st.st_size;
if (need > SHIRUDO_JSON_MAX_BYTES)
@@ -328,6 +351,9 @@ int attest_evidence(const __u8 *nonce, size_t nonce_len,
json_arr_open(&e, "eventlog");
eventlog_boot_lines(emit_line, &e);
json_arr_close(&e);
+ rc = shirudo_config_evidence_emit(&e, &config);
+ if (rc)
+ goto out;
if (cred_len) {
json_obj_open_key(&e, "credential");
emit_hex(&e, "value", cred, cred_len);
@@ -363,6 +389,7 @@ out:
tpm_key_flush(tpm, &ak);
tpm_close(tpm);
}
+ shirudo_config_evidence_clear(&config);
xfree(ek_cert, ek_cert ? EK_CERT_MAX : 0);
xfree(ek_b64, ek_b64_cap);
xfree(fw, fw_cap);
@@ -380,6 +407,17 @@ out:
return rc;
}
+int attest_evidence(const __u8 *nonce, size_t nonce_len,
+ __u32 pcr_mask,
+ const struct shirudo_attest_challenge *challenge,
+ char **out, size_t *len, size_t *cap)
+{
+ return shirudo_attest_evidence_config(nonce, nonce_len, pcr_mask,
+ challenge, NULL, out, len, cap);
+}
+
+/* ---- verification ---------------------------------------------------- */
+
struct record {
char type[16];
char label[SHIRUDO_UPATCH_NAME_MAX + 64];
@@ -650,6 +688,7 @@ int attest_verify(const char *evidence, size_t len,
char *report, size_t report_cap)
{
struct reporter rep = { .buf = report, .cap = report_cap };
+ struct shirudo_config_evidence config = {};
struct shirudo_tpm_attest quote = {}, certify = {};
struct shirudo_tpm_ecc_public ak_pub;
__u8 ak_public[SHIRUDO_TPM_PUBLIC_MAX];
@@ -813,6 +852,10 @@ int attest_verify(const char *evidence, size_t len,
have_cred = cred_sub[0].seen;
}
+ rc = shirudo_config_evidence_parse(evidence, len, &config);
+ if (rc)
+ goto out;
+
/* Freshness: the document must answer this request. */
if (hex_bytes(p->nonce_hex, nonce, sizeof(nonce), &nonce_len)) {
rc = -EINVAL;
@@ -972,6 +1015,28 @@ int attest_verify(const char *evidence, size_t len,
quote.firmware_version == certify.firmware_version,
"quote and certification are of one TPM reset");
+ if (config.present || expect->have_config_root ||
+ expect->have_config_pcr) {
+ const __u8 *root = expect->have_config_root ?
+ expect->config_root : NULL;
+ const char *reason;
+ int pcr;
+
+ pcr = expect->have_config_pcr ? (int)expect->config_pcr : -1;
+ rc = shirudo_config_evidence_verify(&config, quote.pcr_mask,
+ quote.reset_count,
+ quote.restart_count,
+ p->pcrs, root, pcr,
+ &reason);
+ say(&rep, !rc, "config: %s", reason);
+ if (config.present && !expect->have_config_root)
+ note(&rep, "config root has no operator approval; use "
+ "--expect-config-root with --expect-config-pcr");
+ if (config.present)
+ note(&rep, "config records a selection; "
+ "direct TPM writer protection is deferred");
+ }
+
/*
* The binding: the certified index must have the public area a
* register bound to the recorded PCR values has, which is what
@@ -1099,6 +1164,7 @@ int attest_verify(const char *evidence, size_t len,
}
rc = rep.failed ? -EKEYREJECTED : 0;
out:
+ shirudo_config_evidence_clear(&config);
xfree(p->recs, RECORDS_MAX * sizeof(*p->recs));
xfree(p, sizeof(*p));
return rc;
diff --git a/util/attest.h b/util/attest.h
index 18e0a1d8..618168a8 100644
--- a/util/attest.h
+++ b/util/attest.h
@@ -53,6 +53,14 @@ int attest_evidence(const __u8 *nonce, size_t nonce_len,
const struct shirudo_attest_challenge *challenge,
char **out, size_t *len, size_t *cap);
+struct shirudo_config_update;
+
+int shirudo_attest_evidence_config(const __u8 *nonce, size_t nonce_len,
+ __u32 pcr_mask,
+ const struct shirudo_attest_challenge *c,
+ struct shirudo_config_update *update,
+ char **out, size_t *len, size_t *cap);
+
/*
* Operator side. The credential the target has to recover is handed
* to the caller and kept nowhere else; ek_ca is a PEM bundle or NULL.
@@ -89,8 +97,12 @@ struct shirudo_attest_expect {
bool have_ek_name;
__u8 ek_name[SHIRUDO_TPM_NAME_LEN];
bool require_initrd; /* the binding must be the initrd's */
- __u32 bind_expect_mask; /* PCR values at binding time */
+ __u32 bind_expect_mask; /* PCR values at binding time */
__u8 bind_values[24][32];
+ bool have_config_root;
+ __u8 config_root[32];
+ bool have_config_pcr;
+ __u32 config_pcr;
};
/*
diff --git a/util/config_attest.c b/util/config_attest.c
new file mode 100644
index 00000000..3d32fb09
--- /dev/null
+++ b/util/config_attest.c
@@ -0,0 +1,303 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/* Copyright (c) 2026 Authors of shirudo */
+
+#include <shirudo/misc.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "chain.h"
+#include "config_attest.h"
+#include "config_measure.h"
+#include "hex.h"
+#include "json.h"
+#include "macros.h"
+#include "malloc.h"
+
+static int append_event(struct shirudo_config_evidence *view,
+ const struct shirudo_config_evidence_event *event)
+{
+ struct shirudo_config_evidence_event *events;
+ size_t capacity;
+
+ if (view->n_events >= SHIRUDO_CONFIG_EVIDENCE_EVENTS_MAX)
+ return -E2BIG;
+ if (view->n_events == view->capacity) {
+ capacity = view->capacity ? view->capacity * 2 : 16;
+ events = xreallocarray(view->events, view->capacity, capacity,
+ sizeof(*events));
+ if (!events)
+ return -ENOMEM;
+ view->events = events;
+ view->capacity = capacity;
+ }
+ view->events[view->n_events++] = *event;
+ return 0;
+}
+
+static int replay(const struct shirudo_config_evidence *view, __u8 out[32])
+{
+ __u8 digest[32];
+ __u64 sequence = 0;
+ size_t i;
+ int rc;
+
+ if (!view->events || !view->n_events ||
+ view->n_events > SHIRUDO_CONFIG_EVIDENCE_EVENTS_MAX)
+ return -EINVAL;
+ memcpy(out, view->initial_pcr, 32);
+ for (i = 0; i < view->n_events; i++) {
+ const struct shirudo_config_evidence_event *event =
+ &view->events[i];
+
+ if (!event->sequence || event->sequence > INT64_MAX ||
+ (i && event->sequence != sequence + 1) ||
+ event->kind != (i ? SHIRUDO_CONFIG_EVENT_UPDATE :
+ SHIRUDO_CONFIG_EVENT_BOOT))
+ return -EKEYREJECTED;
+ rc = shirudo_config_measure_event(event->kind, event->root_hash,
+ digest);
+ if (!rc)
+ rc = shirudo_chain_fold_checked(out, digest);
+ if (rc)
+ return rc;
+ sequence = event->sequence;
+ }
+ return 0;
+}
+
+static int collect_event(const struct shirudo_config_update_record *record,
+ void *opaque)
+{
+ struct shirudo_config_evidence_event event = {};
+ struct shirudo_config_evidence *view = opaque;
+
+ if (record->reset_count != view->reset_count ||
+ record->restart_count != view->restart_count)
+ return 0;
+ if (record->pcr != view->pcr || record->sequence > INT64_MAX ||
+ memcmp(record->initial_pcr, view->initial_pcr, 32))
+ return -EUCLEAN;
+ memcpy(event.root_hash, record->target.root_hash, 32);
+ event.sequence = record->sequence;
+ event.kind = record->kind;
+ return append_event(view, &event);
+}
+
+int shirudo_config_evidence_collect(struct shirudo_config_update *update,
+ struct shirudo_config_evidence *out)
+{
+ struct shirudo_config_update_record active;
+ const struct shirudo_config_evidence_event *last;
+ int rc;
+
+ memset(out, 0, sizeof(*out));
+ if (!update)
+ return 0;
+ rc = shirudo_config_update_check(update, &active);
+ if (rc)
+ return rc;
+ out->pcr = active.pcr;
+ out->reset_count = active.reset_count;
+ out->restart_count = active.restart_count;
+ memcpy(out->initial_pcr, active.initial_pcr, 32);
+ rc = shirudo_config_update_events(update, collect_event, out);
+ if (!rc)
+ rc = replay(out, out->value);
+ if (!rc) {
+ last = &out->events[out->n_events - 1];
+ if (last->sequence != active.sequence ||
+ memcmp(last->root_hash, active.target.root_hash, 32))
+ rc = -EUCLEAN;
+ }
+ if (rc) {
+ shirudo_config_evidence_clear(out);
+ return rc;
+ }
+ out->present = true;
+ return 0;
+}
+
+void shirudo_config_evidence_clear(struct shirudo_config_evidence *view)
+{
+ if (!view)
+ return;
+ xfree(view->events, view->capacity * sizeof(*view->events));
+ memset(view, 0, sizeof(*view));
+}
+
+static void emit_hash(struct shirudo_json_emit *emit, const char *key,
+ const __u8 bytes[32])
+{
+ char hex[65];
+
+ hex_encode(bytes, 32, hex);
+ json_kv_string(emit, key, hex);
+}
+
+int shirudo_config_evidence_emit(struct shirudo_json_emit *emit,
+ const struct shirudo_config_evidence *view)
+{
+ size_t i;
+
+ if (!view->present)
+ return 0;
+ json_obj_open_key(emit, "config");
+ json_kv_int(emit, "schema", 1);
+ json_kv_int(emit, "pcr", view->pcr);
+ json_kv_int(emit, "reset_count", view->reset_count);
+ json_kv_int(emit, "restart_count", view->restart_count);
+ emit_hash(emit, "initial_pcr", view->initial_pcr);
+ json_arr_open(emit, "events");
+ for (i = 0; i < view->n_events; i++) {
+ const struct shirudo_config_evidence_event *event =
+ &view->events[i];
+
+ if (event->sequence > INT64_MAX)
+ return -EOVERFLOW;
+ json_obj_open(emit);
+ json_kv_int(emit, "sequence", event->sequence);
+ json_kv_int(emit, "kind", event->kind);
+ emit_hash(emit, "root_hash", event->root_hash);
+ json_obj_close(emit);
+ }
+ json_arr_close(emit);
+ json_obj_close(emit);
+ return emit->err;
+}
+
+struct config_parser {
+ struct shirudo_config_evidence *view;
+ struct shirudo_json_field *event_fields;
+ size_t n_fields;
+ __s64 sequence, kind;
+ char root_hash[65];
+};
+
+static int on_event(void *opaque)
+{
+ struct shirudo_config_evidence_event event = {};
+ struct config_parser *parser = opaque;
+ size_t i;
+
+ for (i = 0; i < parser->n_fields; i++)
+ if (!parser->event_fields[i].seen)
+ return -EINVAL;
+ if (parser->sequence <= 0 ||
+ (parser->kind != SHIRUDO_CONFIG_EVENT_BOOT &&
+ parser->kind != SHIRUDO_CONFIG_EVENT_UPDATE) ||
+ strlen(parser->root_hash) != 64 ||
+ hex_decode(parser->root_hash, event.root_hash, 32))
+ return -EINVAL;
+ event.sequence = parser->sequence;
+ event.kind = parser->kind;
+ return append_event(parser->view, &event);
+}
+
+int shirudo_config_evidence_parse(const char *evidence, size_t length,
+ struct shirudo_config_evidence *out)
+{
+ struct config_parser parser = { .view = out };
+ struct shirudo_json_array sink = { on_event, &parser };
+ __s64 schema = 0, reset = 0, restart = 0, pcr = 0;
+ char initial[65] = {};
+ size_t i;
+ int rc;
+ struct shirudo_json_field event_fields[] = {
+ { "sequence", SHIRUDO_JSON_T_INT, &parser.sequence, 0, 0, NULL,
+ 0 },
+ { "kind", SHIRUDO_JSON_T_INT, &parser.kind, 0, 0, NULL, 0 },
+ { "root_hash", SHIRUDO_JSON_T_STRING, parser.root_hash,
+ sizeof(parser.root_hash), 0, NULL, 0 },
+ };
+ struct shirudo_json_field config_fields[] = {
+ { "schema", SHIRUDO_JSON_T_INT, &schema, 0, 0, NULL, 0 },
+ { "pcr", SHIRUDO_JSON_T_INT, &pcr, 0, 0, NULL, 0 },
+ { "reset_count", SHIRUDO_JSON_T_INT, &reset, 0, 0, NULL, 0 },
+ { "restart_count", SHIRUDO_JSON_T_INT, &restart, 0, 0, NULL,
+ 0 },
+ { "initial_pcr", SHIRUDO_JSON_T_STRING, initial,
+ sizeof(initial), 0, NULL, 0 },
+ { "events", SHIRUDO_JSON_T_ARRAY, &sink, 0, 0, event_fields,
+ ARRAY_SIZE(event_fields) },
+ };
+ struct shirudo_json_field top[] = {
+ { "config", SHIRUDO_JSON_T_OBJECT, NULL, 0, 0, config_fields,
+ ARRAY_SIZE(config_fields) },
+ };
+
+ memset(out, 0, sizeof(*out));
+ parser.event_fields = event_fields;
+ parser.n_fields = ARRAY_SIZE(event_fields);
+ rc = json_parse(evidence, length, top, ARRAY_SIZE(top));
+ if (rc)
+ goto fail;
+ if (!top[0].seen)
+ return 0;
+ for (i = 0; i < ARRAY_SIZE(config_fields); i++)
+ if (!config_fields[i].seen) {
+ rc = -EINVAL;
+ goto fail;
+ }
+ if (schema != 1 || reset < 0 || reset > UINT32_MAX || restart < 0 ||
+ restart > UINT32_MAX || pcr < 0 || pcr > 15 ||
+ shirudo_config_measure_pcr_valid(pcr) || strlen(initial) != 64 ||
+ hex_decode(initial, out->initial_pcr, 32)) {
+ rc = -EINVAL;
+ goto fail;
+ }
+ out->pcr = pcr;
+ out->reset_count = reset;
+ out->restart_count = restart;
+ rc = replay(out, out->value);
+ if (rc)
+ goto fail;
+ out->present = true;
+ return 0;
+fail:
+ shirudo_config_evidence_clear(out);
+ return rc;
+}
+
+int shirudo_config_evidence_verify(const struct shirudo_config_evidence *view,
+ __u32 quote_mask, __u32 reset,
+ __u32 restart, const __u8 pcrs[24][32],
+ const __u8 *expected_root,
+ int expected_pcr, const char **reason)
+{
+ __u8 value[32];
+ int rc;
+
+ *reason = "config root history matches the quoted PCR";
+ if (!view->present) {
+ *reason = "configuration evidence is missing";
+ return expected_root || expected_pcr >= 0 ? -EKEYREJECTED : 0;
+ }
+ if (shirudo_config_measure_pcr_valid(view->pcr) ||
+ !(quote_mask & (1u << view->pcr)) ||
+ (expected_pcr >= 0 && view->pcr != (__u32)expected_pcr)) {
+ *reason = "config PCR is unquoted or unexpected";
+ return -EKEYREJECTED;
+ }
+ if (view->reset_count != reset || view->restart_count != restart) {
+ *reason = "config history belongs to another TPM boot";
+ return -EKEYREJECTED;
+ }
+ if (expected_root && expected_pcr < 0) {
+ *reason = "expected config root needs an expected PCR";
+ return -EKEYREJECTED;
+ }
+ rc = replay(view, value);
+ if (rc || memcmp(value, pcrs[view->pcr], 32)) {
+ *reason = "config history does not match the quoted PCR";
+ return rc ? rc : -EKEYREJECTED;
+ }
+ if (expected_root && memcmp(view->events[view->n_events - 1].root_hash,
+ expected_root, 32)) {
+ *reason = "config root was not approved by the operator";
+ return -EKEYREJECTED;
+ }
+ return 0;
+}
diff --git a/util/config_attest.h b/util/config_attest.h
new file mode 100644
index 00000000..9e8caeec
--- /dev/null
+++ b/util/config_attest.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/* Copyright (c) 2026 Authors of shirudo */
+
+#ifndef SHIRUDO_CONFIG_ATTEST_H
+#define SHIRUDO_CONFIG_ATTEST_H
+
+#include <shirudo/misc.h>
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include "config_update.h"
+
+#define SHIRUDO_CONFIG_EVIDENCE_EVENTS_MAX 4096u
+
+struct shirudo_json_emit;
+
+struct shirudo_config_evidence_event {
+ __u8 root_hash[32];
+ __u64 sequence;
+ enum shirudo_config_event_kind kind;
+};
+
+struct shirudo_config_evidence {
+ struct shirudo_config_evidence_event *events;
+ __u8 initial_pcr[32];
+ __u8 value[32];
+ size_t n_events;
+ size_t capacity;
+ __u32 reset_count;
+ __u32 restart_count;
+ __u32 pcr;
+ bool present;
+};
+
+int shirudo_config_evidence_collect(struct shirudo_config_update *update,
+ struct shirudo_config_evidence *out);
+void shirudo_config_evidence_clear(struct shirudo_config_evidence *view);
+int shirudo_config_evidence_emit(struct shirudo_json_emit *emit,
+ const struct shirudo_config_evidence *view);
+int shirudo_config_evidence_parse(const char *evidence, size_t length,
+ struct shirudo_config_evidence *out);
+int shirudo_config_evidence_verify(const struct shirudo_config_evidence *view,
+ __u32 quote_mask, __u32 reset,
+ __u32 restart, const __u8 pcrs[24][32],
+ const __u8 *expected_root,
+ int expected_pcr, const char **reason);
+
+#endif /* SHIRUDO_CONFIG_ATTEST_H */
diff --git a/util/image_runtime.c b/util/image_runtime.c
index 00cc56a9..c503453f 100644
--- a/util/image_runtime.c
+++ b/util/image_runtime.c
@@ -87,6 +87,11 @@ static struct image_context image = {
static int load_runtime_config(void);
static int current_config(void);
+struct shirudo_config_update *shirudo_image_update_context(void)
+{
+ return image.locked ? &image.update : NULL;
+}
+
static bool absolute_path(const char *path)
{
return path && path[0] == '/' && !strstr(path, "/../") &&
@@ -948,8 +953,6 @@ int shirudo_image_enter(const char *command, int argc, const char **argv)
return -EPROTO;
if (!identity.runtime_mode)
return 0;
- if (!strcmp(command, "attest"))
- return -EOPNOTSUPP;
rc = shirudo_image_bootstrap_load();
if (rc < 0)
return rc;
diff --git a/util/image_runtime.h b/util/image_runtime.h
index bb4b99a9..5e33b8cc 100644
--- a/util/image_runtime.h
+++ b/util/image_runtime.h
@@ -11,6 +11,7 @@
struct shirudo_config_update;
struct shirudo_trusted_set;
+struct shirudo_config_update *shirudo_image_update_context(void);
int shirudo_image_bootstrap_load(void);
const __u8 *shirudo_image_runtime_root(void);
int shirudo_image_runtime_mount(void);