repositories

NixDaemon

NixOS pentest workstation as one flake — IceBreaker's successor

clonegit clone https://git.daemon-sec.xyz/NixDaemon.git
gpgx.mdMarkdown210 lines14.7 KiBrendered raw download
# gpgx — gpg without the flag archaeology

One verb per thing gpg is actually used for: lock, unlock, sign, verify, sum, keys.
Every passphrase is typed in **this terminal** — no pinentry window ever opens.
Quick card: **`gpgx-cheat`**. Raw command: **`gpgx -n …`**.

## The paste box
Bare **`gpgx`** opens it. Paste anything, **ctrl-d** ends, **ctrl-c** aborts. There is no mode to choose — it reads what you pasted and does the only sensible thing:

| What you paste | What happens |
|---|---|
| plain text | encrypted to your default key, armored — `gpgx -r KEY` picks someone else, `gpgx --sym` for passphrase-only |
| `-----BEGIN PGP MESSAGE-----` | decrypted (asks for your passphrase) |
| `-----BEGIN PGP SIGNED MESSAGE-----` | verified, then the text is printed |
| `-----BEGIN PGP PUBLIC KEY BLOCK-----` | described — **imported: no** |

(The private-key row is written without its leading `-----BEGIN` on purpose: the
dotfiles secret scanner matches that exact header, and a cheat sheet describing
it should not trip a check that exists to catch the real thing.)
| `…PGP PRIVATE KEY BLOCK-----` | **refused.** Secret keys are never imported by accident |

Output goes to **stdout always** (so it pipes) and to the **clipboard as well** when you are at a terminal — `pbcopy`, `wl-copy` or `xclip`, whichever exists. Redirect it (`gpgx > out.asc`) and the clipboard is skipped: a pipe wants bytes, not a side effect on the desktop session.

- **`gpgx text -r alice@ex.com`** — encrypt to someone else instead of yourself.
- **`gpgx text --sym`** — passphrase-only. They need no key, just the word.
- **`gpgx text -s`** — sign it too, so they know it was you.
- **`echo hi | gpgx`** — same thing from a pipe.

This replaces the old habit `cat <<EOF | gpg --armor --encrypt -r … ` — same result, no pipeline, no flags.

## Encrypt
- **`gpgx lock secrets.txt`** → `secrets.txt.gpg`. Encrypted to **you**, because that is the overwhelmingly common case and the one thing gpg makes you spell out every time.
- **`gpgx lock -r alice@ex.com f`** — only Alice can open it.
- **`gpgx lock -r a -r b f`** — several recipients; **any one** of them can open it.
- **`gpgx lock --sym f`** — passphrase-only, no keys involved at all.
- **`gpgx lock -a f`** → `f.asc`, ascii armor. Pasteable, roughly **33% bigger**.
- **`gpgx lock -s f`** — sign as well as encrypt.
- **`-o out.gpg`** names it; **`-f`** overwrites.

## Decrypt
- **`gpgx unlock f.gpg`** → `f`. The crypto suffix is stripped; a name carrying none gets `.out` appended rather than being overwritten in place.
- **`gpgx unlock -o - f.gpg`** → stdout, so it pipes.
- **`gpgx unlock -o - backup.tar.gpg | tar t`** — look inside without ever writing the plaintext to disk.

A signature **inside** an encrypted file is checked and reported automatically. That is the interesting half: encryption says only that nobody else could read it, never who wrote it.

## Many files at once
Every file verb takes a glob. The passphrase is read **once, before the loop** — three files do not mean three prompts.

- **`gpgx sign *.pdf`** → `a.pdf.asc`, `b.pdf.asc`, `c.pdf.asc`. One signature **per file**.
- **`gpgx lock *.pdf`** → one `.gpg` per file.
- **`gpgx unlock *.gpg`** → all of them, still one prompt.
- **`gpgx sum *.pdf`** → the **other** shape: one manifest and one signature covering the whole set.

`sign` and `sum` answer different questions. Per-file signatures let each file travel on its own; a manifest proves the **set** is complete and costs one signature instead of N. Reach for `sum` when you are shipping a release, `sign` when the files will be handed out separately.

**`-o` names a single file**, so it is refused outright when several inputs are given — otherwise each file in the loop would overwrite the last, and all but one would be silently destroyed. The refusal happens *before* the passphrase prompt.

## Public key or passphrase — which
The one decision that actually changes the outcome.

- **Public key (`-r`)** — they need no secret from you, and nothing has to be arranged in advance beyond having their key. Best for **other people**. Only their secret key opens it.
- **Symmetric (`--sym`)** — one shared word, no keys at all. Best for **yourself**, or for someone you can tell the word to over a phone call. The file is openable by anyone who learns the word.
- **Lost passphrase** — unrecoverable. There is no reset and no backdoor; that is the design, not an oversight.

gpgx names **AES256** and **SHA512** explicitly rather than letting gpg negotiate. gpg's default falls back to whatever the *recipient's* key advertises a preference for, which can be considerably older than anything you would pick yourself.

## Signing — three shapes
| Command | Produces | Use when |
|---|---|---|
| `gpgx sign release.tar` | `release.tar.asc` (detached) | the original must stay byte-identical |
| `gpgx sign --inline notes.txt` | one file with data + signature | you want a single artifact |
| `gpgx sign --clear notes.md` | readable text, signature appended | email, forum posts, commit-style text |
| `gpgx sign --binary f` | `f.sig` instead of `f.asc` | space matters more than pasteability |

**Detached is the default** because it leaves the file untouched: the thing you shipped and the thing you signed remain the same bytes. All three use **SHA512** unless `--digest` says otherwise. **`-u KEY`** signs as a specific key.

## Verify
- **`gpgx verify release.tar`** — finds `release.tar.asc` or `.sig` beside it.
- **`gpgx verify release.tar.asc`** — same result, whichever half you name.
- **`gpgx verify sig.asc data.bin`** — spell both out when the names do not correspond.

**Exit 0** = good signature. **Exit 1 and red** = BAD signature, which means the data changed after it was signed. That verdict is fatal and never dressed as a warning you might scroll past.

Verdicts come from gpg's `--status-fd` machine stream (`GOODSIG` / `BADSIG` / `EXPKEYSIG` / `NO_PUBKEY`), never from scraping human-readable stderr — that text is localised and rewritten between gpg versions.

### What a good signature proves
- **This key signed these exact bytes**, and they have not changed since.
- **Not** that the key belongs to the person whose name is on it. That is a separate question — see **Trust** below.

## Many files, one signature
The release-artifact pattern, and the reason `gpgx sum` exists.

- **`gpgx sum dist/*`** → `SHA256SUMS` **+** `SHA256SUMS.asc`.
- **`gpgx sum --algo sha512 f*`** → `SHA512SUMS`.
- **`gpgx sum --no-sign f*`** — manifest only; sign it later with `gpgx sign`.
- **`gpgx check SHA256SUMS.asc`** — verifies the **signature first**, then every hash.

Signing each file separately would need N signatures and N verifications and *still* would not prove the set was complete. One signature over a manifest covers all of it, and the manifest is a plain text file readable without gpg at all — **`shasum -a 256 -c SHA256SUMS`** works on any box.

Order matters in `check`: hashes verified against a manifest nobody signed prove the files match a list, not who wrote the list. An attacker who can change the files can change an unsigned manifest too.

Paths are recorded **relative to the manifest**, so `gpgx sum dist/*` writes `dist/a.bin` and still resolves when checked from the same directory.

### Digests offered
| Algorithm | Notes |
|---|---|
| `sha256` | the default. Fine for everything. |
| `sha512` | faster than sha256 on 64-bit CPUs, and longer |
| `blake2b` | faster still, less universally installed |
| `sha3-256` | different construction — for when SHA-2 specifically worries you |
| ~~`md5`, `sha1`~~ | **not offered.** Both are broken; a signed list of broken hashes proves nothing, which is worse than no signature at all. |

## Which key gets used
Nothing named? **`default-key` from `~/.gnupg/gpg.conf`** — deliberately the same key `git commit -S` uses, so gpgx can never disagree with the rest of the system. Reading the config beats guessing "the first secret key", which is whatever sorts first in the keyring and changes silently when you import an older one.

- **`-u KEY`** — override for one signing command.
- **`-r KEY`** — override for one encryption.
- **`GPGX_KEY=<id>`** — override for a whole shell.

**`gpgx keys`** lists yours with **★** on the default. **`gpgx keys --public`** lists everyone else's. **`gpgx fp`** prints fingerprints grouped in fours, the way they are read aloud.

## Making and keeping keys
- **`gpgx key new`** — guided: name, email, expiry, algorithm (**ed25519** modern, or **rsa4096** for old software). Uses `--quick-generate-key`, which builds the encryption subkey too — the interactive `--full-generate-key` dialogue makes you walk through that by hand.
- **`gpgx key expire KEY 2y`** — push the expiry date out. Subkeys carry their own.
- **`gpgx key passwd KEY`** — change the passphrase. This one hands off to gpg's own prompt, because gpg has no option to accept an old **and** a new passphrase on file descriptors. It still happens in this terminal; it just looks like gpg rather than gpgx.
- **`gpgx key export KEY`** — public key, armored, to stdout.
- **`gpgx key export --secret`** — the real thing. Warns first, writes mode **600**.
- **`gpgx key import f.asc`** — read one in.
- **`gpgx key revoke KEY`** — write the cancel-this-key certificate, mode 600. Store it **apart** from the key and never in the same backup.

### Backup — all three parts
**`gpgx key backup`** writes a directory (mode 700, files 600) containing:

| File | Why it is not optional |
|---|---|
| `secret-keys.asc` | the keys themselves |
| `ownertrust.txt` | who you vouched for — a **separate database**. Lose it and every key you trusted drops back to "unknown". |
| `openpgp-revocs.d/` | revocation certificates — without them you cannot announce a compromise you can no longer sign for |

Secret keys alone are not a backup. Restore with `gpgx key import secret-keys.asc && gpg --import-ownertrust ownertrust.txt`.

## Trust — two different questions
People conflate these constantly, and gpg's interface does nothing to help.

1. **Is this key really theirs?** → you check the **fingerprint** with them, out of band, then sign the key.
2. **Do I trust them to vouch for other people?** → that is **ownertrust**: `gpgx key trust`.

| Level | Meaning |
|---|---|
| 1 unknown | no opinion. The default for everyone. |
| 2 never | actively do not trust them to vouch for others |
| 3 marginal | vouches somewhat — three marginals equal one full |
| 4 full | you trust their signatures on other people's keys |
| 5 ultimate | this is your own key. Nothing else belongs here. |

Setting trust changes nothing about *them* — it changes which **other** keys gpg will accept as valid by way of them. It is local, private, never published, and the part everybody forgets to back up.

## Passphrases — when it asks, and why
The rule: **unlocking a secret needs the word.** Nothing else does.

| Command | Asks? | Why |
|---|---|---|
| `gpgx lock f` | no | a public key unlocks nothing |
| `gpgx lock -s f` | yes | signing unlocks **your** key |
| `gpgx lock --sym f` | yes, twice | you are choosing a new passphrase |
| `gpgx unlock f.gpg` | yes | unlocking your secret key |
| `gpgx sign`, `gpgx sum` | yes | same reason |
| `gpgx verify`, `gpgx check` | no | verification is entirely public |
| any command with `-n` | no | dry-run reports what *would* run |

### How it is typed
Read from **`/dev/tty`** with `ECHO` off, one **`•`** painted per keystroke. Backspace and ctrl-u work. `getpass()` would do the reading but shows nothing at all — no cursor movement, no length, no sign the keyboard is connected, which is the single most common reason people think a tool "didn't ask".

- **`--show-passphrase`** — echo it literally instead of masking.
- **`--use-agent`** — hand the job back to gpg-agent instead.
- **Never in argv**, so it never appears in `ps`. **Never in the environment**, so no child process inherits it.

gpg receives it on a private file descriptor with `--pinentry-mode loopback`. That pairing is what stops the pinentry window from ever opening.

### When gpg-agent does the asking
`key passwd`, `--use-agent` and `raw` cannot go by loopback, so gpg-agent raises its own pinentry for them. It still lands in **this terminal**: gpgx exports `PINENTRY_USER_DATA=gpgx-tty` (plus `GPG_TTY`), gpg forwards that to the agent, and the agent's `pinentry-program` is `~/.local/bin/pinentry-switch` — a dispatcher that runs **pinentry-tty** when it is `gpgx-tty` (or `tty`) and **pinentry-mac** otherwise. Plain `gpg`, `git commit -S` and GUI apps set nothing, so they get the window. The conf line is `pinentry-program /Users/daemon1/.local/bin/pinentry-switch` in `~/.gnupg/gpg-agent.conf` (absolute path — gpg-agent 2.2 does not expand `~`); `gpgconf --kill gpg-agent` reloads it. gpgx also starts the agent from a clean environment before exporting the marker, so a daemon it happens to launch never inherits `gpgx-tty` for everyone else.

## Suffixes
| Suffix | Means |
|---|---|
| `.gpg` | binary encrypted (default) |
| `.asc` | ascii-armored — encrypted, or a signature |
| `.pgp` | binary, other tools' spelling |
| `.sig` | detached binary signature |

`gpgx unlock` and `gpgx verify` recognise all of them without a flag.

## Keyservers
Default **`hkps://keys.openpgp.org`**, overridable with `--keyserver` or `GPGX_KEYSERVER`.

- **`gpgx recv 0xDEADBEEF`** — fetch someone's key.
- **`gpgx search alice@ex.com`** — look them up.
- **`gpgx send`** — publish yours. **Public and permanent**; keyservers do not forget.

keys.openpgp.org verifies the email address before publishing an identity, which is why it is the default rather than the old SKS pool — that pool is unmaintained and accepts poisoned keys.

## The escape hatches
- **`gpgx -n <anything>`** — print the real gpg command and run nothing. The passphrase fd is shown as a placeholder, since the real number is an artifact of the process.
- **`gpgx raw ARGS…`** — straight through to gpg, nothing translated. `gpgx raw --list-packets f.gpg` to see what is actually inside a file; `gpgx raw --edit-key KEY` for the full interactive dialogue.

## Why it does not just call `gpg`
gpg's grammar is historical rather than logical. `--encrypt` and `--symmetric` are different **modes** rather than different flags. `--sign` means three unrelated things depending on which other option sits beside it. A detached signature and a clear signature are entirely different option names for what is conceptually one choice. And gpg-agent here runs `default-cache-ttl 0`, so every operation would otherwise raise a GUI window.

gpgx picks one verb per intent, reads the passphrase itself, and spells the raw command out under `-n` — so nothing is hidden. The incantation is **taught**, not replaced, and `raw` is always there when the wrapper is in the way.