# CLI Reference

This page describes `octet-vault` 1.0.2. The form of a command is `octet-vault <global options> <command> <options>`. Run `octet-vault <command> --help`, or `man octet-vault-<command>` once the man pages are installed, for the full text of any command. A command marked **admin** needs a `vaults:admin` token.

## Global options

A global option goes before or after the command name.

| Option | Environment variable | Meaning |
|---|---|---|
| `--token-file <file>` | `OCTET_VAULT_TOKEN_FILE` (the file), `OCTET_VAULT_TOKEN` (the token itself) | Your vault token |
| `--json` | | Print JSON instead of text (see [JSON output](#json-output)) |
| `--verbose` | | Print every check line, the PASS lines included |
| `--base-url <URL>` | `OCTET_VAULT_URL` | The API base URL, in place of Octet's. `https://`, or `http://` to a loopback address only. |
| `--log-origin <origin>` | `OCTET_VAULT_LOG_ORIGIN` | The log origin every checkpoint must carry, in place of Octet's |
| `-V`, `--version` | | Print the version. `--version` also prints the commit, the target, the build date and the fingerprints of the built-in root keys. |

A flag beats its environment variable. If `OCTET_VAULT_URL` or `OCTET_VAULT_LOG_ORIGIN` is set and you pass its flag with a different value, the CLI refuses the command before any request, names both values, and exits `64`. `verify`, `verify-log` and `monitor` with a `--base-url` on another host than Octet's also need `--log-origin`, and exit `64` without it.

The CLI checks a token before it sends it. An empty token, a token that is not a `vaults:read` or `vaults:admin` token, or an expired one is refused with the file or variable it came from, and nothing is sent. The CLI follows no redirect, and reports one with its target.

## Auditor options

An auditor passes these options after the command name, in place of a token (see [Delegate to an Auditor](/docs/vaults/integration/delegate/)). `list`, `fetch`, `open`, `export`, `verify` and `verify-log` take them.

| Option | Environment variable | Meaning |
|---|---|---|
| `--delegation <file>` | | An auditor's delegation. Needs `--auditor-key`. |
| `--auditor-key <file>` | | The auditor key file that signs delegated requests |
| `--auditor-passphrase-file <file>` | `OCTET_VAULT_AUDITOR_PASSPHRASE` | The auditor key's passphrase |
| `--grant <file or object-id:grant-id>` | | A grant to open with. Repeatable. `open`, `export` and `verify` take it. |

## Passphrases

Every command that reads a key file asks for its passphrase on the terminal, unless you pass it in a file or an environment variable:

| Key file | Option | Environment variable |
|---|---|---|
| A recipient or custodian key (`--key`, and the `--out` of `keygen`) | `--key-passphrase-file` | `OCTET_VAULT_KEY_PASSPHRASE` |
| An owner key | `--owner-passphrase-file` (`--current-owner-passphrase-file` in `owner replace`) | `OCTET_VAULT_OWNER_PASSPHRASE` |
| A delegation root key | `--root-passphrase-file` | `OCTET_VAULT_ROOT_PASSPHRASE` |
| An auditor key | `--auditor-passphrase-file` | `OCTET_VAULT_AUDITOR_PASSPHRASE` |
| A restored key in `recovery recover` | `--new-passphrase-file` | `OCTET_VAULT_NEW_PASSPHRASE` |

Without a terminal, in a script, a CI job or a container, pass the option or set the variable. When the CLI cannot prompt, its error names both.

## Keys

| Command | What it does |
|---|---|
| `keygen --out <file>` | Create a recipient key. `--recovery <t>-of-<n>` with one `--custodian <public key file>` per custodian also splits it for recovery. `--fido2` enrolls a FIDO2 security key, repeatable, and `--keep-passphrase` keeps an entry that opens with the passphrase alone. |
| `register --key <file>` | **Admin.** Register and activate a recipient key. Sign it with `--owner-key <file>` or `--owner-piv <slot>`. |
| `key list` | List the vault's recipient keys: ID, fingerprint, status, registration time, and whether your owner key signed it |
| `key info <file>` | Show a key file's kind, fingerprint and how it opens, without any secret. With a token, also the key ID the vault registered it under. |
| `key retire <kid>` | **Admin.** Retire the active key. It keeps opening its objects. |
| `key revoke <kid> --yes` | **Admin.** Revoke a compromised key. The vault never seals to it again. |
| `key wrap <file> --out <file> --fido2` | Write a copy of any key file that opens with a FIDO2 security key and the passphrase. Repeat `--fido2` for several security keys. `--keep-passphrase` keeps an entry that opens with the passphrase alone. Local, no token. |
| `key unwrap-info <file>` | Show how a key file opens: its version and entries, without any secret. Local, no token. |
| `owner keygen --out <file>` | Create an owner key file |
| `owner set` | **Admin.** Set the vault's first owner key, from `--owner-key <file or PEM>` or `--owner-piv <slot>` |
| `owner replace` | **Admin.** Replace the owner key. The current key (`--current-owner-key` or `--current-owner-piv`) signs the new one (`--new-owner-key` or `--new-owner-piv`). |
| `owner sign-key <kid>` | **Admin.** Sign a recipient key with the current owner key, after an owner-key reset |
| `owner history` | Print the owner keys, oldest first, and check the chain |
| `recovery public-key --key <file>` | Print a key's public key, for whoever splits a key to you as custodian |
| `recovery transfer` | As a custodian, check your share and re-encrypt it to the person restoring the key (`--restorer-key`) |
| `recovery recover` | Restore a recipient key from enough transferred shares |

Commands that change keys take `--allow-list <file>` and append the events they cause. Commands that use a YubiKey PIV slot or a FIDO2 security key take `--ykman <path>`, or `OCTET_VAULT_YKMAN`, if `ykman` is not on your `PATH`. See [Security keys](/docs/vaults/concepts/keys/#security-keys).

When you open an object with a key it is not sealed to, the error names the key ID and fingerprint of both keys.

## Objects

| Command | What it does |
|---|---|
| `list` | List objects, one row per object under a header: `OBJECT`, `RECEIVED`, `TYPE`, `SOURCE`, `KID` and `SIZE`. Filter with `--since`, `--until` (RFC 3339, on the received time), `--decision-ref`, `--subject-ref` and `--source`. `--all` follows every page. |
| `fetch <object-id> --out <dir>` | Download the sealed object and its evidence into a directory |
| `open <object-id> --key <file>` | Open an object and print a summary: its type, platform, key ID, times and proof size. `--json` prints the whole evidence bundle. `--dir <dir>` reads a fetched or exported directory instead. `--out` writes the bundle, and `--proof-out` the signed proof bytes. |
| `verify-log <object-id>` | Check the receipt, the log event, the inclusion proof, the checkpoint and its timestamps, without opening the object. `--with-blob` also downloads and checks the sealed object. `--state <file>` also checks the log against the checkpoint saved in a `monitor` state file, and saves a newer one only with a consistency proof. `--dir <dir>` works offline. |
| `verify <object-id> --key <file>` | Check the object end to end and verify the proof inside at its validation window. Pass the app identity (see below). `--dir <dir>` works offline. |
| `export <object-id> --out <dir>` | Write an evidence package that verifies offline. `--key <file>` also opens it and adds what `verify --dir` needs. |
| `hold set`, `hold clear` | **Admin.** Set or clear a legal hold on `<object-id>`, or with `--vault` on the whole vault. `--reason` records why. |
| `delete <object-id> --yes` | **Admin.** Delete an object. `--reason` records why. |
| `subject erase <subject-ref> --yes` | **Admin.** Delete every object of a subject |
| `verify-renewal --tree-size <n>` | Check the archive renewal chain of the checkpoint of tree size `n`, from its RFC 3161 token to the newest renewal. `--leaves` also fetches the log's leaves and recomputes each renewal's log root. `--save <file>` writes the evidence it checked. `--file <file>` checks a saved file offline, without a token. |
| `retention-challenge <object-id>` | Check that the vault still holds the object's sealed bytes, unaltered, without downloading the object (see [Proof of retention](/docs/vaults/concepts/integrity/#proof-of-retention)). `--samples <n>` sets how many chunks the vault must return, 1 to 256, 16 by default. `--blob <file>` checks the answer against your own copy of the sealed object, the `object.ovlt` that `fetch` or `export` writes. `--full` asks for a digest of the whole object instead, and needs `--blob`. Exits `3` (INCONCLUSIVE) when the object's retention root is not committed yet. |
| `monitor --state <file>` | Check every new log event and the log's consistency. `--allow-list <file>`, `--witness <key>` (repeatable), `--min-cosignatures <n>`, `--dry-run`. `--retention-sample <n>` also challenges `n` random objects, 1 to 60 (see [Check retention](/docs/vaults/integration/monitor/#check-retention)). `--notify-webhook <URL>`, `--notify-secret-file <file>` and `--notify-always` post a summary of the run (see [Get notified](/docs/vaults/integration/monitor/#get-notified)). |

`fetch` and `export` create the `--out` directory if it is missing. They refuse a directory that has files in it, unless you pass `--force`, which replaces the files the two have in common.

`delete`, `subject erase` and `key revoke` need `--yes`. Without it, on a terminal, they ask you to type the object ID, `erase` or the key ID to confirm. Without a terminal, they exit `64`.

`list --all`, `export`, `monitor` and `verify-renewal --leaves` show a progress counter on standard error when it is a terminal.

### `verify` options

| Option | Meaning |
|---|---|
| `--android-app-identity <package>,<cert SHA-256>` | Your Android app: its package name and the SHA-256 of its signing certificate, 64 hex digits, with or without colons, as `keytool` or the Play Console prints it. Repeatable. |
| `--app-attest-team-id`, `--app-attest-bundle-id` | Your iOS app |
| `--app-attest-environment <env>` | Which App Attest environment to accept: `production`, `development` or `any`. By default, your vault's: `production` for a `release` vault, `development` for a `sandbox` vault. `any` accepts both. |
| `--any-app` | Accept a proof from any app. The `app-binding` check is skipped, and the result can be VALID without an app identity. Refused together with an app identity. |
| `--max-age-seconds <n>` | Freshness limit for a proof made without an upload challenge. 300 by default. |
| `--cache-dir <dir>`, `--no-cache` | Where archived Android revocation lists are cached (`OCTET_VAULT_CACHE_DIR`) |
| `--engine-receipt-keys`, `--engine-policy-keys`, `--engine-receipt-history`, `--engine-policy-history`, `--engine-receipt-anchor`, `--engine-policy-anchor` | The policy engine's keys, to verify a decision record |

Without `--android-app-identity`, or `--app-attest-team-id` with `--app-attest-bundle-id`, for the proof's platform, the `app-binding` line reads NOT-CHECKED and the result is INCONCLUSIVE, exit code `3`. See [App identity](/docs/vaults/concepts/verification/#app-identity).

## Delegation

| Command | What it does |
|---|---|
| `auditor keygen --out <file>` | Create an auditor key file and its `.pub.json` |
| `delegation root keygen --out <file>` | Create a delegation root key |
| `delegation root set --root-key <file>` | **Admin.** Certify the root with the owner key (`--owner-key` or `--owner-piv`). `--not-after` ends it, one year by default. |
| `delegation create` | **Admin.** Create and register a delegation: `--root-key`, `--auditor <.pub.json>`, `--object`, `--subject-ref`, `--decision-ref`, `--received-from`, `--received-until`, `--ops`, `--until` (at most 90 days ahead), `--out` |
| `delegation attenuate <file> --out <file>` | Narrow a delegation with `--ops`, `--object` or an earlier `--until` |
| `delegation inspect <file>` | Print a delegation's blocks, offline and unverified |
| `delegation list` | **Admin.** List the vault's delegations |
| `delegation revoke <delegation-id>` | **Admin.** Revoke a delegation, or one narrowed copy with `--revocation-id` |
| `grant <object-id> --key <file> --auditor <.pub.json>` | **Admin.** Store a grant that lets the auditor open one object. `--out` also writes it to a file. |

## Exit codes

Every command uses the same exit codes, `monitor` included:

| Code | Result | When |
|---|---|---|
| `0` | VALID | No check failed or raised an ALERT. For `verify`, the proof's signatures and its app identity also verified. |
| `1` | INVALID | A check failed. Altered evidence, such as a changed byte in the sealed object, is a failed check. |
| `2` | ALERT | No check failed, and at least one line is an ALERT |
| `3` | INCONCLUSIVE | Nothing failed or raised an ALERT, but the result is not established: for example no app identity was given, or the proof's signatures could not be verified, or `retention-challenge` found no committed retention root for the object |
| `4` | Could not run | A credential, the network, a key file, a wrong key or passphrase, a server error, input that cannot be read, or a `monitor` notification that could not be sent |
| `64` | Usage error | A wrong flag or value, a flag and its environment variable that disagree, or `delete`, `subject erase` or `key revoke` without `--yes` where the CLI cannot ask |

NOT-CHECKED, ABSENT, WARN and INFO lines leave the exit code as it is. See [Check Lines and Exit Codes](/docs/vaults/reference/checks/) for each line.

**`subject erase`.** Exit code `1` means that the erasure is incomplete: a legal hold or write-once retention kept some of the subject's objects. The output lists each kept object with its reason. See [Erase a subject](/docs/vaults/integration/delete/#erase-a-subject).

## JSON output

With `--json`, a command that prints a report (`verify`, `verify-log`, `verify-renewal`, `retention-challenge`, `monitor` and `export`) prints one JSON object of the format `octet-vault/report/1` on standard output. It starts with these keys, in this order:

| Key | Content |
|---|---|
| `format` | Always `octet-vault/report/1` |
| `result` | Always `completed`: the command ran to the end and judged its input |
| `exit_code` | The exit code: `0`, `1`, `2` or `3`, or `4` when `monitor` could not send its notification |
| `verdict` | The overall result: `VALID`, `INVALID`, `ALERT` or `INCONCLUSIVE` |
| `reason` | One line that names the check that decided the verdict |
| `deciding_check` | The name of that check: the first FAIL, else the first ALERT, else the check that left the result INCONCLUSIVE. `null` for VALID. |
| `not_checked` | The names of the NOT-CHECKED and ABSENT checks |
| `title` | The report's title |
| `checks` | Every check, in the order it ran, each with `name`, `status` and `detail`. Names are unique: a repeated check is named `<name>#2`, `<name>#3`. |

`verify` adds `proof_verdict`, the proof verifier's own verdict, and `verifier`, the `octet-verify` release that judged the proof. `proof_verdict` can read VALID while a log check fails and `verdict` reads INVALID, so read `verdict` for the overall result. `export` adds `directory` and `written`, every file it wrote. `monitor` adds `notification` when it sent one.

A command that could not run, or was misused, prints one JSON object of the format `octet-vault/error/1` on standard error:

```json
{
  "format": "octet-vault/error/1",
  "result": "could-not-run",
  "exit_code": 4,
  "verdict": null,
  "error": "wrong passphrase, or the key file was altered"
}
```

`result` is `could-not-run` with exit code `4`, or `usage-error` with exit code `64`.

The JSON Schema for both formats is [`schema/report-1.schema.json`](https://github.com/octetproof/octet-vault/blob/v1.0.2/schema/report-1.schema.json) in the `octet-vault` repository. The `--json` output of other commands, such as `list`, `open`, `keygen` and `subject erase`, has no `format` key.

## Completions and man pages

`octet-vault completions <shell>` prints a completion script for `bash`, `zsh`, `fish`, `powershell` or `elvish`. Load it from your shell's startup file:

```bash
# zsh, in ~/.zshrc after compinit
source <(octet-vault completions zsh)

# bash, in ~/.bashrc
source <(octet-vault completions bash)

# fish, in ~/.config/fish/config.fish
octet-vault completions fish | source
```

Each release has one man page per command in `octet-vault-man.tar.gz`: `octet-vault(1)`, `octet-vault-verify(1)`, `octet-vault-owner-set(1)` and so on. The file is listed in `SHA256SUMS`. With `SHA256SUMS` verified as in the [Quickstart](/docs/vaults/getting-started/quickstart/#1-install-the-cli), check the archive and install it:

```bash
curl -fsSLO "$BASE/octet-vault-man.tar.gz"
grep " octet-vault-man.tar.gz\$" SHA256SUMS | shasum -a 256 -c -   # must print "octet-vault-man.tar.gz: OK"
sudo tar -xzf octet-vault-man.tar.gz -C /usr/local/share/man
man octet-vault-verify
```

The [container image](/docs/vaults/integration/monitor/#with-the-container-image) carries them in `/usr/share/man/man1`.

## Renamed in 1.0.0

Some options and environment variables have new names in 1.0.0, and this page lists only the new ones. The old names still work and print a one-line note on standard error that names the new one. The auditor options also moved after the command name. The [release notes](https://github.com/octetproof/octet-vault/releases/tag/v1.0.0) list every rename.
