Skip to content

eBPF-based security platform

cli: take option values after a space too and name options alike

Daniel Borkmanne5054b92ec08
diff --git a/.gitignore b/.gitignore
index a13378db..988a831f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,7 +20,7 @@
*.upatch.json
# Local bpf-next kernel and userspace dependency artifacts
-/artifacts/
+/artifacts
# Generated headers
/vmlinux.h
diff --git a/Documentation/internals/seal.rst b/Documentation/internals/seal.rst
index 346c9bd3..9113acc2 100644
--- a/Documentation/internals/seal.rst
+++ b/Documentation/internals/seal.rst
@@ -233,7 +233,7 @@ shirudo's readers do not trust an entry because it is there. They open
each path component without following symbolic links and require every
entry under a labeled directory to carry its parent's label; anything
else is reported as a foreign entry and refused. A path a caller names
-for shirudo to write, such as ``--report`` or ``--out``, must be an
+for shirudo to write, such as ``--report`` or ``--output``, must be an
unlabeled regular file outside any labeled directory, so a task with
runtime authority cannot be pointed at sealed state.
diff --git a/Documentation/operate/run/attest.rst b/Documentation/operate/run/attest.rst
index 3b09aa68..d5801298 100644
--- a/Documentation/operate/run/attest.rst
+++ b/Documentation/operate/run/attest.rst
@@ -107,7 +107,7 @@ you trust.
.. code-block:: console
- target# shirudo attest --nonce=<nonce> --out=enroll.json
+ target# shirudo attest --nonce=<nonce> --output=enroll.json
``<nonce>`` is the hex string from step 1. The command prints nothing
on success and writes the file with mode ``0600``. Copy
@@ -126,7 +126,7 @@ you trust.
.. code-block:: console
operator$ shirudo attest challenge --evidence=enroll.json \
- --ak-name=<ak-name> --ek-ca=<ek-issuers.pem> --out=challenge.json
+ --ak-name=<ak-name> --ek-ca=<ek-issuers.pem> --output=challenge.json
``<ak-name>`` is the name from step 3. ``<ek-issuers.pem>`` is your
manufacturer's issuer bundle. The endorsement certificate in the
@@ -144,7 +144,7 @@ you trust.
.. code-block:: console
target# shirudo attest --nonce=<nonce-2> --challenge=challenge.json \
- --out=answer.json
+ --output=answer.json
The TPM can recover the credential only when the attestation key and
the endorsement key are in it. The command refuses with
@@ -218,7 +218,7 @@ Collect evidence
.. code-block:: console
- target# shirudo attest --nonce=<nonce> --out=ev.json
+ target# shirudo attest --nonce=<nonce> --output=ev.json
The evidence holds the TPM quote of PCRs 0 to 7, 9 and 11 to 15, the
certified register, this boot's eventlog records and the config
diff --git a/Documentation/operate/troubleshoot/incident-tampered.rst b/Documentation/operate/troubleshoot/incident-tampered.rst
index 42d3e4d4..a4cd5949 100644
--- a/Documentation/operate/troubleshoot/incident-tampered.rst
+++ b/Documentation/operate/troubleshoot/incident-tampered.rst
@@ -111,7 +111,7 @@ Preserve the evidence
.. code-block:: console
- target# shirudo attest --nonce=<nonce> --out=evidence/evidence.json
+ target# shirudo attest --nonce=<nonce> --output=evidence/evidence.json
When the config cannot be verified or its activation is pending,
every command but ``status`` and ``image status`` refuses,
diff --git a/Documentation/reference/cheat-sheet.rst b/Documentation/reference/cheat-sheet.rst
index 1e8eb57e..9674fe83 100644
--- a/Documentation/reference/cheat-sheet.rst
+++ b/Documentation/reference/cheat-sheet.rst
@@ -281,7 +281,7 @@ Produce evidence for that nonce on the target with :doc:`cli/attest`:
.. code-block:: console
- target# shirudo attest --nonce=<nonce> --out=ev.json
+ target# shirudo attest --nonce=<nonce> --output=ev.json
Read the attestation key name to pin at enrollment:
@@ -294,13 +294,13 @@ Make a credential challenge for the pinned key with
.. code-block:: console
- operator$ shirudo attest challenge --evidence=ev.json --ak-name=<ak-name> --ek-ca=<tpm-vendor-roots> --out=challenge.json
+ operator$ shirudo attest challenge --evidence=ev.json --ak-name=<ak-name> --ek-ca=<tpm-vendor-roots> --output=challenge.json
Answer the challenge on the target with :doc:`cli/attest`:
.. code-block:: console
- target# shirudo attest --nonce=<nonce> --challenge=challenge.json --out=ev.json
+ target# shirudo attest --nonce=<nonce> --challenge=challenge.json --output=ev.json
Predict the register for the certificates the target enrolls and a load
after boot with :doc:`cli/attest-predict`:
diff --git a/Documentation/reference/cli/attest-challenge.rst b/Documentation/reference/cli/attest-challenge.rst
index d1c3ad29..aabd2e7e 100644
--- a/Documentation/reference/cli/attest-challenge.rst
+++ b/Documentation/reference/cli/attest-challenge.rst
@@ -20,7 +20,7 @@ Usage
.. code-block:: none
- shirudo attest challenge --evidence=<evidence> --out=<challenge>
+ shirudo attest challenge --evidence=<evidence> --output=<challenge>
(--ek-ca=<bundle> | --ek-name=<name> | --trust-presented-ek)
[--ak-name=<name>]
@@ -47,7 +47,7 @@ to the target's endorsement key:
Without any of the three, the check fails.
#. It makes a random 32-byte credential, protects it for the endorsement
- key and the attestation key name, writes the challenge to ``--out``
+ key and the attestation key name, writes the challenge to ``--output``
with mode 0600 and prints ``challenge: <path>`` and
``credential: <hex>``.
@@ -68,7 +68,7 @@ Options
* - ``--evidence``
- ``<evidence>``, a file
- Required. Evidence from the target.
- * - ``--out``
+ * - ``--output``
- ``<challenge>``, a path
- Required. Where to write the challenge.
* - ``--ak-name``
@@ -99,7 +99,7 @@ Exit status
- A check failed (``verdict: fail``), or the challenge could not be
written.
* - 2
- - ``--evidence`` or ``--out`` missing, an unknown option or invalid
+ - ``--evidence`` or ``--output`` missing, an unknown option or invalid
value, an unreadable evidence file, or evidence that carries no
endorsement key.
@@ -110,7 +110,7 @@ Make a challenge for a target whose TPM vendor roots you hold:
.. code-block:: console
- operator$ shirudo attest challenge --evidence=ev.json --ak-name=<ak-name> --ek-ca=<tpm-vendor-roots> --out=challenge.json
+ operator$ shirudo attest challenge --evidence=ev.json --ak-name=<ak-name> --ek-ca=<tpm-vendor-roots> --output=challenge.json
``<ak-name>`` is ``.ak.name`` of the evidence (:doc:`attest`) and
``<tpm-vendor-roots>`` a PEM bundle of the TPM manufacturers' issuing
diff --git a/Documentation/reference/cli/attest.rst b/Documentation/reference/cli/attest.rst
index d3b1155d..95e1d69a 100644
--- a/Documentation/reference/cli/attest.rst
+++ b/Documentation/reference/cli/attest.rst
@@ -21,7 +21,7 @@ Usage
.. code-block:: none
shirudo attest [--nonce=<nonce>] [--pcrs=<list>] [--challenge=<challenge>]
- [--out=<path>]
+ [--output=<path>]
shirudo attest verify ...
shirudo attest predict ...
shirudo attest challenge ...
@@ -80,7 +80,7 @@ Options
- ``<challenge>``, a file
- none
- Credential challenge from ``attest challenge`` to activate.
- * - ``--out``
+ * - ``--output``
- ``<path>``
- standard output
- Write the evidence to ``<path>`` with mode 0600. A path in sealed
@@ -111,7 +111,7 @@ Files and environment
- Reads the TPM, ``/var/lib/shirudo/eventlog``, the config activation
records and the firmware and systemd event logs
-- Writes ``--out``
+- Writes ``--output``
Examples
--------
@@ -126,7 +126,7 @@ On the target, produce evidence for that nonce:
.. code-block:: console
- target# shirudo attest --nonce=a707993af885f29e88a1f9e936a3ccf9806b8d8b02c43dfe56fe571ce0f200d3 --out=ev.json
+ target# shirudo attest --nonce=a707993af885f29e88a1f9e936a3ccf9806b8d8b02c43dfe56fe571ce0f200d3 --output=ev.json
``attest`` prints nothing on success and writes ``ev.json`` with mode
0600. The document is JSON with the keys ``schema``, ``kind``
diff --git a/Documentation/reference/cli/bpm.rst b/Documentation/reference/cli/bpm.rst
index 06398964..e6d24a6a 100644
--- a/Documentation/reference/cli/bpm.rst
+++ b/Documentation/reference/cli/bpm.rst
@@ -21,11 +21,11 @@ Usage
.. code-block:: none
- shirudo bpm config register add <source> oci://<registry> (--key-file <certificate> | --key-file=<certificate>)
+ shirudo bpm config register add <source> oci://<registry> (--cert <certificate> | --cert=<certificate>)
shirudo bpm config register list [--json]
shirudo bpm config register (remove | rm) <source>
shirudo bpm config update --base-package <package> --version <version>
- [-f <beefile> | --file <beefile>]
+ [--file <beefile>]
[--rodata-input <name>=<path>]... [--keys-dir <dir>]
shirudo bpm repo update [<source>]
shirudo bpm tree sync [--dry-run] [--report <path> | --report=<path>]
@@ -38,7 +38,7 @@ Usage
shirudo bpm info data <package> <member> [--json]
shirudo bpm push <package> oci://<registry>/<repository>
[--keys-dir <dir> | --index-cert <certificate> --index-key <signing-key>]
- shirudo bpm build [<context>] --version <version> [-f <beefile> | --file <beefile>]
+ shirudo bpm build [<context>] --version <version> [--file <beefile>]
[--keys-dir <dir>] [--vmlinux <vmlinux-h>]
[--rodata-input <name>=<path>]...
shirudo bpm install <source>/<name>[@<version>]
@@ -132,9 +132,9 @@ image, the image's ``etc/shirudo/bpm/registries.d/`` is used instead, and
image mode: change repository definitions and keys in a signed config image, then run `shirudo image update`
- ``add`` checks that the endpoint is ``oci://<host>[:<port>]`` without a
- path and that ``--key-file`` is a certificate, copies the certificate to
+ path and that ``--cert`` is a certificate, copies the certificate to
``/etc/shirudo/bpm/keys/<source>.der`` and writes the source file.
- Arguments after the endpoint other than ``--key-file`` are ignored.
+ Arguments after the endpoint other than ``--cert`` are ignored.
- ``list`` prints the registered source names, one per line.
- ``remove`` and ``rm`` delete the source file and its certificate.
diff --git a/Documentation/reference/cli/shirudo.rst b/Documentation/reference/cli/shirudo.rst
index 58d8e3a1..638d0bb3 100644
--- a/Documentation/reference/cli/shirudo.rst
+++ b/Documentation/reference/cli/shirudo.rst
@@ -123,6 +123,17 @@ of ``image``, the actions of ``bpm config register`` and the words
``shirudo --list-cmds`` and ``shirudo help --list-cmds`` print the
command names one per line. Bash completion reads them from there.
+Option forms
+~~~~~~~~~~~~
+
+An option that takes a value takes it after an equals sign or as the
+next argument: ``--cert=cert.der`` and ``--cert cert.der`` are the
+same. The same function has the same name on every command: a file to
+write is ``-o <path>`` or ``--output <path>``, a certificate file is
+``--cert``, a signing key ``--key``, the directory that holds both
+``--keys-dir``, a Beefile ``--file``, and ``--json`` prints the JSON form
+wherever a command has one.
+
Runtime binary
~~~~~~~~~~~~~~
diff --git a/Documentation/start/guides/attest-target.rst b/Documentation/start/guides/attest-target.rst
index a88052a0..bab53722 100644
--- a/Documentation/start/guides/attest-target.rst
+++ b/Documentation/start/guides/attest-target.rst
@@ -62,7 +62,7 @@ Take the first evidence
.. code-block:: console
- target# shirudo attest --nonce=<nonce1> --out=/mnt/shirudo-out/first.json
+ target# shirudo attest --nonce=<nonce1> --output=/mnt/shirudo-out/first.json
``<nonce1>`` is the value you printed.
@@ -90,7 +90,7 @@ Challenge the attestation key
.. code-block:: console
- operator$ shirudo attest challenge --evidence="$RESULT/first.json" --ak-name="$AK" --trust-presented-ek --out="$RESULT/challenge.json"
+ operator$ shirudo attest challenge --evidence="$RESULT/first.json" --ak-name="$AK" --trust-presented-ek --output="$RESULT/challenge.json"
OK attestation key: the pinned key
OK endorsement key: name matches its public area
OK endorsement key: TCG default template under the endorsement policy
@@ -139,7 +139,7 @@ Answer the challenge on the target
.. code-block:: console
- target# shirudo attest --nonce=<nonce2> --challenge=/mnt/shirudo-out/challenge.json --out=/mnt/shirudo-out/enrolled.json
+ target# shirudo attest --nonce=<nonce2> --challenge=/mnt/shirudo-out/challenge.json --output=/mnt/shirudo-out/enrolled.json
The TPM activates the credential for its attestation key, and the
evidence carries the recovered value. A challenge made for another
@@ -245,7 +245,7 @@ Verify evidence
.. code-block:: console
- target# shirudo attest --nonce=<nonce3> --out=/mnt/shirudo-out/ev.json
+ target# shirudo attest --nonce=<nonce3> --output=/mnt/shirudo-out/ev.json
3. Verify it with the pinned key and the predicted register:
diff --git a/Documentation/start/quickstart.rst b/Documentation/start/quickstart.rst
index 356e9405..300768ae 100644
--- a/Documentation/start/quickstart.rst
+++ b/Documentation/start/quickstart.rst
@@ -437,7 +437,7 @@ nothing but the evidence, your certificates and your artifacts.
.. code-block:: console
- target# shirudo attest --nonce=<nonce> --out=/mnt/shirudo-out/ev.json
+ target# shirudo attest --nonce=<nonce> --output=/mnt/shirudo-out/ev.json
``<nonce>`` is the value you printed. The TPM signs a quote over the
PCRs and a certification of the register with its attestation key, and
diff --git a/builtin-attest.c b/builtin-attest.c
index ef018d50..3d850340 100644
--- a/builtin-attest.c
+++ b/builtin-attest.c
@@ -49,7 +49,7 @@ static const struct help_item attest_options[] = {
{ "--nonce=<hex>", "freshness value from the verifier (up to 64 bytes)" },
{ "--pcrs=<list>", "PCRs to quote, comma separated (default 0-7,9,11-15)" },
{ "--challenge=<path>", "a challenge from the verifier to activate while attesting" },
- { "--out=<path>", "write the evidence there (0600) instead of stdout" },
+ { "-o, --output <path>", "write the evidence there (0600) instead of stdout" },
};
static const struct help_item verify_options[] = {
@@ -79,7 +79,7 @@ static const struct help_item challenge_options[] = {
{ "--ek-ca=<bundle>", "PEM issuers the endorsement certificate must chain to" },
{ "--ek-name=<hex>", "an endorsement key name known out of band" },
{ "--trust-presented-ek", "accept an endorsement key nothing vouches for" },
- { "--out=<path>", "write the challenge there (0600)" },
+ { "-o, --output <path>", "write the challenge there (0600)" },
};
static const struct help_item predict_options[] = {
@@ -108,12 +108,12 @@ static const struct help_section attest_help_sections[] = {
static const struct help attest_help = {
.usage = "shirudo attest [--nonce=<hex>] [--pcrs=<list>] "
- "[--challenge=<path>] [--out=<path>]\n"
+ "[--challenge=<path>] [--output=<path>]\n"
" shirudo attest verify --evidence=<path> --nonce=<hex> "
"--ak-name=<hex> [options]\n"
" shirudo attest predict --cert=<cert.der> [options]\n"
" shirudo attest challenge --evidence=<path> "
- "--out=<path> --ek-ca=<bundle>|--ek-name=<hex>|"
+ "--output=<path> --ek-ca=<bundle>|--ek-name=<hex>|"
"--trust-presented-ek [options]",
.summary = "Without a subcommand: emit a TPM-signed evidence document "
"for this\ntarget (quote over the PCRs, certification of "
@@ -328,46 +328,76 @@ static int cmd_attest_predict(int argc, const char **argv)
return 1;
for (i = 2; i < (size_t)argc; i++) {
const char *a = argv[i];
+ const char *v = NULL;
+ enum opt_status r;
- if (!strncmp(a, "--cert=", 7)) {
+ if (opt_arg("--cert", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest predict: %s takes a value", a);
+ goto out;
+ }
if (n_certs >= KEYS_MAX) {
pr_err("attest predict: at most %d --cert",
KEYS_MAX);
goto out;
}
- if (cert_digest(a + 7, cert_shas[n_certs]))
+ if (cert_digest(v, cert_shas[n_certs]))
goto out;
n_certs++;
have_cert = true;
- } else if (!strncmp(a, "--upatch=", 9)) {
- if (member_add_file(&m, a + 9))
+ } else if (opt_arg("--upatch", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest predict: %s takes a value", a);
+ goto out;
+ }
+ if (member_add_file(&m, v))
goto out;
- } else if (!strncmp(a, "--expect=", 9)) {
- if (member_add_spec(&m, a + 9)) {
- pr_err("attest: bad --expect '%s'", a + 9);
+ } else if (opt_arg("--expect", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest predict: %s takes a value", a);
+ goto out;
+ }
+ if (member_add_spec(&m, v)) {
+ pr_err("attest: bad --expect '%s'", v);
+ goto out;
+ }
+ } else if (opt_arg("--tree-root", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest predict: %s takes a value", a);
goto out;
}
- } else if (!strncmp(a, "--tree-root=", 12)) {
- if (parse_hex32("--tree-root", a + 12, tree_root))
+ if (parse_hex32("--tree-root", v, tree_root))
goto out;
- } else if (!strncmp(a, "--event=", 8)) {
+ } else if (opt_arg("--event", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest predict: %s takes a value", a);
+ goto out;
+ }
if (n_events >= EVENTS_MAX)
goto out;
- events[n_events++] = a + 8;
- } else if (!strncmp(a, "--writer-public=", 16)) {
- if (hex_decode(a + 16, writer_public, sizeof(writer_public))) {
+ events[n_events++] = v;
+ } else if (opt_arg("--writer-public", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest predict: %s takes a value", a);
+ goto out;
+ }
+ if (hex_decode(v, writer_public, sizeof(writer_public))) {
pr_err("attest predict: invalid RSA-3072 --writer-public");
goto out;
}
have_writer = true;
} else if (!strcmp(a, "--json")) {
po.json = true;
- } else if (!strncmp(a, "--bind-pcr=", 11)) {
+ } else if (opt_arg("--bind-pcr", a, argc, argv, &i, &v, &r)) {
const char *value = NULL;
int slot = -1;
__u64 n;
- if (!parse_pcr_value(a + 11, &n, &value))
+ if (r == OPT_MISSING) {
+ pr_err("attest predict: %s takes a value", a);
+ goto out;
+ }
+ if (!parse_pcr_value(v, &n, &value))
slot = n == CHAIN_PCR ? 0 :
n == CHAIN_PHASE_PCR ? 1 : -1;
if (slot < 0 ||
@@ -594,11 +624,23 @@ static int cmd_attest_verify(int argc, const char **argv)
goto out;
for (i = 2; i < (size_t)argc; i++) {
const char *a = argv[i];
+ const char *v = NULL;
+ enum opt_status r;
- if (!strncmp(a, "--evidence=", 11)) {
- evidence_path = a + 11;
- } else if (!strncmp(a, "--nonce=", 8)) {
- if (parse_hex(a + 8, nonce, sizeof(nonce),
+ if (opt_arg("--evidence", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ evidence_path = v;
+ } else if (opt_arg("--nonce", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ if (parse_hex(v, nonce, sizeof(nonce),
&nonce_len)) {
pr_err("attest verify: --nonce must be hex of "
"up to %d bytes",
@@ -606,10 +648,15 @@ static int cmd_attest_verify(int argc, const char **argv)
goto out;
}
have_nonce = true;
- } else if (!strncmp(a, "--ak-name=", 10)) {
+ } else if (opt_arg("--ak-name", a, argc, argv, &i, &v, &r)) {
size_t n;
- if (parse_hex(a + 10, x.ak_name, sizeof(x.ak_name),
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ if (parse_hex(v, x.ak_name, sizeof(x.ak_name),
&n) || n != TPM_NAME_LEN) {
pr_err("attest verify: --ak-name must be %d "
"hex characters",
@@ -617,53 +664,93 @@ static int cmd_attest_verify(int argc, const char **argv)
goto out;
}
x.have_ak_name = true;
- } else if (!strncmp(a, "--cert=", 7)) {
+ } else if (opt_arg("--cert", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
if (n_certs >= KEYS_MAX) {
pr_err("attest verify: at most %d --cert",
KEYS_MAX);
goto out;
}
- if (cert_digest(a + 7, cert_shas[n_certs]))
+ if (cert_digest(v, cert_shas[n_certs]))
goto out;
n_certs++;
have_cert = true;
- } else if (!strncmp(a, "--upatch=", 9)) {
- if (member_add_file(&m, a + 9))
+ } else if (opt_arg("--upatch", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ if (member_add_file(&m, v))
goto out;
- } else if (!strncmp(a, "--expect=", 9)) {
- if (member_add_spec(&m, a + 9)) {
+ } else if (opt_arg("--expect", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ if (member_add_spec(&m, v)) {
pr_err("attest verify: bad --expect '%s'",
- a + 9);
+ v);
+ goto out;
+ }
+ } else if (opt_arg("--tree-root", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
goto out;
}
- } else if (!strncmp(a, "--tree-root=", 12)) {
- if (parse_hex32("--tree-root", a + 12, tree_root))
+ if (parse_hex32("--tree-root", v, tree_root))
goto out;
have_tree_root = true;
- } else if (!strncmp(a, "--expect-config-root=", 21)) {
+ } else if (opt_arg("--expect-config-root", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
if (x.have_config_root ||
- parse_hex32("--expect-config-root", a + 21,
+ parse_hex32("--expect-config-root", v,
x.config_root))
goto out;
x.have_config_root = true;
- } else if (!strncmp(a, "--expect-config-pcr=", 20)) {
+ } else if (opt_arg("--expect-config-pcr", a, argc, argv, &i, &v, &r)) {
__u64 pcr;
- if (parse_u64(a + 20, strlen(a + 20), 15, &pcr) ||
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ if (parse_u64(v, strlen(v), 15, &pcr) ||
x.have_config_pcr ||
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))
+ } else if (opt_arg("--expect-chain", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ if (parse_hex32("--expect-chain", v, x.chain))
goto out;
x.have_chain = true;
- } else if (!strncmp(a, "--expect-pcr=", 13)) {
+ } else if (opt_arg("--expect-pcr", a, argc, argv, &i, &v, &r)) {
const char *value;
__u64 n;
- if (parse_pcr_value(a + 13, &n, &value) ||
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ if (parse_pcr_value(v, &n, &value) ||
parse_hex32("--expect-pcr value", value, x.pcrs[n]))
goto out;
x.pcr_expect_mask |= 1u << n;
@@ -673,15 +760,25 @@ static int cmd_attest_verify(int argc, const char **argv)
x.allow_runtime_events = true;
} else if (!strcmp(a, "--strict-anchor")) {
x.strict_anchor = true;
- } else if (!strncmp(a, "--expect-credential=", 20)) {
- if (parse_hex32("--expect-credential", a + 20,
+ } else if (opt_arg("--expect-credential", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ if (parse_hex32("--expect-credential", v,
x.credential))
goto out;
x.have_credential = true;
- } else if (!strncmp(a, "--ek-name=", 10)) {
+ } else if (opt_arg("--ek-name", a, argc, argv, &i, &v, &r)) {
size_t n;
- if (parse_hex(a + 10, x.ek_name, sizeof(x.ek_name),
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ if (parse_hex(v, x.ek_name, sizeof(x.ek_name),
&n) || n != TPM_NAME_LEN) {
pr_err("attest verify: --ek-name must be %d "
"hex characters",
@@ -689,11 +786,16 @@ static int cmd_attest_verify(int argc, const char **argv)
goto out;
}
x.have_ek_name = true;
- } else if (!strncmp(a, "--expect-bind-pcr=", 18)) {
+ } else if (opt_arg("--expect-bind-pcr", a, argc, argv, &i, &v, &r)) {
const char *value;
__u64 n;
- if (parse_pcr_value(a + 18, &n, &value) ||
+ if (r == OPT_MISSING) {
+ pr_err("attest verify: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ if (parse_pcr_value(v, &n, &value) ||
parse_hex32("--expect-bind-pcr value", value,
x.bind_values[n]))
goto out;
@@ -789,21 +891,46 @@ static int cmd_attest_challenge(int argc, const char **argv)
return 1;
for (i = 2; i < (size_t)argc; i++) {
const char *a = argv[i];
+ const char *v = NULL;
+ enum opt_status r;
+
+ if (!strcmp(a, "-o"))
+ a = "--output";
- if (!strncmp(a, "--evidence=", 11)) {
- evidence_path = a + 11;
- } else if (!strncmp(a, "--ek-ca=", 8)) {
- pol.ek_ca = a + 8;
- } else if (!strncmp(a, "--ak-name=", 10)) {
- if (parse_hex(a + 10, ak_name, sizeof(ak_name), &n) ||
+ if (opt_arg("--evidence", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest challenge: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ evidence_path = v;
+ } else if (opt_arg("--ek-ca", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest challenge: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ pol.ek_ca = v;
+ } else if (opt_arg("--ak-name", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest challenge: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ if (parse_hex(v, ak_name, sizeof(ak_name), &n) ||
n != TPM_NAME_LEN) {
pr_err("attest challenge: --ak-name must be %d "
"hex characters", 2 * TPM_NAME_LEN);
goto out;
}
pol.ak_name = ak_name;
- } else if (!strncmp(a, "--ek-name=", 10)) {
- if (parse_hex(a + 10, ek_name, sizeof(ek_name), &n) ||
+ } else if (opt_arg("--ek-name", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest challenge: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ if (parse_hex(v, ek_name, sizeof(ek_name), &n) ||
n != TPM_NAME_LEN) {
pr_err("attest challenge: --ek-name must be %d "
"hex characters", 2 * TPM_NAME_LEN);
@@ -812,8 +939,13 @@ static int cmd_attest_challenge(int argc, const char **argv)
pol.ek_name = ek_name;
} else if (!strcmp(a, "--trust-presented-ek")) {
pol.trust_presented = true;
- } else if (!strncmp(a, "--out=", 6)) {
- out_path = a + 6;
+ } else if (opt_arg("--output", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest challenge: %s takes a value", a);
+ ret = 2;
+ goto out;
+ }
+ out_path = v;
} else if (is_help(a)) {
print_help(&attest_help);
ret = 0;
@@ -824,7 +956,7 @@ static int cmd_attest_challenge(int argc, const char **argv)
}
}
if (!evidence_path || !out_path) {
- pr_err("attest challenge: --evidence and --out are required");
+ pr_err("attest challenge: --evidence and --output are required");
goto out;
}
if (read_evidence(evidence_path, &evidence, &evidence_len))
@@ -888,24 +1020,45 @@ static int cmd_attest_evidence(int argc, const char **argv)
for (i = 1; i < (size_t)argc; i++) {
const char *a = argv[i];
+ const char *v = NULL;
+ enum opt_status r;
- if (!strncmp(a, "--challenge=", 12)) {
- challenge_path = a + 12;
- } else if (!strncmp(a, "--nonce=", 8)) {
- if (parse_hex(a + 8, nonce, sizeof(nonce),
+ if (!strcmp(a, "-o"))
+ a = "--output";
+
+ if (opt_arg("--challenge", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest: %s takes a value", a);
+ return 2;
+ }
+ challenge_path = v;
+ } else if (opt_arg("--nonce", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest: %s takes a value", a);
+ return 2;
+ }
+ if (parse_hex(v, nonce, sizeof(nonce),
&nonce_len)) {
pr_err("attest: --nonce must be hex of up to "
"%d bytes", ATTEST_NONCE_MAX);
return 2;
}
- } else if (!strncmp(a, "--pcrs=", 7)) {
- if (parse_pcrs(a + 7, &mask)) {
+ } else if (opt_arg("--pcrs", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest: %s takes a value", a);
+ return 2;
+ }
+ if (parse_pcrs(v, &mask)) {
pr_err("attest: --pcrs takes a comma separated "
"list of 0..23");
return 2;
}
- } else if (!strncmp(a, "--out=", 6)) {
- out_path = a + 6;
+ } else if (opt_arg("--output", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ pr_err("attest: %s takes a value", a);
+ return 2;
+ }
+ out_path = v;
} else if (is_help(a)) {
print_help(&attest_help);
return 0;
diff --git a/builtin-bpm.c b/builtin-bpm.c
index c3673233..d8c70b04 100644
--- a/builtin-bpm.c
+++ b/builtin-bpm.c
@@ -1490,7 +1490,7 @@ static int cmd_bpm_config(int argc, const char **argv)
"usage: shirudo bpm config register {add|list|remove} ...\n"
" shirudo bpm config update --base-package "
"<package.bee|oci://host/repo:tag> --version <version> "
- "[-f <name>.bee] [options]\n");
+ "[--file <name>.bee] [options]\n");
return op ? 0 : 2;
}
if (strcmp(op, "register"))
@@ -1576,16 +1576,16 @@ static int cmd_bpm_config(int argc, const char **argv)
return 2;
}
for (int i = 5; i < argc; i++) {
- if (!strncmp(argv[i], "--key-file=", 11))
- key = argv[i] + 11;
- else if (!strcmp(argv[i], "--key-file") && i + 1 < argc)
+ if (!strncmp(argv[i], "--cert=", 7))
+ key = argv[i] + 7;
+ else if (!strcmp(argv[i], "--cert") && i + 1 < argc)
key = argv[++i];
}
if (!key || cert_read_file(key, &cert) ||
!bpm_name_ok(s.name) ||
bpm_oci_parse_endpoint(s.endpoint, &probe)) {
cert_free(&cert);
- pr_err("bpm: register add requires a valid oci:// endpoint and --key-file certificate");
+ pr_err("bpm: register add requires a valid oci:// endpoint and --cert certificate");
return 2;
}
cert_free(&cert);
diff --git a/builtin-upatch.c b/builtin-upatch.c
index d86e0557..e22aa246 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -2620,7 +2620,7 @@ static int parse_op_args(int argc, const char **argv, const char *verb,
const char **expect_version_id, bool *no_precheck,
bool *no_version_check, const char **report)
{
- int i;
+ size_t i;
*file = NULL;
*expect_chain = NULL;
@@ -2628,17 +2628,34 @@ static int parse_op_args(int argc, const char **argv, const char *verb,
*no_precheck = false;
*no_version_check = false;
*report = NULL;
- for (i = 1; i < argc; i++) {
+ for (i = 1; i < (size_t)argc; i++) {
const char *a = argv[i];
+ const char *v = NULL;
+ enum opt_status r;
- if (strncmp(a, "--expect-chain=", 15) == 0) {
- *expect_chain = a + 15;
- } else if (strncmp(a, "--expect-version-id=", 20) == 0) {
- *expect_version_id = a + 20;
+ if (opt_arg("--expect-chain", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ fprintf(stderr, "upatch %s: %s takes a value\n",
+ verb, a);
+ return 2;
+ }
+ *expect_chain = v;
+ } else if (opt_arg("--expect-version-id", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ fprintf(stderr, "upatch %s: %s takes a value\n",
+ verb, a);
+ return 2;
+ }
+ *expect_version_id = v;
} else if (strcmp(a, "--no-version-check") == 0) {
*no_version_check = true;
- } else if (strncmp(a, "--report=", 9) == 0) {
- *report = a + 9;
+ } else if (opt_arg("--report", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ fprintf(stderr, "upatch %s: %s takes a value\n",
+ verb, a);
+ return 2;
+ }
+ *report = v;
} else if (strcmp(a, "--no-precheck") == 0) {
*no_precheck = true;
} else if (a[0] == '-') {
@@ -3485,10 +3502,13 @@ static int cmd_upatch_map(int argc, const char **argv)
bool insecure_set = false;
bool retries_set = false;
size_t n = 0;
- int i, ret = 0;
+ size_t i;
+ int ret = 0;
- for (i = 1; i < argc; i++) {
+ for (i = 1; i < (size_t)argc; i++) {
const char *a = argv[i];
+ const char *v = NULL;
+ enum opt_status r;
if (is_help(a)) {
print_help(&upatch_map_help);
@@ -3524,22 +3544,30 @@ static int cmd_upatch_map(int argc, const char **argv)
return 2;
}
otel = true;
- } else if (strncmp(a, "--otel-endpoint=", 16) == 0) {
- if (otel_opts.endpoint || !a[16]) {
+ } else if (opt_arg("--otel-endpoint", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ fprintf(stderr, "upatch map: %s takes a value\n", a);
+ return 2;
+ }
+ if (otel_opts.endpoint || !v[0]) {
fprintf(stderr, "upatch map: invalid or duplicate "
"--otel-endpoint\n");
return 2;
}
- otel_opts.endpoint = a + 16;
- } else if (strncmp(a, "--tenant-id=", 12) == 0) {
+ otel_opts.endpoint = v;
+ } else if (opt_arg("--tenant-id", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ fprintf(stderr, "upatch map: %s takes a value\n", a);
+ return 2;
+ }
if (otel_opts.tenant_id ||
- !tenant_id_valid(a + 12)) {
+ !tenant_id_valid(v)) {
fprintf(stderr, "upatch map: invalid or duplicate "
"--tenant-id; expected 1..128 characters using "
"A-Z, a-z, 0-9, '.', '_', or '-'\n");
return 2;
}
- otel_opts.tenant_id = a + 12;
+ otel_opts.tenant_id = v;
} else if (strcmp(a, "--otel-insecure") == 0) {
if (insecure_set) {
fprintf(stderr, "upatch map: duplicate --otel-insecure\n");
@@ -3547,27 +3575,35 @@ static int cmd_upatch_map(int argc, const char **argv)
}
insecure_set = true;
otel_opts.allow_insecure = true;
- } else if (strncmp(a, "--otel-retries=", 15) == 0) {
+ } else if (opt_arg("--otel-retries", a, argc, argv, &i, &v, &r)) {
__u64 value;
- if (retries_set || !a[15]) {
+ if (r == OPT_MISSING) {
+ fprintf(stderr, "upatch map: %s takes a value\n", a);
+ return 2;
+ }
+ if (retries_set || !v[0]) {
fprintf(stderr, "upatch map: invalid or duplicate "
"--otel-retries\n");
return 2;
}
- if (parse_u64(a + 15, strlen(a + 15), 10, &value)) {
+ if (parse_u64(v, strlen(v), 10, &value)) {
fprintf(stderr, "upatch map: --otel-retries must be 0..10\n");
return 2;
}
otel_opts.retries = (__u32)value;
retries_set = true;
- } else if (strncmp(a, "--s3-uri=", 9) == 0) {
- if (otel_opts.s3_uri || !a[9]) {
+ } else if (opt_arg("--s3-uri", a, argc, argv, &i, &v, &r)) {
+ if (r == OPT_MISSING) {
+ fprintf(stderr, "upatch map: %s takes a value\n", a);
+ return 2;
+ }
+ if (otel_opts.s3_uri || !v[0]) {
fprintf(stderr, "upatch map: invalid or duplicate "
"--s3-uri\n");
return 2;
}
- otel_opts.s3_uri = a + 9;
+ otel_opts.s3_uri = v;
} else if (a[0] == '-') {
fprintf(stderr, "upatch map: unknown option '%s'\n", a);
return 2;
diff --git a/completion/shirudo.bash b/completion/shirudo.bash
index d511ed4a..facae0d6 100644
--- a/completion/shirudo.bash
+++ b/completion/shirudo.bash
@@ -104,7 +104,7 @@ _shirudo()
elif [[ ($sub == list || ($sub == key && ${COMP_WORDS[3]} == list)) && $cur == -* ]]; then
COMPREPLY=( $(compgen -W "--json" -- "$cur") )
elif [[ $sub == config && ${COMP_WORDS[3]} == register && ${COMP_WORDS[4]} == add && $cur == -* ]]; then
- COMPREPLY=( $(compgen -W "--key-file=" -- "$cur") )
+ COMPREPLY=( $(compgen -W "--cert=" -- "$cur") )
elif [[ $sub == repo && cword -eq 3 ]]; then
COMPREPLY=( $(compgen -W "update" -- "$cur") )
elif [[ $sub == info && cword -eq 3 ]]; then
@@ -198,11 +198,11 @@ _shirudo()
COMPREPLY=( $(compgen -W "--cert= --upatch= --expect= \
--tree-root= --event= --json" -- "$cur") )
elif [[ $sub == challenge ]]; then
- COMPREPLY=( $(compgen -W "--evidence= --ek-ca= --out=" \
+ COMPREPLY=( $(compgen -W "--evidence= --ek-ca= --output=" \
-- "$cur") )
else
COMPREPLY=( $(compgen -W "--nonce= --pcrs= --challenge= \
- --out=" -- "$cur") )
+ --output=" -- "$cur") )
fi
;;
keys)
diff --git a/testing/end2end/t9105-delivery.sh b/testing/end2end/t9105-delivery.sh
index dc492046..b1cc9fcb 100755
--- a/testing/end2end/t9105-delivery.sh
+++ b/testing/end2end/t9105-delivery.sh
@@ -73,7 +73,7 @@ test_expect_success 'the map export unit ships what the package observed' '
test_expect_success 'the target attests what it runs' '
"$SHIRUDO_BIN" attest --nonce="$(cat "$E2E/nonce")" \
- --out="$OUT/evidence.json" &&
+ --output="$OUT/evidence.json" &&
[ -s "$OUT/evidence.json" ]
'
diff --git a/testing/end2end/t9106-policy-exec-graph.sh b/testing/end2end/t9106-policy-exec-graph.sh
index c0227e52..6ab94d41 100644
--- a/testing/end2end/t9106-policy-exec-graph.sh
+++ b/testing/end2end/t9106-policy-exec-graph.sh
@@ -43,7 +43,7 @@ else
UNLABELED_RESULT=failed
fi
"$WORK/exec-1" run "$UNLABELED_RESULT" || exit 1
-"$SHIRUDO_BIN" attest --nonce="$NONCE" --out="$OUT/evidence.json" ||
+"$SHIRUDO_BIN" attest --nonce="$NONCE" --output="$OUT/evidence.json" ||
exit 1
"$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck >/dev/null 2>&1 ||
exit 1
diff --git a/testing/functional/image/t5004-image-cli.sh b/testing/functional/image/t5004-image-cli.sh
index 6a8c4a9c..30251e84 100755
--- a/testing/functional/image/t5004-image-cli.sh
+++ b/testing/functional/image/t5004-image-cli.sh
@@ -35,7 +35,7 @@ refused() {
test_expect_success 'local repository mutations fail before changing config or keys' '
source_file keep "$WORK/host.der" &&
cp "$REG/keep.conf" "$WORK/before.conf" &&
- refused bpm config register add new oci://example.invalid --key-file "$WORK/host.der" &&
+ refused bpm config register add new oci://example.invalid --cert "$WORK/host.der" &&
refused bpm config register remove keep &&
refused bpm config register rm keep &&
cmp "$REG/keep.conf" "$WORK/before.conf" &&
@@ -55,7 +55,7 @@ test_expect_success 'local key changes explain signed revocation and reboot enro
test_expect_success 'read-only repository listing and command help remain available' '
"$H" "$ROOT" bpm config register list >"$WORK/list" &&
- grep -qx keep "$WORK/list" &&
+ grep -qx " keep" "$WORK/list" &&
"$H" "$ROOT" keys add --help &&
"$H" "$ROOT" keys revoke --help &&
"$H" "$ROOT" bpm key add --help &&
diff --git a/testing/functional/otel/t8004-status-otel.sh b/testing/functional/otel/t8004-status-otel.sh
index 4dc4fbc7..34036364 100644
--- a/testing/functional/otel/t8004-status-otel.sh
+++ b/testing/functional/otel/t8004-status-otel.sh
@@ -184,9 +184,9 @@ PY
test_expect_success 'status --include-system prints kernel config' '
work=$(mktemp -d) &&
"$S" status --include-system >"$work/status" 2>"$work/stderr" &&
- grep -q "^ Kernel Config:$" "$work/status" &&
- grep -Eq "^ Kernel Build ID: ([0-9a-f]+)?$" "$work/status" &&
- grep -Eq "^ (CONFIG_[^=]+=.*|\\(unavailable\\))$" "$work/status" &&
+ grep -Eq "^ Kernel build ID: +([0-9a-f]+)?$" "$work/status" &&
+ "$S" status --json --include-system 2>/dev/null |
+ python3 -c "import json, sys; sys.exit(0 if \"kernel_config\" in json.load(sys.stdin)[\"system\"] else 1)" &&
rm -rf "$work"
'
diff --git a/testing/functional/signing/t2001-genkey.sh b/testing/functional/signing/t2001-genkey.sh
index f6b28afa..9874cf62 100755
--- a/testing/functional/signing/t2001-genkey.sh
+++ b/testing/functional/signing/t2001-genkey.sh
@@ -74,7 +74,7 @@ if [ "$have_mldsa" = 1 ]; then
grep -q "Algorithm: *ML-DSA-87" "$tmp/keys.out" &&
grep -q "Issued: *20[0-9][0-9]-" "$tmp/keys.out" &&
! grep -Eq "Valid until|Expires in" "$tmp/keys.out" &&
- grep -q "signing key matches cert" "$tmp/keys.out"
+ grep -q "Matches cert: *yes" "$tmp/keys.out"
'
test_expect_success 'genkey refuses to overwrite without --force' '
@@ -94,7 +94,7 @@ if [ "$have_mldsa" = 1 ]; then
rmdir "$tmp/keys/cert.der" &&
mv "$tmp/old.der" "$tmp/keys/cert.der" &&
"$SHIRUDO" keys --keys-dir "$tmp/keys" >"$tmp/keys.out" 2>&1 &&
- grep -q "signing key matches cert" "$tmp/keys.out"
+ grep -q "Matches cert: *yes" "$tmp/keys.out"
'
else
test_expect_success 'genkey refuses with an upgrade hint on an OpenSSL without ML-DSA' '
diff --git a/testing/functional/tamperproof/t6114-output-paths.sh b/testing/functional/tamperproof/t6114-output-paths.sh
index 0a9c6eff..5f869038 100755
--- a/testing/functional/tamperproof/t6114-output-paths.sh
+++ b/testing/functional/tamperproof/t6114-output-paths.sh
@@ -3,7 +3,7 @@
# Copyright (c) 2026 Authors of shirudo
#
# t6114 -- a path root names for shirudo to write. The seal lets the
-# runtime task write what it denies everyone else, so a --report, --out
+# runtime task write what it denies everyone else, so a --report, --output
# or --json path pointed at sealed state, directly or through a symbolic
# link, must be refused rather than clobber the eventlog or plant a file
# the next boot restores. Non-destructive: every refusal leaves the state
@@ -54,7 +54,7 @@ test_expect_success 'a map listing is not appended to the eventlog' '
'
test_expect_success 'evidence is not written over the eventlog' '
- ! "$SHIRUDO_BIN" attest --nonce=00 --out="$EVENTLOG" \
+ ! "$SHIRUDO_BIN" attest --nonce=00 --output="$EVENTLOG" \
>/dev/null 2>"$LINK.err" &&
grep -q "refusing to write sealed state" "$LINK.err" &&
[ "$(sha256sum "$EVENTLOG" | cut -d" " -f1)" = "$BEFORE" ]
diff --git a/testing/functional/tpm/t4003-register.sh b/testing/functional/tpm/t4003-register.sh
index 3c51ec1a..3af081e5 100644
--- a/testing/functional/tpm/t4003-register.sh
+++ b/testing/functional/tpm/t4003-register.sh
@@ -245,16 +245,16 @@ test_expect_success 'a tree operation records its digest as the target writes it
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" &&
+ --output="$WORK/challenge-none.json" >"$WORK/challenge-none.out" &&
grep -q "^ FAIL no endorsement certificate: pin the key" "$WORK/challenge-none.out" &&
[ ! -e "$WORK/challenge-none.json" ] &&
! $S attest challenge --evidence="$WORK/evidence.json" \
--ek-name="000b$(py "print(\"00\"*32)")" \
- --out="$WORK/challenge-wrong.json" >"$WORK/challenge-wrong.out" &&
+ --output="$WORK/challenge-wrong.json" >"$WORK/challenge-wrong.out" &&
grep -q "^ FAIL endorsement key: the pinned key" "$WORK/challenge-wrong.out" &&
! $S attest challenge --evidence="$WORK/evidence.json" \
--ak-name="000b$(py "print(\"00\"*32)")" --trust-presented-ek \
- --out="$WORK/challenge-wrong.json" >"$WORK/challenge-wrong2.out" &&
+ --output="$WORK/challenge-wrong.json" >"$WORK/challenge-wrong2.out" &&
grep -q "^ FAIL attestation key: the pinned key" "$WORK/challenge-wrong2.out"
'
@@ -262,7 +262,7 @@ test_expect_success 'a challenge made from the evidence activates on the target'
nonce=1112 &&
$S attest challenge --evidence="$WORK/evidence.json" \
--ak-name="$(cat "$WORK/ak")" --ek-name="$(cat "$WORK/ek")" \
- --out="$WORK/challenge.json" >"$WORK/challenge.out" &&
+ --output="$WORK/challenge.json" >"$WORK/challenge.out" &&
grep -q "^ OK attestation key: the pinned key" "$WORK/challenge.out" &&
grep -q "^ OK endorsement key: the pinned key" "$WORK/challenge.out" &&
grep -q "^ OK endorsement key: TCG default template" "$WORK/challenge.out" &&
@@ -315,7 +315,7 @@ test_expect_success 'an RSA endorsement key protects and activates the challenge
"$(cat "$WORK/ak")" "$(echo "$out" | field public)" \
"$(echo "$out" | field name)" >"$WORK/rsa.json" &&
$S attest challenge --evidence="$WORK/rsa.json" --trust-presented-ek \
- --out="$WORK/challenge-rsa.json" |
+ --output="$WORK/challenge-rsa.json" |
sed -n "s/^credential: //p" >"$WORK/credential-rsa" &&
nonce=1314 &&
./$R evidence $nonce "$WORK/challenge-rsa.json" >"$WORK/evidence-rsa.json" &&
@@ -325,7 +325,7 @@ test_expect_success 'an RSA endorsement key protects and activates the challenge
test_expect_success 'challenge refuses a key that is not an endorsement key' '
py "import json; d=json.load(open(\"$WORK/evidence.json\")); d[\"ek\"]={\"type\":\"ecc\",\"public\":d[\"ak\"][\"public\"],\"name\":d[\"ak\"][\"name\"]}; open(\"$WORK/fake-ek.json\",\"w\").write(json.dumps(d))" &&
! $S attest challenge --evidence="$WORK/fake-ek.json" --trust-presented-ek \
- --out="$WORK/challenge-fake.json" >"$WORK/fake.out" &&
+ --output="$WORK/challenge-fake.json" >"$WORK/fake.out" &&
grep -q "^ FAIL endorsement key: TCG default template" "$WORK/fake.out" &&
grep -qx "verdict: fail" "$WORK/fake.out" &&
[ ! -e "$WORK/challenge-fake.json" ]
diff --git a/testing/functional/tpm/t4102-tpm-chain.sh b/testing/functional/tpm/t4102-tpm-chain.sh
index f130ed30..27cf79e9 100644
--- a/testing/functional/tpm/t4102-tpm-chain.sh
+++ b/testing/functional/tpm/t4102-tpm-chain.sh
@@ -89,7 +89,7 @@ test_expect_success 'a real signed unload extends the register and remains repla
'
test_expect_success 'the installed binary emits evidence that verifies against the live register' '
- "$SHIRUDO_BIN" attest --nonce="$NONCE" --out="$W/evidence.json" &&
+ "$SHIRUDO_BIN" attest --nonce="$NONCE" --output="$W/evidence.json" &&
AK=$(evidence_field ak.name) &&
EK=$(evidence_field ek.name) &&
CHAIN=$(tpm_chain chain) &&
@@ -184,26 +184,26 @@ PY
test_expect_success 'a challenge requires the correct pinned endorsement and attestation keys' '
! "$SHIRUDO_BIN" attest challenge --evidence="$W/evidence.json" \
- --out="$W/challenge-none.json" >"$W/challenge-none.out" &&
+ --output="$W/challenge-none.json" >"$W/challenge-none.out" &&
grep -q "^ FAIL no endorsement certificate: pin the key" "$W/challenge-none.out" &&
[ ! -e "$W/challenge-none.json" ] &&
! "$SHIRUDO_BIN" attest challenge --evidence="$W/evidence.json" \
- --ek-name=000b$(printf "%064d" 0) --out="$W/challenge-wrong.json" \
+ --ek-name=000b$(printf "%064d" 0) --output="$W/challenge-wrong.json" \
>"$W/challenge-wrong.out" &&
grep -q "^ FAIL endorsement key: the pinned key" "$W/challenge-wrong.out" &&
! "$SHIRUDO_BIN" attest challenge --evidence="$W/evidence.json" \
--ak-name=000b$(printf "%064d" 0) --trust-presented-ek \
- --out="$W/challenge-wrong.json" >"$W/challenge-wrong-ak.out" &&
+ --output="$W/challenge-wrong.json" >"$W/challenge-wrong-ak.out" &&
grep -q "^ FAIL attestation key: the pinned key" "$W/challenge-wrong-ak.out"
'
test_expect_success 'the production target activates an ECC endorsement-key challenge' '
"$SHIRUDO_BIN" attest challenge --evidence="$W/evidence.json" \
- --ak-name="$AK" --ek-name="$EK" --out="$W/challenge.json" >"$W/challenge.out" &&
+ --ak-name="$AK" --ek-name="$EK" --output="$W/challenge.json" >"$W/challenge.out" &&
credential=$(sed -n "s/^credential: //p" "$W/challenge.out") &&
[ "${#credential}" = 64 ] &&
"$SHIRUDO_BIN" attest --nonce=1112 --challenge="$W/challenge.json" \
- --out="$W/evidence-credential.json" &&
+ --output="$W/evidence-credential.json" &&
"$SHIRUDO_BIN" attest verify --evidence="$W/evidence-credential.json" --nonce=1112 \
--ak-name="$AK" --ek-name="$EK" --allow-runtime-events \
--expect-credential="$credential" >"$W/credential.report" &&
@@ -228,9 +228,9 @@ foreign["ak_name"] = "000b" + "00" * 32
json.dump(foreign, open(sys.argv[2] + "/challenge-foreign.json", "w"))
PY
! "$SHIRUDO_BIN" attest --nonce=1112 --challenge="$W/challenge-corrupt.json" \
- --out="$W/corrupt-evidence.json" &&
+ --output="$W/corrupt-evidence.json" &&
! "$SHIRUDO_BIN" attest --nonce=1112 --challenge="$W/challenge-foreign.json" \
- --out="$W/foreign-evidence.json"
+ --output="$W/foreign-evidence.json"
'
test_expect_success 'an RSA endorsement key activates the challenge through the production target' '
@@ -247,10 +247,10 @@ doc = {"ak": {"name": d["ak"]["name"]},
json.dump(doc, open(sys.argv[3], "w"))
PY
"$SHIRUDO_BIN" attest challenge --evidence="$W/rsa.json" --trust-presented-ek \
- --out="$W/challenge-rsa.json" >"$W/challenge-rsa.out" &&
+ --output="$W/challenge-rsa.json" >"$W/challenge-rsa.out" &&
credential=$(sed -n "s/^credential: //p" "$W/challenge-rsa.out") &&
"$SHIRUDO_BIN" attest --nonce=1314 --challenge="$W/challenge-rsa.json" \
- --out="$W/evidence-rsa.json" &&
+ --output="$W/evidence-rsa.json" &&
"$SHIRUDO_BIN" attest verify --evidence="$W/evidence-rsa.json" --nonce=1314 \
--ak-name="$AK" --allow-runtime-events --expect-credential="$credential" \
>"$W/rsa.report" &&
@@ -265,7 +265,7 @@ d["ek"] = {"type": "ecc", "public": d["ak"]["public"], "name": d["ak"]["name"]}
json.dump(d, open(sys.argv[2], "w"))
PY
! "$SHIRUDO_BIN" attest challenge --evidence="$W/fake-ek.json" --trust-presented-ek \
- --out="$W/challenge-fake.json" >"$W/fake-ek.out" &&
+ --output="$W/challenge-fake.json" >"$W/fake-ek.out" &&
grep -q "^ FAIL endorsement key: TCG default template" "$W/fake-ek.out" &&
[ ! -e "$W/challenge-fake.json" ]
'
diff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.c
index be9f6d63..6b3ed5f0 100644
--- a/tools/shirudo-build/bpm-build.c
+++ b/tools/shirudo-build/bpm-build.c
@@ -1596,7 +1596,7 @@ static void build_usage(void)
{
fprintf(stderr,
"usage: shirudo bpm build [context] --version <version>\n"
- " shirudo bpm build [context] -f <name>.bee --version <version>\n"
+ " shirudo bpm build [context] --file <name>.bee --version <version>\n"
" [--keys-dir <dir>]\n"
" [--vmlinux <vmlinux.h>]\n"
" [--rodata-input <name>=<path>]...\n\n"
@@ -1629,7 +1629,7 @@ static int __build_bpm_build(int argc, char **argv,
if (build_is_help(argv[i])) {
build_usage();
return 0;
- } else if (!strcmp(argv[i], "-f") || !strcmp(argv[i], "--file")) {
+ } else if (!strcmp(argv[i], "--file")) {
if (++i >= argc)
goto usage;
file_arg = argv[i];
@@ -1939,12 +1939,11 @@ static int __build_bpm_config_update(int argc, char **argv,
"usage: shirudo bpm config update "
"--base-package <package.bee|oci://host/repo:tag> "
"--version <version> "
- "[-f <name>.bee] [--rodata-input <name>=<path>]...\n"
+ "[--file <name>.bee] [--rodata-input <name>=<path>]...\n"
"Without -f, the Beefile and updater inputs come from "
"--base-package and are trusted as operator-side code.\n");
return 0;
- } else if (!strcmp(argv[i], "-f") ||
- !strcmp(argv[i], "--file")) {
+ } else if (!strcmp(argv[i], "--file")) {
if (++i >= argc)
goto usage;
file_arg = argv[i];
@@ -2037,7 +2036,7 @@ static int __build_bpm_config_update(int argc, char **argv,
ret = build_copy_package_member(base_package, "Beefile", build_file);
if (ret == -ENOENT) {
pr_err("bpm config update: base package %s has no Beefile; "
- "rebuild it with a Beefile or pass -f <name>.bee",
+ "rebuild it with a Beefile or pass --file <name>.bee",
base_package);
ret = -EINVAL;
}
@@ -2217,7 +2216,7 @@ usage:
fprintf(stderr,
"usage: shirudo bpm config update --base-package "
"<package.bee|oci://host/repo:tag> --version <version> "
- "[-f <name>.bee] "
+ "[--file <name>.bee] "
"[--rodata-input <name>=<path>]... [--keys-dir <dir>]\n");
return -EINVAL;
}
@@ -2239,11 +2238,11 @@ static int build_bpm_config_update(int argc, char **argv)
static void bpm_usage(FILE *fp)
{
fprintf(fp,
- "usage: shirudo bpm build [context] --version <version> [-f <name>.bee]\n"
+ "usage: shirudo bpm build [context] --version <version> [--file <name>.bee]\n"
" [--keys-dir <dir>] [--vmlinux <vmlinux.h>]\n"
" [--rodata-input <name>=<path>]...\n"
" shirudo bpm config update --base-package <package.bee|oci://...>\n"
- " --version <version> [-f <name>.bee]\n"
+ " --version <version> [--file <name>.bee]\n"
" [--rodata-input <name>=<path>]...\n"
" shirudo bpm push <package-file> <repository> [--keys-dir <dir> |\n"
" --index-cert <cert.der> --index-key <key.pem>]\n"
diff --git a/tools/shirudo-build/image.c b/tools/shirudo-build/image.c
index de3b67a2..23e9caaf 100644
--- a/tools/shirudo-build/image.c
+++ b/tools/shirudo-build/image.c
@@ -270,7 +270,8 @@ int build_image(int argc, char **argv)
image_usage(stdout);
return 0;
}
- if (!strcmp(arg, "-o") && i + 1 < argc) {
+ if ((!strcmp(arg, "-o") || !strcmp(arg, "--output")) &&
+ i + 1 < argc) {
prefix = argv[++i];
} else if (!strcmp(arg, "--keys-dir") && i + 1 < argc) {
keys_dir = argv[++i];
diff --git a/tools/shirudo-build/package.c b/tools/shirudo-build/package.c
index 1b3a2344..28fa14d3 100644
--- a/tools/shirudo-build/package.c
+++ b/tools/shirudo-build/package.c
@@ -460,7 +460,8 @@ int build_upatch_cli(int argc, char **argv)
return 2;
}
for (i = 2; i < argc; i++) {
- if (!strcmp(argv[i], "-o") && i + 1 < argc) {
+ if ((!strcmp(argv[i], "-o") || !strcmp(argv[i], "--output")) &&
+ i + 1 < argc) {
output = argv[++i];
} else if (!strcmp(argv[i], "--data-range") && i + 1 < argc) {
const char *range = argv[++i];
diff --git a/tools/shirudo-build/shirudo-build.c b/tools/shirudo-build/shirudo-build.c
index a28f5733..e08aa43f 100644
--- a/tools/shirudo-build/shirudo-build.c
+++ b/tools/shirudo-build/shirudo-build.c
@@ -224,7 +224,8 @@ int main(int argc, char **argv)
for (i = 1; i < argc; i++) {
const char *a = argv[i];
- if (strcmp(a, "-o") == 0 && i + 1 < argc) {
+ if ((strcmp(a, "-o") == 0 || strcmp(a, "--output") == 0) &&
+ i + 1 < argc) {
output = argv[++i];
} else if (strcmp(a, "--name") == 0 && i + 1 < argc) {
name = argv[++i];
diff --git a/tools/shirudo-build/vouch.c b/tools/shirudo-build/vouch.c
index 2a9c9672..2ad50ab4 100644
--- a/tools/shirudo-build/vouch.c
+++ b/tools/shirudo-build/vouch.c
@@ -96,7 +96,8 @@ int build_keys_vouch(int argc, char **argv)
for (int i = 1; i < argc; i++) {
const char *a = argv[i];
- if (!strcmp(a, "-o") && i + 1 < argc) {
+ if ((!strcmp(a, "-o") || !strcmp(a, "--output")) &&
+ i + 1 < argc) {
output = argv[++i];
} else if (!strcmp(a, "--keys-dir") && i + 1 < argc) {
keys_dir_arg = argv[++i];
diff --git a/util/help.h b/util/help.h
index 56d2922a..a574470b 100644
--- a/util/help.h
+++ b/util/help.h
@@ -8,6 +8,8 @@
#ifndef SHIRUDO_HELP_H
#define SHIRUDO_HELP_H
+#include <stdbool.h>
+#include <string.h>
#include <stddef.h>
struct help_item {
@@ -33,6 +35,44 @@ int is_help(const char *arg);
int is_list_cmds(const char *arg);
+/*
+ * A valued option takes its value after an equals sign or as the next
+ * argument. opt_arg() says whether arg, argv[*i] or a name a caller
+ * substituted for it, is the option name: it hands the value out and
+ * steps *i past a value that followed, or reports an option that came
+ * last with nothing after it.
+ */
+enum opt_status {
+ OPT_NONE,
+ OPT_VALUE,
+ OPT_MISSING,
+};
+
+static inline bool opt_arg(const char *name, const char *arg, int argc,
+ const char **argv, size_t *i, const char **value,
+ enum opt_status *status)
+{
+ size_t n = strlen(name);
+
+ *status = OPT_NONE;
+ if (strncmp(arg, name, n))
+ return false;
+ if (arg[n] == '=') {
+ *value = arg + n + 1;
+ *status = OPT_VALUE;
+ return true;
+ }
+ if (arg[n])
+ return false;
+ if (*i + 1 >= (size_t)argc) {
+ *status = OPT_MISSING;
+ return true;
+ }
+ *value = argv[++*i];
+ *status = OPT_VALUE;
+ return true;
+}
+
void print_help(const struct help *h);
/* What bash completion reads through --list-cmds. */