RFC-0015: cryptosuite CLI Implementation Decisions

  • Status: Proposed; implements RFC-0009 and records the decisions it left open. Adds Protector.rewrap_stream and protector.inspect_envelope.

  • Owner: CLI and API leads; security review required.

  • Last updated: 2026-11-29

Context

RFC-0009 fixes the command tree, global options, exit codes, and the cryptosuite-status/1 schema, and defers the code, the provider and context file schemas, and several details. This RFC records how the implementation in cryptography_suite.cli resolves them.

Decisions

Packaging

The wheel exposes exactly one console script, cryptosuite (cryptography_suite.cli.main:main), and python -m cryptography_suite.cli runs the same code. The package root never imports the CLI. The artifact and installed-wheel contracts check both.

Option names

RFC-0009 names both the global output format and each command’s protected output file --output. Global options are accepted before the command (cryptosuite --output json encrypt --output out.cse ...); the command’s option is stored separately, so the two never collide.

Provider configuration (cryptosuite-provider-config/1)

{
  "schema_version": "cryptosuite-provider-config/1",
  "providers": [
    {
      "type": "hpke",
      "provider_id": "cryptography-suite.hpke",
      "recipients": [{"key_id": "archive", "public_key": "cs4hpke1-x25519:..."}],
      "identity": {"key_id": "archive"}
    }
  ],
  "keys": {"archive": {"provider_id": "cryptography-suite.hpke", "key_id": "archive"}},
  "primary_key": "archive",
  "additional_keys": []
}
  • Keys are named once and referenced by name (primary_key, additional_keys, rewrap --destination-key NAME), so key identifiers with / or : (cloud ARNs) never need escaping on the command line.

  • The file contains references only. An identity declares that the private key for that key_id arrives through --secret-fd FD or --secret-stdin as PKCS #8 PEM; an encrypted PEM’s password is prompted on the TTY and refused under --non-interactive. At most one identity per invocation.

  • type is hpke in this distribution. Other provider types belong to their own distributions; the CLI never imports a module named in a config file.

  • Unknown fields, duplicate keys, floats, and oversized files are rejected.

Context files (cryptosuite-context/1)

{"schema_version": "cryptosuite-context/1", "values": {...}}, where each value is a string or {"base64url": "..."} (canonical, unpadded) for bytes. Several --context-file options merge; a key may appear only once.

Status, logs, and errors

  • Usage and configuration errors use the CLI-level code USAGE_INVALID (category usage, exit 2); POLICY_INVALID also exits 2.

  • Argument-parser messages are replaced by a fixed message because they can echo argument values such as paths.

  • In text mode a failure prints one line to stderr; --log-level info adds start and finish trace lines that contain only the command and error code.

  • A status file that cannot be written turns a success into exit 8.

Cancellation and --timeout

SIGINT and SIGTERM request cooperative cancellation (exit 9, output aborted); a second SIGINT stops at once, still aborting the output. --timeout SECONDS is a wall-clock deadline for the whole command enforced through the same cancellation, so it never changes the policy (and so never changes the policy_id written into envelopes). Provider call deadlines remain those of the policy.

Commands

  • encrypt, decrypt, and rewrap stream from --input PATH|- into the transactional file sink; rewrap uses Protector.rewrap_stream, which copies records unchanged and validates their framing, so archives of any size are rewrapped in bounded memory.

  • inspect uses inspect_envelope, which needs no provider configuration.

  • migrate validates its arguments and context, then refuses with LEGACY_DENIED and a warning: this distribution ships no legacy adapter (RFC-0008). No input is read and no output or receipt is written.

  • provider health calls each configured provider’s health_check.

  • policy validate loads --policy offline and reports its identifier.

  • doctor reports versions, the OpenSSL build, the HPKE KEMs, ML-KEM availability, the platform’s atomic-output capabilities for the temporary directory, and the validity of any given policy or provider configuration. It creates no keys and sends nothing.

Deferred

Machine progress lines (cryptosuite-progress/1), shell completion, and man pages.

Test and validation requirements

tests/cli/ runs every command end to end, every exit code, both secret channels, prompting, signals, timeouts, status files, and every rejection in the configuration loaders. The artifact and installed-wheel tests check the entry point, and the installed wheel runs doctor.