repositories

NixDaemon

NixOS pentest workstation as one flake — IceBreaker's successor

clonegit clone https://git.daemon-sec.xyz/NixDaemon.git
gpgx.mdMarkdown210 lines14.7 KiBsource 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.

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

Encrypt#

Decrypt#

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.

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.

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#

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#

Many files, one signature#

The release-artifact pattern, and the reason gpgx sum exists.

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.

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#

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".

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.

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#

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.