Skip to content

eBPF-based security platform

attest: take the register's handle and PCRs from constants, not evidence

Daniel Borkmann4ffcbd873054
diff --git a/Documentation/tpm.rst b/Documentation/tpm.rst
index dd1fb0f8..648dc29b 100644
--- a/Documentation/tpm.rst
+++ b/Documentation/tpm.rst
@@ -414,7 +414,8 @@ checks, in order:
its public area and that area is the TCG default template under
the endorsement policy; with ``--ek-name`` it is the pinned key;
with ``--expect-credential`` the document's ``credential`` equals
- the value the challenge carried.
+ the value the challenge carried, which needs ``--ak-name``: the
+ credential proves where the pinned key lives, not which key signed.
3. The quote: ECDSA signature by that key over the ``TPMS_ATTEST``,
signer equal to the key's qualified name under the endorsement
hierarchy, the nonce as extra data, the selection equal to
@@ -423,22 +424,31 @@ checks, in order:
4. The register certification: the same signature, signer and nonce
checks, the certified index name equal to the listed name, and the
certified 32 bytes at offset 0 equal to the listed value.
-5. The binding: this boot has an ``init`` record; the name a register
- bound to that record's ``pcr_before`` and ``phase_before`` must
- have, computed in software from the handle, the attributes with
- ``TPMA_NV_WRITTEN``, the policy and the size, equals both the
- certified name and the recorded one. Every ``--expect-bind-pcr``
- value equals the recorded one for that PCR, so the operator pins
- the ``enter-initrd`` phase value from the UKI, and
+5. The binding: this boot has an ``init`` record; the document names
+ the register's handle and PCRs 9 and 11, the verifier's own
+ constants and never the record's, since a target can define an
+ index of its own under a policy over PCRs it extends and resets at
+ will; the name a register bound to that record's ``pcr_before`` and
+ ``phase_before`` must have, computed in software from the handle,
+ the attributes with ``TPMA_NV_WRITTEN``, the policy and the size,
+ equals both the certified name and the recorded one. Every
+ ``--expect-bind-pcr`` value equals the recorded one for that PCR, so
+ the operator pins the ``enter-initrd`` phase value from the UKI, and
``--require-initrd`` fails unless the record says the binding was
- made while the initrd ran.
+ made while the initrd ran; the record is the target's word, so
+ ``--expect-bind-pcr=11`` is what proves it.
6. The reset: the boot holds one init record for the reset count the
last one names, that count is the one the certification carries,
and the quote and the certification carry the same reset count and
firmware version, so a register bound again after boot cannot pass
as the boot's.
7. The replay: this boot's records fold from zeros to the certified
- value.
+ value, and every event after the ``init`` record carries the digest
+ its own fields produce: the name and payload of a load or unload,
+ the sequence number and operation digest of a tree operation, the
+ certificate digest of a revocation. A record relabelled after the
+ fact still replays, since the digest is what was measured, and
+ fails here.
8. The anchor: the record's anchor digest is the digest of the anchor
string for the recorded name, and the quoted PCR 9 equals
``pcr_before`` extended by it. When PCR 9 holds further
diff --git a/builtin-attest.c b/builtin-attest.c
index 8da672f7..7e3b2093 100644
--- a/builtin-attest.c
+++ b/builtin-attest.c
@@ -596,6 +596,16 @@ static int cmd_attest_verify(int argc, const char **argv)
"describe the init event and need --cert");
goto out;
}
+ /*
+ * The credential proves that the pinned attestation key sits beside
+ * the endorsement key; recovered on the target, its value says
+ * nothing about which key signed the evidence.
+ */
+ if (x.have_credential && !x.have_ak_name) {
+ pr_err("attest verify: --expect-credential needs the key the "
+ "challenge was made for; give --ak-name");
+ goto out;
+ }
if (!x.have_ak_name)
pr_warn("attest verify: no --ak-name; the signer is not "
"pinned");
diff --git a/testing/helper/test-register.c b/testing/helper/test-register.c
index ee8d8f12..904a8b39 100644
--- a/testing/helper/test-register.c
+++ b/testing/helper/test-register.c
@@ -23,6 +23,7 @@
#include "malloc.h"
#include "paths.h"
#include "tpm.h"
+#include "version.h"
static void puthex(const __u8 *b, size_t n)
{
@@ -75,7 +76,8 @@ static int append_init(const __u8 event[32],
}
static int append_event(const char *type, const char *name,
- const __u8 event[32], const __u8 chain[32])
+ const __u8 payload[32], const __u8 event[32],
+ const __u8 chain[32])
{
char buf[4096], ts[32], boot_id[64], nv_index[16], hex[65];
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
@@ -94,6 +96,41 @@ static int append_event(const char *type, const char *name,
json_kv_string(&e, "boot_id", boot_id);
json_obj_open_key(&e, "upatch");
json_kv_string(&e, "name", name);
+ hex_encode(payload, 32, hex);
+ json_kv_string(&e, "payload_sha256", hex);
+ json_obj_close(&e);
+ hex_encode(chain, 32, hex);
+ json_kv_string(&e, "chain", hex);
+ json_obj_close(&e);
+ if (e.err)
+ return e.err;
+ return eventlog_append(buf);
+}
+
+static int append_tree(__s64 seq, const char *op, const char *id,
+ const char *operation_digest, const __u8 event[32],
+ const __u8 chain[32])
+{
+ char buf[4096], ts[32], boot_id[64], nv_index[16], hex[65];
+ struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
+
+ eventlog_timestamp(ts, sizeof(ts));
+ eventlog_boot_id(boot_id, sizeof(boot_id));
+ snprintf(nv_index, sizeof(nv_index), "0x%08X", SHIRUDO_NV_INDEX);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 2);
+ json_kv_string(&e, "ts", ts);
+ json_kv_string(&e, "nv_index", nv_index);
+ json_kv_string(&e, "alg", "sha256");
+ hex_encode(event, 32, hex);
+ json_kv_string(&e, "digest", hex);
+ json_kv_string(&e, "type", "tree_op");
+ json_kv_string(&e, "boot_id", boot_id);
+ json_obj_open_key(&e, "tree");
+ json_kv_int(&e, "seq", seq);
+ json_kv_string(&e, "op", op);
+ json_kv_string(&e, "id", id);
+ json_kv_string(&e, "operation_digest", operation_digest);
json_obj_close(&e);
hex_encode(chain, 32, hex);
json_kv_string(&e, "chain", hex);
@@ -149,8 +186,26 @@ int main(int argc, char **argv)
return 1;
printf("value=");
puthex(chain, 32);
- return append_event("upatch_load", argv[2], event, chain) ?
- 1 : 0;
+ return append_event("upatch_load", argv[2], payload, event,
+ chain) ? 1 : 0;
+ }
+ /* A tree operation, with the digest in the form the target records. */
+ if (strcmp(argv[1], "tree") == 0 && argc == 6) {
+ __u8 operation[32];
+ __s64 seq = atoi(argv[2]);
+
+ if (strncmp(argv[5], "sha256:", 7) ||
+ hex_decode(argv[5] + 7, operation, 32))
+ return 2;
+ chain_tree_event(seq, operation, event);
+ rc = chain_extend(event, chain);
+ printf("rc=%d\n", rc);
+ if (rc)
+ return 1;
+ printf("value=");
+ puthex(chain, 32);
+ return append_tree(seq, argv[3], argv[4], argv[5], event,
+ chain) ? 1 : 0;
}
if (strcmp(argv[1], "extend-raw") == 0 && argc == 3) {
if (hex_decode(argv[2], event, 32))
@@ -283,6 +338,185 @@ int main(int argc, char **argv)
printf("rc=%d\n", rc);
return rc ? 1 : 0;
}
+ /*
+ * The attack: a register of the target's own at another handle,
+ * bound to PCRs the target can extend and reset at will, written
+ * with the init event the operator expects, anchored into one of
+ * those PCRs and certified by the genuine attestation key in the
+ * real register's place.
+ */
+ if (strcmp(argv[1], "forge") == 0 && argc == 7) {
+ struct shirudo_tpm_key ak = { .handle = 0 }, ek = { .handle = 0 };
+ struct shirudo_tpm_key ak_copy = {}, ek_copy = {};
+ struct shirudo_tpm_attestation quote = {}, certify = {};
+ char hex[2 * SHIRUDO_TPM_ATTEST_MAX + 1], buf[32 * 1024];
+ struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
+ __u8 branch_written[32], branch_init[32], policy[32];
+ __u8 values[24][32] = {}, before[64], anchor_digest[32];
+ char ts[32], boot_id[64], nv_index[16];
+ char anchor[SHIRUDO_CHAIN_ANCHOR_MAX];
+ size_t nonce_len = strlen(argv[6]) / 2;
+ struct shirudo_tpm *tpm = NULL;
+ __u32 index, pcr, phase, mask, quoted, reset = 0, i;
+ __u8 value[32], nonce[64];
+ struct tpm_nv_info nv;
+
+ index = (__u32)strtoul(argv[2], NULL, 16);
+ pcr = (__u32)atoi(argv[3]);
+ phase = (__u32)atoi(argv[4]);
+ mask = (1u << pcr) | (1u << phase);
+ quoted = SHIRUDO_ATTEST_PCR_DEFAULT | mask;
+ if (pcr > 23 || phase > 23 || pcr == phase ||
+ hex_decode(argv[5], event, 32) ||
+ nonce_len == 0 || nonce_len > sizeof(nonce) ||
+ hex_decode(argv[6], nonce, nonce_len))
+ return 2;
+ if (tpm_open(&tpm))
+ return 1;
+ rc = tpm_reset_count(tpm, &reset);
+ if (!rc)
+ rc = tpm_pcr_read(tpm, pcr, before);
+ if (!rc)
+ rc = tpm_pcr_read(tpm, phase, before + 32);
+ if (!rc) {
+ tpm_register_policy(mask, before, 2, branch_written,
+ branch_init, policy);
+ rc = tpm_nv_define(tpm, index, policy, NULL, 0);
+ }
+ if (!rc)
+ rc = tpm_nv_extend_first(tpm, index, mask,
+ branch_written, branch_init,
+ event);
+ if (!rc)
+ rc = tpm_nv_info(tpm, index, &nv);
+ if (!rc)
+ rc = chain_anchor(nv.name, anchor, sizeof(anchor));
+ if (!rc) {
+ shirudo_sha256(anchor, strlen(anchor), anchor_digest);
+ rc = tpm_pcr_extend(tpm, pcr, anchor_digest);
+ }
+ if (!rc)
+ rc = tpm_nv_read(tpm, index, value);
+ if (!rc)
+ rc = tpm_ak_create(tpm, &ak);
+ if (!rc)
+ rc = tpm_ek_create(tpm, false, &ek);
+ for (i = 0; !rc && i < 24; i++) {
+ if (quoted & (1u << i))
+ rc = tpm_pcr_read(tpm, i, values[i]);
+ }
+ if (!rc)
+ rc = tpm_quote(tpm, &ak, nonce, nonce_len, quoted,
+ &quote);
+ if (!rc)
+ rc = tpm_nv_certify(tpm, &ak, index, nonce, nonce_len,
+ &certify);
+ /* Flushing scrubs the key; keep the public parts. */
+ memcpy(&ak_copy, &ak, sizeof(ak_copy));
+ memcpy(&ek_copy, &ek, sizeof(ek_copy));
+ tpm_key_flush(tpm, &ek);
+ tpm_key_flush(tpm, &ak);
+ tpm_close(tpm);
+ if (rc) {
+ printf("rc=%d\n", rc);
+ return 1;
+ }
+
+ eventlog_timestamp(ts, sizeof(ts));
+ eventlog_boot_id(boot_id, sizeof(boot_id));
+ snprintf(nv_index, sizeof(nv_index), "0x%08X", index);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_kv_string(&e, "kind", "shirudo-attestation");
+ json_kv_string(&e, "version_id", shirudo_version_id);
+ json_kv_string(&e, "ts", ts);
+ json_kv_string(&e, "boot_id", boot_id);
+ hex_encode(nonce, nonce_len, hex);
+ json_kv_string(&e, "nonce", hex);
+ json_kv_string(&e, "pcr_bank", "sha256");
+ json_kv_int(&e, "pcr_mask", quoted);
+ json_arr_open(&e, "pcrs");
+ for (i = 0; i < 24; i++) {
+ if (!(quoted & (1u << i)))
+ continue;
+ json_obj_open(&e);
+ json_kv_int(&e, "index", i);
+ hex_encode(values[i], 32, hex);
+ json_kv_string(&e, "value", hex);
+ json_obj_close(&e);
+ }
+ json_arr_close(&e);
+ json_obj_open_key(&e, "ak");
+ hex_encode(ak_copy.public, ak_copy.public_len, hex);
+ json_kv_string(&e, "public", hex);
+ hex_encode(ak_copy.name, ak_copy.name_len, hex);
+ json_kv_string(&e, "name", hex);
+ json_obj_close(&e);
+ json_obj_open_key(&e, "ek");
+ json_kv_string(&e, "type", "ecc");
+ hex_encode(ek_copy.public, ek_copy.public_len, hex);
+ json_kv_string(&e, "public", hex);
+ hex_encode(ek_copy.name, ek_copy.name_len, hex);
+ json_kv_string(&e, "name", hex);
+ json_obj_close(&e);
+ json_obj_open_key(&e, "quote");
+ hex_encode(quote.attest, quote.attest_len, hex);
+ json_kv_string(&e, "attest", hex);
+ hex_encode(quote.signature, quote.signature_len, hex);
+ json_kv_string(&e, "signature", hex);
+ json_obj_close(&e);
+ json_obj_open_key(&e, "register");
+ json_kv_string(&e, "nv_index", nv_index);
+ json_kv_int(&e, "pcr", pcr);
+ hex_encode(nv.name, nv.name_len, hex);
+ json_kv_string(&e, "name", hex);
+ hex_encode(value, 32, hex);
+ json_kv_string(&e, "value", hex);
+ hex_encode(certify.attest, certify.attest_len, hex);
+ json_kv_string(&e, "attest", hex);
+ hex_encode(certify.signature, certify.signature_len, hex);
+ json_kv_string(&e, "signature", hex);
+ json_obj_close(&e);
+ json_arr_open(&e, "eventlog");
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 2);
+ json_kv_string(&e, "ts", ts);
+ json_kv_string(&e, "nv_index", nv_index);
+ json_kv_string(&e, "alg", "sha256");
+ hex_encode(event, 32, hex);
+ json_kv_string(&e, "digest", hex);
+ json_kv_string(&e, "type", "init");
+ json_kv_string(&e, "boot_id", boot_id);
+ json_kv_int(&e, "tpm_reset_count", reset);
+ json_kv_int(&e, "pcr", pcr);
+ hex_encode(before, 32, hex);
+ json_kv_string(&e, "pcr_before", hex);
+ json_kv_int(&e, "phase_pcr", phase);
+ hex_encode(before + 32, 32, hex);
+ json_kv_string(&e, "phase_before", hex);
+ json_kv_string(&e, "bound_in", "initrd");
+ hex_encode(nv.name, nv.name_len, hex);
+ json_kv_string(&e, "nv_name", hex);
+ json_kv_string(&e, "anchor", anchor);
+ hex_encode(anchor_digest, 32, hex);
+ json_kv_string(&e, "anchor_digest", hex);
+ hex_encode(value, 32, hex);
+ json_kv_string(&e, "chain", hex);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_kv_null(&e, "credential");
+ json_kv_null(&e, "ek_certificate");
+ json_obj_open_key(&e, "logs");
+ json_kv_null(&e, "firmware");
+ json_kv_null(&e, "systemd");
+ json_obj_close(&e);
+ json_obj_close(&e);
+ if (e.err)
+ return 1;
+ fwrite(buf, 1, e.len, stdout);
+ fputc('\n', stdout);
+ return 0;
+ }
if (strcmp(argv[1], "evidence") == 0 && (argc == 3 || argc == 4)) {
struct shirudo_attest_challenge challenge = {};
__u8 nonce[64];
diff --git a/testing/tpm/t0034-register.sh b/testing/tpm/t0034-register.sh
index ffb191b7..6e2a1a69 100644
--- a/testing/tpm/t0034-register.sh
+++ b/testing/tpm/t0034-register.sh
@@ -167,6 +167,62 @@ test_expect_success 'a wrong nonce, key name, binding value or tampered value fa
grep -q "^FAIL: register: certified contents" "$WORK/report4"
'
+# Root on the target defines an index of its own, bound to the debug and
+# application PCRs it can extend and reset at will, writes the init event
+# the operator expects into it, anchors it there and has the genuine
+# attestation key certify it in the real register's place. The evidence
+# is consistent in every value it carries; only the handle and the PCR
+# numbers, which the verifier must take from its own constants and not
+# from the document, give it away.
+test_expect_success 'a register of the target'"'"'s own, bound to PCRs it controls, is refused' '
+ nonce=0102030405060708090a0b0c0d0e0f10 &&
+ ./$R forge 01818e01 16 23 "$(cat "$WORK/init")" $nonce >"$WORK/forged.json" &&
+ [ "$(py "import json; print(json.load(open(\"$WORK/forged.json\"))[\"register\"][\"value\"])")" = \
+ "$(sha "$Z$(cat "$WORK/init")")" ] &&
+ ! $S attest verify --evidence="$WORK/forged.json" --nonce=$nonce \
+ --ak-name="$(cat "$WORK/ak")" --ek-name="$(cat "$WORK/ek")" \
+ --cert="$WORK/keys/cert.der" --strict-anchor --require-initrd \
+ >"$WORK/report-forged" &&
+ grep -q "^FAIL: register: the document names index 0x01818E00 and PCRs 9 and 11" \
+ "$WORK/report-forged" &&
+ grep -q "^ok: register: certified contents match the listed value" \
+ "$WORK/report-forged"
+'
+
+test_expect_success 'an event relabelled after the fact fails although the replay closes' '
+ nonce=0102030405060708090a0b0c0d0e0f10 &&
+ sed "s/\"type\":\"upatch_load\"/\"type\":\"upatch_unload\"/" \
+ "$WORK/evidence.json" >"$WORK/relabelled.json" &&
+ ! $S attest verify --evidence="$WORK/relabelled.json" --nonce=$nonce \
+ --ak-name="$(cat "$WORK/ak")" --cert="$WORK/keys/cert.der" \
+ --allow-runtime-events >"$WORK/report-relabelled" &&
+ grep -q "^ok: eventlog: 2 records replay to the certified value" \
+ "$WORK/report-relabelled" &&
+ grep -q "^FAIL: eventlog: event 1 (upatch_unload foo) digest does not derive from its fields" \
+ "$WORK/report-relabelled" &&
+ $S attest verify --evidence="$WORK/evidence.json" --nonce=$nonce \
+ --ak-name="$(cat "$WORK/ak")" --cert="$WORK/keys/cert.der" \
+ --allow-runtime-events >"$WORK/report-labelled" &&
+ ! grep -q "does not derive" "$WORK/report-labelled"
+'
+
+test_expect_success 'a tree operation records its digest as the target writes it' '
+ nonce=0102030405060708090a0b0c0d0e0f10 &&
+ before=$(./$R read | field value) &&
+ op=$(py "print(\"cd\"*32)") &&
+ event=$(py "import hashlib; print(hashlib.sha256(b\"shirudo-tree\\0\" + (1).to_bytes(8, \"big\") + bytes.fromhex(\"$op\")).hexdigest())") &&
+ out=$(./$R tree 1 append shirudo-test-tree "sha256:$op") &&
+ echo "$out" | grep -qx "rc=0" &&
+ [ "$(echo "$out" | field value)" = "$(sha "$before$event")" ] &&
+ ./$R evidence $nonce >"$WORK/evidence-tree.json" &&
+ $S attest verify --evidence="$WORK/evidence-tree.json" --nonce=$nonce \
+ --ak-name="$(cat "$WORK/ak")" --cert="$WORK/keys/cert.der" \
+ --allow-runtime-events >"$WORK/report-tree" &&
+ grep -qx "verdict: ok" "$WORK/report-tree" &&
+ grep -q "^ok: eventlog: 3 records replay to the certified value" "$WORK/report-tree" &&
+ ! grep -q "does not derive" "$WORK/report-tree"
+'
+
test_expect_success 'a challenge needs a vouched-for endorsement key' '
! $S attest challenge --evidence="$WORK/evidence.json" \
--out="$WORK/challenge-none.json" >"$WORK/challenge-none.out" &&
@@ -206,6 +262,16 @@ test_expect_success 'a challenge made from the evidence activates on the target'
grep -q "^ok: endorsement key: TCG default template" "$WORK/report-cred"
'
+test_expect_success 'a credential expectation needs the pinned attestation key' '
+ nonce=1112 &&
+ $S attest verify --evidence="$WORK/evidence-cred.json" --nonce=$nonce \
+ --cert="$WORK/keys/cert.der" --allow-runtime-events \
+ --expect-credential="$(cat "$WORK/credential")" \
+ >/dev/null 2>"$WORK/cred-unpinned.err"; rc=$? &&
+ [ "$rc" = 2 ] &&
+ grep -q "give --ak-name" "$WORK/cred-unpinned.err"
+'
+
test_expect_success 'a wrong credential, a tampered blob and a foreign challenge are refused' '
nonce=1112 &&
! $S attest verify --evidence="$WORK/evidence-cred.json" --nonce=$nonce \
@@ -257,7 +323,7 @@ test_expect_success 'a recreated index is unwritable and no longer anchored' '
test_expect_success 'init refuses a second binding before the next TPM reset' '
./$R init "$(cat "$WORK/init")" | grep -qx "rc=-17" &&
- [ "$(wc -l <"$WORK/eventlog")" = 2 ] &&
+ [ "$(wc -l <"$WORK/eventlog")" = 3 ] &&
./$R status | grep -qx "rebound=0"
'
diff --git a/util/attest.c b/util/attest.c
index c2815538..3eed9f37 100644
--- a/util/attest.c
+++ b/util/attest.c
@@ -426,6 +426,7 @@ struct record {
char type[16];
char label[SHIRUDO_UPATCH_NAME_MAX + 64];
__u8 digest[32];
+ bool derived; /* digest follows from the record's fields */
};
struct init_record {
@@ -478,10 +479,13 @@ struct parse {
__s64 rec_phase_pcr;
__s64 rec_reset;
char upatch_name[SHIRUDO_UPATCH_NAME_MAX + 1];
+ char upatch_payload_hex[65];
char tree_id[SHIRUDO_UPATCH_NAME_MAX + 1];
char tree_op[16];
+ char tree_digest_hex[sizeof("sha256:") + 64];
__s64 tree_seq;
char key_fingerprint[65];
+ char key_sha_hex[65];
struct record *recs;
size_t n_recs;
__u32 inits; /* init records this boot */
@@ -556,22 +560,49 @@ static int on_record(void *ctx)
memset(r, 0, sizeof(*r));
strscpy(r->type, "init", sizeof(r->type));
memcpy(r->digest, in->digest, 32);
- } else if (!strncmp(p->type, "upatch_", 7)) {
+ } else if (!strcmp(p->type, "upatch_load") ||
+ !strcmp(p->type, "upatch_unload")) {
+ bool load = p->type[7] == 'l';
+ __u8 payload[32], event[32];
+
strscpy(r->label, p->upatch_name, sizeof(r->label));
+ if (!hex_decode(p->upatch_payload_hex, payload, 32)) {
+ chain_upatch_event(load ? "shirudo-upatch" :
+ "shirudo-unload", p->upatch_name,
+ payload, event);
+ r->derived = ct_eq(event, r->digest, 32);
+ }
} else if (!strcmp(p->type, "tree_op")) {
+ __u8 operation[32], event[32];
+
if (strsprintf(r->label, sizeof(r->label), "%s %s seq %lld",
p->tree_op, p->tree_id, (__s64)p->tree_seq) < 0)
return -E2BIG;
- } else if (!strncmp(p->type, "key_", 4)) {
+ if (p->tree_seq > 0 &&
+ !strncmp(p->tree_digest_hex, "sha256:", 7) &&
+ !hex_decode(p->tree_digest_hex + 7, operation, 32)) {
+ chain_tree_event(p->tree_seq, operation, event);
+ r->derived = ct_eq(event, r->digest, 32);
+ }
+ } else if (!strcmp(p->type, "key_revoke")) {
+ __u8 sha[32], event[32];
+
strscpy(r->label, p->key_fingerprint, sizeof(r->label));
+ if (!hex_decode(p->key_sha_hex, sha, 32)) {
+ chain_key_event("shirudo-key-revoke", sha, event);
+ r->derived = ct_eq(event, r->digest, 32);
+ }
}
p->n_recs++;
/* Reset the per-element scratch the next element may not set. */
p->type[0] = '\0';
p->upatch_name[0] = '\0';
+ p->upatch_payload_hex[0] = '\0';
p->tree_id[0] = '\0';
p->tree_op[0] = '\0';
+ p->tree_digest_hex[0] = '\0';
p->key_fingerprint[0] = '\0';
+ p->key_sha_hex[0] = '\0';
p->anchor[0] = '\0';
p->bound_in[0] = '\0';
p->tree_seq = 0;
@@ -773,11 +804,16 @@ int attest_verify(const char *evidence, size_t len,
struct shirudo_json_field upatch_sub[] = {
{ "name", SHIRUDO_JSON_T_STRING, p->upatch_name,
sizeof(p->upatch_name), 0, NULL, 0 },
+ { "payload_sha256", SHIRUDO_JSON_T_STRING,
+ p->upatch_payload_hex, sizeof(p->upatch_payload_hex),
+ 0, NULL, 0 },
};
struct shirudo_json_field key_sub[] = {
{ "fingerprint", SHIRUDO_JSON_T_STRING,
p->key_fingerprint, sizeof(p->key_fingerprint), 0,
NULL, 0 },
+ { "cert_sha256", SHIRUDO_JSON_T_STRING, p->key_sha_hex,
+ sizeof(p->key_sha_hex), 0, NULL, 0 },
};
struct shirudo_json_field tree_sub[] = {
{ "seq", SHIRUDO_JSON_T_INT, &p->tree_seq, 0, 0, NULL,
@@ -786,6 +822,9 @@ int attest_verify(const char *evidence, size_t len,
sizeof(p->tree_op), 0, NULL, 0 },
{ "id", SHIRUDO_JSON_T_STRING, p->tree_id,
sizeof(p->tree_id), 0, NULL, 0 },
+ { "operation_digest", SHIRUDO_JSON_T_STRING,
+ p->tree_digest_hex, sizeof(p->tree_digest_hex), 0,
+ NULL, 0 },
};
struct shirudo_json_field rec_sub[] = {
{ "type", SHIRUDO_JSON_T_STRING, p->type,
@@ -1044,32 +1083,40 @@ int attest_verify(const char *evidence, size_t len,
* register bound to the recorded PCR values has, which is what
* makes a recreation impossible to pass off, and those values are
* what the operator pins to tell an initrd binding from a later one.
+ * The handle and the PCRs are the register's, never the document's:
+ * taken from the record, a target could certify an index of its own
+ * under a policy over PCRs it can extend and reset at will.
*/
say(&rep, p->init.present, "eventlog: this boot has an init record");
if (!p->init.present) {
rc = -EKEYREJECTED;
goto out;
}
+ say(&rep, reg_index == SHIRUDO_NV_INDEX &&
+ (__u32)p->reg_pcr == SHIRUDO_CHAIN_PCR &&
+ p->init.pcr == SHIRUDO_CHAIN_PCR &&
+ p->init.phase_pcr == SHIRUDO_CHAIN_PHASE_PCR,
+ "register: the document names index 0x%08X and PCRs %u and %u",
+ SHIRUDO_NV_INDEX, SHIRUDO_CHAIN_PCR, SHIRUDO_CHAIN_PHASE_PCR);
memcpy(bind, p->init.pcr_before, 32);
memcpy(bind + 32, p->init.phase_before, 32);
- tpm_register_policy((1u << p->init.pcr) |
- (1u << p->init.phase_pcr), bind, 2,
+ tpm_register_policy(SHIRUDO_CHAIN_PCR_MASK, bind, 2,
branch_written, branch_init, policy);
- tpm_nv_name(reg_index,
+ tpm_nv_name(SHIRUDO_NV_INDEX,
SHIRUDO_TPM_REGISTER_ATTRS | SHIRUDO_TPM_NV_WRITTEN,
policy, 32, expected_name);
- say(&rep, (__u32)p->reg_pcr == p->init.pcr &&
- ct_eq(expected_name, reg_name, SHIRUDO_TPM_NAME_LEN) &&
+ say(&rep, ct_eq(expected_name, reg_name, SHIRUDO_TPM_NAME_LEN) &&
ct_eq(expected_name, p->init.name, SHIRUDO_TPM_NAME_LEN),
"register: public area is bound to PCRs %u and %u as recorded",
- p->init.pcr, p->init.phase_pcr);
+ SHIRUDO_CHAIN_PCR, SHIRUDO_CHAIN_PHASE_PCR);
for (bit = 0; bit < 24; bit++) {
const __u8 *held;
if (!(expect->bind_expect_mask & (1u << bit)))
continue;
- held = bit == p->init.pcr ? p->init.pcr_before :
- bit == p->init.phase_pcr ? p->init.phase_before : NULL;
+ held = bit == SHIRUDO_CHAIN_PCR ? p->init.pcr_before :
+ bit == SHIRUDO_CHAIN_PHASE_PCR ? p->init.phase_before :
+ NULL;
say(&rep, held && ct_eq(held, expect->bind_values[bit],
32),
"binding: PCR %u held the expected value", bit);
@@ -1102,6 +1149,17 @@ int attest_verify(const char *evidence, size_t len,
say(&rep, ct_eq(chain, reg_value, 32),
"eventlog: %zu record%s replay to the certified value", p->n_recs,
p->n_recs == 1 ? "" : "s");
+ /*
+ * A digest the record's own fields do not produce is a record
+ * relabelled after the fact: the replay still closes, but what the
+ * events say happened is not what was measured.
+ */
+ for (i = 1; i < p->n_recs; i++) {
+ if (!p->recs[i].derived)
+ say(&rep, false, "eventlog: event %zu (%s %s) digest "
+ "does not derive from its fields", i,
+ p->recs[i].type, p->recs[i].label);
+ }
{
char anchor[SHIRUDO_CHAIN_ANCHOR_MAX];
@@ -1114,21 +1172,22 @@ int attest_verify(const char *evidence, size_t len,
"anchor: record digest matches the index name");
memcpy(pcr_expected, p->init.pcr_before, 32);
chain_fold(pcr_expected, anchor_digest);
- if (p->pcr_have & (1u << p->init.pcr)) {
+ if (p->pcr_have & (1u << SHIRUDO_CHAIN_PCR)) {
bool exact = ct_eq(pcr_expected,
- p->pcrs[p->init.pcr], 32);
+ p->pcrs[SHIRUDO_CHAIN_PCR], 32);
if (exact || expect->strict_anchor)
say(&rep, exact, "anchor: PCR %u equals the "
"recorded value extended by the anchor",
- p->init.pcr);
+ SHIRUDO_CHAIN_PCR);
else
note(&rep, "anchor: PCR %u carries further "
"measurements after the anchor; replay "
- "the logs to confirm it", p->init.pcr);
+ "the logs to confirm it",
+ SHIRUDO_CHAIN_PCR);
} else {
say(&rep, false, "anchor: PCR %u is not in the quote",
- p->init.pcr);
+ SHIRUDO_CHAIN_PCR);
}
}