diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..22ec2a7 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,41 @@ +name: ci + +on: + push: + branches: [main] + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: dependencies + run: | + SUDO= + if [ "$(id -u)" -ne 0 ] && command -v sudo >/dev/null 2>&1; then + SUDO=sudo + fi + if command -v apt-get >/dev/null 2>&1; then + $SUDO apt-get update + $SUDO apt-get install -y --no-install-recommends \ + build-essential libssl-dev pkg-config \ + openssh-client python3 util-linux procps + fi + + - name: build + run: make + + - name: test + run: make check + + - name: man page + run: make lint-man + + - name: sanitizers + run: | + make clean + make CFLAGS="-O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer" \ + LDFLAGS="-fsanitize=address,undefined" + make check diff --git a/AGENTS.md b/AGENTS.md index 1533614..a845cbb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,6 +30,10 @@ you pass; do not remove that `override`. * `src/armor.c` — base64 armor. * `src/util.c` — buffers, base64, zeroing. * `tests/run.sh` — everything is tested through the binary, not unit tests. +* `docs/sshcrypt.1` — the man page. Any flag change updates it too; + `make lint-man` (what CI runs) fails on bad markup. +* `.gitea/workflows/ci.yml` — build, `make check`, `make lint-man`, then the + same tests again under ASan+UBSan. ## Traps that already cost time (all verified) diff --git a/Makefile b/Makefile index 4e1ef63..c2b75ac 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ PREFIX ?= /usr/local BINDIR ?= $(PREFIX)/bin +MANDIR ?= $(PREFIX)/share/man/man1 CC ?= cc PKG_CONFIG ?= pkg-config @@ -25,8 +26,17 @@ check: sshcrypt install: sshcrypt install -d $(DESTDIR)$(BINDIR) install -m 0755 sshcrypt $(DESTDIR)$(BINDIR)/sshcrypt + install -d $(DESTDIR)$(MANDIR) + install -m 0644 docs/sshcrypt.1 $(DESTDIR)$(MANDIR)/sshcrypt.1 + +lint-man: + @if command -v mandoc >/dev/null 2>&1; then \ + mandoc -Tlint docs/sshcrypt.1 && echo "man page ok"; \ + else \ + echo "mandoc not installed, man page not linted"; \ + fi clean: rm -f $(OBJ) sshcrypt -.PHONY: all check install clean +.PHONY: all check install lint-man clean diff --git a/README.md b/README.md index 189b9bf..35ac127 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,10 @@ Code: https://git.kropa.tech/hiddenbox/sshcrypt make # the binary, needs libcrypto headers make check # end-to-end tests, no network - make install PREFIX=$HOME/.local # ~/.local/bin/sshcrypt + make install PREFIX=$HOME/.local # ~/.local/bin/sshcrypt and the man page + make lint-man # mandoc -Tlint, if mandoc is installed + + man sshcrypt ## The usual job diff --git a/docs/sshcrypt.1 b/docs/sshcrypt.1 new file mode 100644 index 0000000..c53fcfc --- /dev/null +++ b/docs/sshcrypt.1 @@ -0,0 +1,168 @@ +.TH SSHCRYPT 1 "2026-11-21" "sshcrypt 0.1.0" "User Commands" +.SH NAME +sshcrypt \- encrypt a file, a message, or stdin for an SSH public key +.SH SYNOPSIS +.B sshcrypt +.B \-r +.I pubkey +.RB [ \-i +.IR in ] +.RB [ \-o +.IR out ] +.RB [ \-b ] +.RB [ \-q ] +.br +.B sshcrypt +.B \-d \-k +.I privkey +.RB [ \-i +.IR in ] +.RB [ \-o +.IR out ] +.RB [ \-q ] +.br +.B sshcrypt +.B \-F +.I key +.SH DESCRIPTION +.B sshcrypt +encrypts bytes for the holder of an SSH key pair. +Encrypting needs only the recipient's public key, the one already in their +.I authorized_keys +or +.IR id_ed25519.pub . +Decrypting needs the matching private key. +Nothing else is configured, and no identity system is created. +.PP +The ciphertext is ASCII armored by default, so it survives mail, chat and +copy-paste. +With +.B \-b +the raw binary envelope is written instead. +.PP +The default mode is encrypt. +Input is stdin unless +.B \-i +is given; output is stdout unless +.B \-o +is given. +Nothing but the payload is written to stdout. +.SH OPTIONS +.TP +.BR \-e ", " \-\-encrypt +Encrypt. +This is the default. +.TP +.BR \-d ", " \-\-decrypt +Decrypt. +Requires +.BR \-k . +.TP +.BR \-r ", " \-\-recipient " " \fIFILE\fP +The recipient's public key, in +.I authorized_keys +format. +A private key is accepted too: its public half is derived from it. +A file that holds more than one supported key is rejected. +.TP +.BR \-k ", " \-\-key " " \fIFILE\fP +Your private key, for +.BR \-d . +PEM and PKCS#8 keys are read directly. +An OpenSSH-format key +.RB ( "BEGIN OPENSSH PRIVATE KEY" ) +is converted through +.BR ssh-keygen (1), +which must then be installed. +.TP +.BR \-i ", " \-\-input " " \fIFILE\fP +Read from +.IR FILE . +The default is stdin; +.B \- +also means stdin. +.TP +.BR \-o ", " \-\-output " " \fIFILE\fP +Write to +.IR FILE . +The default is stdout. +.TP +.BR \-b ", " \-\-binary +Write the raw envelope without the text armor. +.TP +.BR \-q ", " \-\-quiet +Do not print the +\(lqencrypted for\(rq +line on stderr. +That line only appears when stderr is a terminal anyway. +.TP +.BR \-F ", " \-\-fingerprint " " \fIKEY\fP +Print the key's +\(lqSHA256:...\(rq +fingerprint, the same value +.B ssh\-keygen \-l +shows, and exit. +.TP +.BR \-h ", " \-\-help +Print usage and exit. +.TP +.BR \-V ", " \-\-version +Print the version and exit. +.SH ENVIRONMENT +.TP +.B SSHCRYPT_PASSPHRASE +The private key passphrase, for scripts. +Without it the passphrase is read from +.I /dev/tty +with echo off. +It is never read from stdin, which carries the payload. +.TP +.B TMPDIR +Where the temporary key conversion file goes when +.I /dev/shm +is not writable. +.SH FILES +.TP +.I /dev/tty +The passphrase prompt. +.TP +.I /dev/shm/sshcrypt\-XXXXXX +A conversion file, mode 0600, created only for an OpenSSH private key. +It is unlinked as soon as it has been read, and on SIGINT, SIGTERM or SIGHUP. +.SH "EXIT STATUS" +.TP +.B 0 +Success. +.TP +.B 1 +Usage or I/O error. +.TP +.B 2 +Malformed input: not an sshcrypt message, truncated, or bad base64. +.TP +.B 3 +Wrong key, or the message was modified. +.SH SECURITY +There are no signatures and no sender authentication: +anyone holding your public key can encrypt to you, and a message proves +nothing about who sent it. +.PP +There is no forward secrecy. +Whoever later obtains the recipient's private key can decrypt the messages +they kept. +.PP +Check fingerprints out of band. +A message names the fingerprint it was addressed to, and +.B sshcrypt +refuses to guess: a mismatch prints both fingerprints. +.PP +Ed25519 and RSA keys are supported. +ECDSA keys are not. +.PP +The whole input is buffered in memory, up to 1 GiB. +.SH "SEE ALSO" +.BR ssh (1), +.BR ssh\-keygen (1), +.BR openssl (1) +.SH LICENSE +CNCL 1.1, the Could Not Care Less License. diff --git a/src/main.c b/src/main.c index 70107ba..f8c3e1e 100644 --- a/src/main.c +++ b/src/main.c @@ -36,7 +36,7 @@ static void usage(FILE *f) static void version(void) { - printf("sshcrypt %s\n", "0.1.0"); + printf("sshcrypt %s\n", SCR_VERSION_STR); } static const char *need_arg(int argc, char **argv, int *i, const char *opt) diff --git a/src/sshcrypt.h b/src/sshcrypt.h index 19d9c0c..349b58b 100644 --- a/src/sshcrypt.h +++ b/src/sshcrypt.h @@ -4,6 +4,7 @@ #include #define SCR_VERSION 1 +#define SCR_VERSION_STR "0.1.0" #define SCR_SUITE_X25519 1 #define SCR_SUITE_RSA 2