Metadata-Version: 2.5
Name: burnedsecret-cli
Version: 1.1.0
Summary: Command-line interface for the burnedsecret.com zero-knowledge secrets API
Author: BurnedSecret
License: MIT
Keywords: burnedsecret,cli,encryption,secrets,zero-knowledge
Requires-Python: >=3.11
Requires-Dist: burnedsecret<2,>=1.3.1
Requires-Dist: rich>=13.8
Requires-Dist: tomli-w>=1.2
Requires-Dist: typer>=0.26
Provides-Extra: dev
Requires-Dist: pytest; extra == 'dev'
Description-Content-Type: text/markdown

# burnedsecret-cli (`bs`)

Command-line interface wrapping the [burnedsecret](https://burnedsecret.com)
zero-knowledge secrets REST API. All encryption happens client-side; the server
never sees plaintext or decryption keys — the key travels only in the URL
`#k=...` fragment, which the server never receives.

```bash
pip install burnedsecret-cli
bs auth login
echo "my-secret" | bs secret create
```

## Install

The CLI ships through five channels:

```bash
# 1. pip (Python 3.11+)
pip install burnedsecret-cli

# 2. Homebrew (macOS Apple Silicon only; Linux uses install.sh or pip)
brew install JensrudJ/burnedsecret/bs

# 3. Scoop (Windows)
scoop bucket add burnedsecret https://github.com/JensrudJ/scoop-burnedsecret
scoop install bs

# 4. Chocolatey (Windows)
choco install burnedsecret-cli

# 5. Standalone binary (no Python needed)
curl -fsSL https://burnedsecret.com/install/cli/install.sh | sh      # POSIX
irm https://burnedsecret.com/install/cli/install.ps1 | iex            # Windows PowerShell
```

### Supported platforms

| Platform              | Channels                                   |
| --------------------- | ------------------------------------------ |
| Linux x86_64          | binary (`install.sh`), pip                 |
| Linux arm64           | binary (`install.sh`), pip                 |
| macOS Apple Silicon   | binary (`install.sh`), Homebrew, pip       |
| macOS Intel (x86_64)  | pip only                                   |
| Windows x86_64        | Scoop, Chocolatey, zip (`install.ps1`), pip |
| Windows arm64         | pip                                        |

The Homebrew formula is macOS Apple Silicon only (it has no `on_linux`
block); Linux users install the standalone binary via `install.sh` or use pip.
No Intel macOS binary is published, by decision, and none is planned: the pip
install is the identical tool. `brew install` and `install.sh` on an Intel Mac
say so and point at `pip install burnedsecret-cli`.

> **macOS first run:** the standalone binary is currently shipped unsigned. On
> first launch macOS Gatekeeper may block it; right-click → Open, or
> `xattr -d com.apple.quarantine $(which bs)` to clear the quarantine flag.
> (Signed/notarized builds are a follow-up — see the v1 gaps below.)

## Quickstart

```bash
# 1. Authenticate (opens your browser to authorize this machine)
bs auth login

# 2. Create a secret — prints ONLY the share URL on stdout
url=$(echo "the launch codes" | bs secret create --ttl 1h)
echo "$url"

# 3. Read (and burn) it
bs secret read "$url"
```

Because the share URL is the only thing on stdout, `url=$(... )` captures
exactly the URL; every prompt, table, and diagnostic goes to stderr.

## Global options

| Option              | Env var                  | Description                                              |
| ------------------- | ------------------------ | -------------------------------------------------------- |
| `--profile NAME`    | `BURNEDSECRET_PROFILE`   | Select a config profile (default: `default`).            |
| `--json`            | —                        | Emit the raw SDK shape as JSON on stdout.                |
| `--verbose` / `-v`  | —                        | Extra diagnostics on stderr.                             |
| `--version`         | —                        | Print the CLI version and exit.                          |

The API key is resolved as `BURNEDSECRET_API_KEY` (env) > the stored
`config[profile].api_key`.

## Command reference

### `bs secret create`

Creates a burn-after-reading secret and prints **only** the share URL.

| Flag                       | Description                                                              |
| -------------------------- | ------------------------------------------------------------------------ |
| `--content` / `-c`         | Secret text. If omitted: stdin pipe → `--edit` → hidden prompt.          |
| `--edit` / `-e`            | Compose the secret in `$EDITOR`.                                         |
| `--file` / `-f`            | Encrypt a file as the secret (max 10 MB). Excludes text input.          |
| `--passphrase` / `-p`      | Add a PBKDF2 passphrase layer (bare flag prompts hidden).               |
| `--max-views`              | Reads before the secret burns (1..5, default 1).                        |
| `--ttl`                    | Time to live: `5m` / `1h` / `1d` / `7d` (default `1d`).                 |
| `--webhook-url`            | Notify this URL when the secret is read.                                |
| `--notification-email`     | Email this address when the secret is read.                             |
| `--allow-ip CIDR`          | Only this IPv4/IPv6 CIDR or IP may open the secret (repeatable).        |
| `--allow-country CC`       | Only this ISO country code may open it, e.g. `NO` (repeatable).         |
| `--block-country CC`       | This ISO country code may not open it (repeatable).                     |

```bash
echo "hunter2" | bs secret create --max-views 3 --ttl 7d
bs secret create --file ./id_rsa --ttl 1h
bs secret create --content "deploy key" --passphrase --ttl 1h   # prompts for passphrase
echo "db password" | bs secret create --allow-ip 203.0.113.0/24 --allow-country NO
```

**Access restrictions.** `--allow-ip`, `--allow-country` and `--block-country`
work for text and `--file` secrets. Restrictions combine with AND: a caller
must match the IP allowlist and the country rule. `--allow-country` and
`--block-country` cannot be used together; mixing them exits with code `2`
before anything is created. Invalid values (a country that is not two letters,
a `/0` CIDR) also exit `2` with no request sent. A blocked caller gets the same
not-found answer as for a missing secret, in the CLI, the SDKs and the web
viewer. The creator is not exempt when reading or burning: you cannot burn a
secret from outside its allowlist either (only the creator's status-only
metadata lookup, `GET /v1/secrets/<id>/metadata`, is exempt). CAPTCHA is web-only and has no flag.

> **Web-viewer non-interop caveat:** secrets created with `--file` or
> `--passphrase` are decryptable only by an SDK/CLI client. Their share URL will
> **NOT** open in the burnedsecret.com web viewer. Plain text secrets without a
> passphrase remain web-viewer compatible. (After a `--file`/`--passphrase`
> create the CLI also prints a one-line reminder to stderr.)

### `bs secret read`

Reads and **burns** a secret from its share URL.

| Flag                  | Description                                                          |
| --------------------- | ------------------------------------------------------------------- |
| `URL` (argument)      | Share URL — **must** include the `#k=...` key fragment.             |
| `--passphrase` / `-p` | Passphrase for a protected secret (bare flag prompts hidden).       |
| `--output` / `-o`     | Write file-secret bytes to PATH, or `-` to stream to stdout.        |

```bash
bs secret read "https://burnedsecret.com/s/abc#k=..."
bs secret read "$url" --passphrase hunter2
bs secret read "$url" --output ./downloaded.bin
```

### `bs request create | status | read`

Ask someone to send you a secret. `create` needs a login (or
`BURNEDSECRET_API_KEY`) and prints two distinctly labelled links on stdout:

```text
Submission link: https://burnedsecret.com/r/<id>
Private view link: https://burnedsecret.com/r/<id>/view#s=<root secret>
```

Send the **submission link** to the person who will reply. Keep the **private
view link** yourself: anyone who has it can read the reply once, and it cannot
be recovered if lost (the server never sees the `#s=` part). A warning saying
so goes to stderr. Nothing is written to disk. With `--json`, `create` emits
exactly `{"url", "id", "private_view_url"}`.

| `create` flag          | Description                                                            |
| ---------------------- | --------------------------------------------------------------------- |
| `--prompt`             | What you are asking the recipient to send (required).                |
| `--fields`             | Custom fields: `name:type:required;...` (type = text\|password\|textarea). |
| `--ttl`                | `5m` / `1h` / `1d` / `7d`.                                            |
| `--webhook-url`        | Notify this URL when the request is fulfilled.                       |
| `--notification-email` | Email this address when the request is fulfilled.                    |
| `--fulfill-allow-ip CIDR` | Only this CIDR or IP may submit the reply (repeatable).            |
| `--fulfill-allow-country CC` / `--fulfill-block-country CC` | Allow or block countries for submitting the reply (repeatable, not both). |
| `--retrieve-allow-ip CIDR` | Only this CIDR or IP may read the reply with the private view link (repeatable). |
| `--retrieve-allow-country CC` / `--retrieve-block-country CC` | Allow or block countries for reading the reply (repeatable, not both). |

Restrictions are set per axis: `--fulfill-*` limits who may submit the reply,
`--retrieve-*` limits who may read it with the private view link, so you must
read from an allowed network. Allow and block countries are exclusive on each
axis (mixing them on one axis exits `2` before anything is created); an allow
rule on one axis and a block rule on the other is fine.

```bash
bs request create --prompt "send the VPN key" \
  --fulfill-allow-country NO --retrieve-allow-ip 198.51.100.0/24
```

`bs request status PRIVATE_VIEW_URL|-` reports `Status: waiting` or
`Status: ready` plus the expiry, without consuming the reply (`--json`:
`{"status", "expires_at"}`). `bs request read PRIVATE_VIEW_URL|-` reads and
burns the reply: free-text replies print as text, custom-field replies as
JSON. Neither command needs a login; the private view link is the credential.

Pass `-` to read the link from stdin. That keeps it out of shell history and
process lists, so prefer it over putting the link on the command line:

```bash
bs request create --prompt "send the AWS key" --ttl 1d
# Share the submission link. The recipient replies through it.
read -rs LINK          # paste the private view link (not echoed, not in history)
printf '%s\n' "$LINK" | bs request status -
printf '%s\n' "$LINK" | bs request read -
unset LINK
```

stdin must hold exactly one link; empty or multi-line input is rejected
without being echoed. If `read` reports "Retrieval outcome uncertain: the reply
may already be consumed; do not retry.", do not run it again: the one-time
read may already have happened. `status` does not consume anything, but the
private-link routes are rate limited (60 requests per minute per IP), so poll
sparingly or use `--webhook-url`.

#### Breaking change

`bs request create` and `bs request read` changed in this release line.
`create` no longer writes a private key file and no longer has a key
destination option; its `--json` output is now `{url, id, private_view_url}`.
`read` now takes the private view link (or `-`) instead of a request id plus a
private key source. Key files under
`<config_dir>/requests/` and the per-request key environment variables written
by earlier versions are no longer read and cannot read new requests; you can
delete them. The next published release needs a major-version decision; the
CLI version has not been bumped yet.

### `bs key create | list | revoke | whoami`

Key management is **browser/dashboard-assisted** in v1 (see the gaps below).

| Command       | Behavior                                                                       |
| ------------- | ------------------------------------------------------------------------------ |
| `key create`  | Alias of `bs auth login` — the PKCE exchange mints the labeled key.            |
| `key list`    | Prints your dashboard `/keys` URL (view/revoke there).                         |
| `key revoke`  | Prints the dashboard `/keys` URL; the CLI never network-revokes a key.         |
| `key whoami`  | Shows the stored `key_prefix`/`hostname`/`base_url` — **no network call**.     |

The CLI never mints sibling keys from a stored key: minting from a leaked key
would be a privilege-escalation surface.

### `bs auth login | logout | status`

| Command        | Behavior                                                                      |
| -------------- | ----------------------------------------------------------------------------- |
| `auth login`   | Browser PKCE flow; stores a hostname-labeled key. The key is **never printed**. |
| `auth logout`  | Forgets the local key (does **not** revoke server-side — use the dashboard).  |
| `auth status`  | Shows the profile's identity (configured?, source env/file, prefix, host).   |

### `bs config list-profiles`

Lists configured profiles with their `key_prefix`/`base_url`.

## Configuration & storage

Config lives at:

- **Windows:** `%APPDATA%\burnedsecret\config.toml`
- **POSIX:** `${XDG_CONFIG_HOME:-~/.config}/burnedsecret/config.toml`

On POSIX the config is written with `0600` permissions so only the owner can
read the stored API key. `bs request` writes nothing to disk; request key files
left in `<config_dir>/requests/` by earlier versions are unused and can be
deleted.

Environment overrides: `BURNEDSECRET_API_KEY`, `BURNEDSECRET_PROFILE`.

## Exit codes

Result data is always on stdout; diagnostics/errors/prompts are on stderr.

| Code | Meaning                   |
| ---- | ------------------------- |
| 0    | success                   |
| 1    | generic error             |
| 2    | invalid arguments / usage |
| 3    | authentication error      |
| 4    | not found                 |
| 5    | rate limited              |

The same table is shown in `bs --help`; see [`docs/exit-codes.md`](docs/exit-codes.md)
for the canonical reference and scripting examples.

## The browser-auth recipe (PKCE + loopback)

`bs auth login` implements a **reusable** pattern for authenticating a CLI/native
app through the browser without ever putting a secret in a URL or asking the user
to paste a token. It is a textbook implementation of **PKCE (RFC 7636)** plus the
**loopback-redirect native-app flow (RFC 8252)**, and the recipe transfers to any
CLI that needs browser auth — not just BurnedSecret:

1. **Generate ephemeral secrets locally.** A random CSRF `state` and a PKCE pair:
   `verifier = base64url(32 random bytes)`, `challenge = base64url(sha256(verifier))`
   (S256). The verifier never leaves the machine; only the challenge is sent.
2. **Bind a one-shot loopback server.** Grab a free `127.0.0.1:<port>` and start a
   single-request HTTP server in a thread. This is the redirect target — no public
   callback host, no firewall holes.
3. **Open the browser to the consent page**, carrying only public values: the
   loopback `callback`, the CSRF `state`, the S256 `code_challenge`, and a
   `hostname` label for the key. The URL is also echoed to stderr so a headless or
   no-default-browser user can paste it manually.
4. **Capture and validate the callback.** The browser redirects to the loopback
   server with `?code=&state=`. The handler **constant-comparison-checks the
   returned `state`** against the one it generated — a mismatch is a hard abort
   that captures no code, so no exchange ever happens. The callback carries only
   `code` + `state`; the API key is **never** in any URL.
5. **Exchange the single-use code for the key.** POST `{code, code_verifier}` to
   the exchange endpoint. The server recomputes `sha256(verifier)` and
   constant-time compares it to the stored challenge, proving the same client that
   started the flow is finishing it. The **API key is returned only in the
   response body**, then stored chmod-600 and never printed.

Security rationale, in one line each:

- **CSRF `state`** — prevents a forged callback from injecting an attacker's code.
- **PKCE `verifier`/`challenge`** — binds the code to this client; a stolen code
  is useless without the verifier, which never traveled over the network.
- **Key never in the callback URL** — URLs leak (history, logs, referrers); the
  key lives only in the exchange response body and on-disk chmod-600.
- **Single-use, short-TTL code** — narrows the window for replay.

## Documented v1 gaps & follow-ups

These are deliberate v1 scope decisions, recorded here rather than silently
dropped:

- **Access-restriction flags shipped (Phase 25).** `bs secret create` takes
  `--allow-ip` / `--allow-country` / `--block-country` and `bs request create`
  the `--fulfill-*` / `--retrieve-*` equivalents (see the command reference).
  CAPTCHA stays web-only; the CLI has no CAPTCHA flag.
- **Release ordering (SDK before CLI).** The restriction flags need a
  `burnedsecret` SDK release that contains `AccessRestrictions` (PyPI 1.2.0 does
  not). Publish that `sdk-py-v*` release first, raise the `burnedsecret` floor
  in `cli/pyproject.toml` to it, then tag `cli-v*`. Otherwise PyPI installs fail
  with `ImportError` on every command.
- **OS keyring storage is deferred to v2.** Keys are stored in a chmod-600
  config file, not the OS keychain/credential manager.
- **`bs secret read --copy` (clipboard) is deferred.** Pipe to your platform's
  clipboard tool (`pbcopy` / `clip` / `wl-copy`) in the meantime.
- **`bs secret create --bulk` is deferred.** Create secrets one at a time (or
  loop in your shell) for now.
- **Polished tab-completion install is deferred.** Typer's completion machinery
  is wired, but a one-command shell-completion installer is a follow-up.
- **`bs key list` / `bs key revoke` are browser/dashboard-assisted in v1.** They
  print your dashboard `/keys` URL rather than calling an API-key-authenticated
  keys endpoint (which would be a privilege-escalation surface). A
  token-cache-backed headless listing is a v2 option.
- **Standalone binaries before 1.0.4 do not start** (`ImportError: attempted
  relative import` on launch, all platforms). Reinstall with the installer,
  `brew upgrade bs`, or `scoop update bs`; pip installs were never affected.
- **Standalone macOS binaries are currently unsigned** (see the install note);
  signing/notarization is a follow-up.
- **No Intel macOS binary (decided 2026-09-17):** use pip; the wheel is the
  same code. Apple Silicon gets the standalone binary and the Homebrew formula.

### CI usage

Automation does **not** run the browser flow. CI uses a pre-minted
`BURNEDSECRET_API_KEY` env var; none of the `bs auth`/`bs key` commands are
needed in a pipeline.

## Published-channel smoke (CI)

The per-platform release workflows smoke-run the binary they just **built**.
That never proves the path a user actually takes, so
`cli/scripts/smoke_published_cli.py` (standard library only) exercises the
**published** `install.sh` channel end to end:

1. downloads the official installer from
   `https://burnedsecret.com/install/cli/install.sh` (fixed HTTPS origin) into
   a private temporary directory -- never the source-tree copy;
2. runs that downloaded file with `sh`, `BS_INSTALL_DIR` pointed at the
   temporary directory, so the installer fetches the release tarball and
   checksum from GitHub and verifies the SHA256 (its normal fail-closed path;
   `BS_ALLOW_UNVERIFIED` is never forwarded);
3. runs the installed binary by its absolute path: `bs --version` and
   `bs secret create --help`. Both are credential-free; neither can create a
   secret.

```bash
# offline contract tests (no network, mocked downloader/subprocesses)
python -m unittest discover -s cli/tests -p test_published_smoke.py -v

# live: latest published release (needs egress to burnedsecret.com + github.com)
python3 cli/scripts/smoke_published_cli.py

# live: exact release, e.g. right after publishing cli-v1.1.0
python3 cli/scripts/smoke_published_cli.py --version 1.1.0
```

| Where it runs                       | Mode                                     | Platform covered      |
| ----------------------------------- | ---------------------------------------- | --------------------- |
| `flutter-web` (every `dev` push)    | latest release, right after deployment   | macOS Apple Silicon   |
| `cli-binary-linux` (`cli-v*` tags)  | `--version ${CM_TAG#cli-v}` after upload | Linux x86_64          |

On `flutter-web` the step runs immediately after "Deploy to Firebase" on
purpose: `install.sh` is served by Firebase Hosting and published by that same
workflow, so smoking after the deploy proves the installer this build just
shipped (a pre-deploy smoke could only test the previous deploy's copy, and a
broken published installer would then block the deploy that fixes it). A
failure still fails the build and its GSDCC status notification.

Only `install.sh` is covered; Homebrew, Scoop, Chocolatey, `install.ps1` and
pip are not exercised by this check. The child processes get an allowlisted
environment (private `HOME`/`XDG_CONFIG_HOME`/working directory; no API keys,
publishing tokens or CLI profile state), so a smoke can never touch a real
account. Output is limited to the channel, the resolved version and bounded
diagnostics.

Reading a failure (`FAIL: ...`, exit 1 -- the CI step is a hard gate with no
`ignore_failure` and no fallback to a locally built binary):

- `installer download returned HTTP 4xx` -- the installer is not being served
  by Firebase Hosting (check the "Stage CLI install scripts" step).
- `installer exited N: ... download failed: <url>` -- the release asset for
  this platform/version is missing on GitHub. Transient propagation is retried
  a bounded number of times (`--download-retries`, default 3); a persistent
  failure after a release means the upload step did not publish the asset
  (for example `GITHUB_TOKEN` was absent).
- `checksum mismatch` / `checksum file unavailable` -- never retried; the
  published tarball and `.sha256` disagree or the checksum was not uploaded.
- `installed version X does not equal the requested release Y` -- the tag's
  tarball contains a binary built from a different version.
- `bs --version exited N` / `... printed no version` / `usage line is not for
  'create'` -- the published binary does not start or its CLI surface changed.
- `timed out` -- bounded by `--download-timeout` (installer fetch) and
  `--command-timeout` (each child process).
