7 Commits
Author SHA1 Message Date
lotherk 154d25be91 accept input of exactly the documented size limit
ci / build (push) Successful in 28s
Review found the cap used as an output bound as well as an input bound: a file
of exactly 1 GiB, the documented maximum, was rejected twice. scr_read_fd could
not tell a full buffer from a larger input, and scr_encrypt refused anything
over SCR_INPUT_MAX minus the envelope overhead. The reader now probes a single
byte past a full buffer to distinguish the two, and the encrypt guard is a
plain size_t overflow check.

The suite builds a second binary with -DSCR_INPUT_MAX=65536 so both sides of the
boundary are tested without a 1 GiB file; the previous code fails the exact-cap
case. Also adds CRLF armor and 'a failed decrypt leaves the output file alone'
cases, and documents that -r on a protected key asks for its passphrase.
2026-11-21 20:07:04 +00:00
lotherk 577052decd fix the remaining review findings in key handling
ci / build (push) Successful in 30s
- Parse public key lines field by field instead of searching for the type name
  anywhere. A commented-out key line is now ignored (it used to be accepted,
  so a secret could be encrypted to a key the user had disabled), and an
  authorized_keys option that contains the word ssh-rsa no longer aborts the
  parse. A candidate field only counts if its base64 decodes to that type.
- Bound the line loop by the buffer length, not by *p: the buffer is not NUL
  terminated, so a 64 KiB file ending in a newline made the loop look at
  uninitialised heap (valgrind). Reproduced on the old build, clean now.
- Ask for the passphrase before creating the temp file, and register an
  atexit cleanup, so a scr_die between mkstemp and the unlink cannot leave the
  key behind (no tty and no SSHCRYPT_PASSPHRASE used to leak one per run).
- Install the cleanup handler before the prompt again. A background job in a
  non-interactive shell inherits SIG_IGN for SIGINT, and ignored dispositions
  survive exec, so killing at the prompt is a no-op without a handler.

The suite is 31 cases and now covers each of these; five of them fail on the
previous build.
2026-11-21 19:02:08 +00:00
lotherk 6851364ccb bound the public blob copied out of a key container
ci / build (push) Successful in 1m7s
Review found a stack-buffer-overflow in scr_openssh_load: the public blob
length came straight from the file and was memcpy'd into struct scr_priv's
4096-byte field. A crafted RSA key file (the ed25519 path cross-checks first)
overwrote the stack: ASan reported a 6000-byte write.

Also reject p or q <= 1 before BN_mod, arm the temp-file cleanup before the
write rather than after, clear the active flag on the conversion-failure path,
and block INT/TERM/HUP across ssh-keygen so a signalled child cannot rename a
fresh copy back after the handler unlinked it.

The new case crafts an oversized blob and asserts a clean exit 1, not a crash.
2026-11-21 18:38:46 +00:00
lotherk c65e756cac read the OpenSSH key container ourselves
ci / build (push) Successful in 35s
ssh-keygen -p -m PKCS8 is not a conversion path: on OpenSSH 10.2 (Ubuntu
26.04 LTS) it ignores -m for ed25519 keys, exits 0, and leaves the container,
so every ed25519 decryption failed there. RSA still converted, which hid it.

src/openssh.c now parses the unencrypted openssh-key-v1 container directly:
ed25519 seed plus public key, or RSA n/e/d/iqmp/p/q, with the public and
private halves checked against each other. ssh-keygen is left with one job,
stripping a passphrase (-p -N ''), which works on every version. Unencrypted
keys no longer need the program at all, which the suite now asserts by
running one decryption with PATH=/nonexistent.

Verified on Debian bookworm (OpenSSH 9.2) and Ubuntu 26.04 (10.2).
2026-11-21 17:11:26 +00:00
lotherk 5eaa930520 unlink the converted key when the conversion is interrupted
SIGINT at the passphrase prompt used to leave the 0600 temp file in /dev/shm
until reboot. A handler for INT, TERM and HUP removes it and exits. The test
interrupts a real pty session and checks the temp directory.
2026-11-21 16:19:34 +00:00
lotherk d471ec1723 fix the tty prompt: restore echo, keep queued input
The old prompt saved termios, disabled ECHO, then re-read termios into the
same struct to restore it - which restored the no-echo state. Because termios
belongs to the terminal, not the fd, the user's shell was left without echo.
TCSAFLUSH also discarded a passphrase that was already queued in the tty.

Save the original state once, restore that copy, and use TCSANOW. Two
script(1) cases now cover the prompt end to end and go red on the old code.
2026-11-21 16:16:33 +00:00
lotherk 0afb114993 sshcrypt: encrypt to an SSH public key, decrypt with the private key
C99/POSIX tool, one job: -r PUBKEY encrypts, -d -k PRIVKEY decrypts.
Ed25519 goes through X25519 + HKDF-SHA256 + ChaCha20-Poly1305, RSA through
RSA-OAEP-SHA256. Text armor by default so the message survives mail and chat.
OpenSSH private keys are converted through ssh-keygen; no other subprocess is
ever started.
2026-11-21 10:56:55 +00:00