Skip to content
stopsopaPublic

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ssenc

Start here: examples/SUMMARY.md — all arguments in one table, then every use case as a few commands to copy and run.

Format specification: SPEC.md — the exact bytes of an encrypted file.

Live pages

  • Encryptor — type a message and a key in the browser, get a shareable link that holds only the encrypted text
  • Test report — every implementation decrypting what every other one encrypted, rebuilt on each push

Install

The Rust ssenc command is released as a single binary, nothing else is needed to use it. (The TypeScript and Bash implementations are used from a clone of this repository, see Command line.)

Download and verify

Go to GitHub Releases, open the release you want (the latest one normally) and run the block of your platform (ssenc-darwin-arm64, ssenc-linux-x64, ssenc-linux-arm64). It creates a new temporary directory, cds into it, downloads the binary there as ssenc and verifies its checksum.

The verification has to end with ssenc: OK. Then come back here, in the same terminal (you are in the directory with the downloaded file).

Or build it instead: rust/compile.sh gives rust/target/release/ssenc (version dev).

Install

In the directory with the downloaded file:

mkdir -p ~/.ssenc
mv ssenc ~/.ssenc/
chmod 755 ~/.ssenc/ssenc

# check that it runs
~/.ssenc/ssenc --version

Add one line to the startup file of your shell. Run one of the two blocks: the first is for zsh (~/.zshrc), the second for bash (~/.bashrc). It is safe to run it again: when the line is already there (the comment # ssenc - https://github.com/stopsopa/encrypt is what is looked for), nothing is added:

if grep -qF '# ssenc - https://github.com/stopsopa/encrypt' ~/.zshrc 2> /dev/null; then
  echo "already in ~/.zshrc, nothing added"
else
  cat <<'EEE' >> ~/.zshrc

# ssenc - https://github.com/stopsopa/encrypt
export PATH="${HOME}/.ssenc:${PATH}"
EEE
  echo "added to ~/.zshrc"
fi
if grep -qF '# ssenc - https://github.com/stopsopa/encrypt' ~/.bashrc 2> /dev/null; then
  echo "already in ~/.bashrc, nothing added"
else
  cat <<'EEE' >> ~/.bashrc

# ssenc - https://github.com/stopsopa/encrypt
export PATH="${HOME}/.ssenc:${PATH}"
EEE
  echo "added to ~/.bashrc"
fi

Open a new terminal and check that it works, without any path:

ssenc --version     # ssenc rust <tag of the release>
ssenc --help

The file can live anywhere, ~/.ssenc is only a suggestion: it only has to be found through PATH. Later: ssenc --update.

Update

ssenc --update            update to the latest release
ssenc --update <tag>      install the given release (also an older one), e.g. v0.1.0
ssenc --update --check    only say whether there is something newer, change nothing

Needs curl or wget, and sha256sum or shasum. The new binary is downloaded next to the installed one, its sha256 is compared with SHA256SUMS.txt of the release, it is executed and has to report the expected version, and only then the installed file is replaced (by rename). After any failure the installed file is what it was. The checksum comes from the same release as the binary: it protects against a broken download, not against someone who controls the release.

Variable Default
SSENC_RELEASES https://github.com/stopsopa/encrypt/releases where ssenc --update takes releases from (url or directory with the same layout)
SSENC_CONFIRM true false: ssenc --update doesn't ask before replacing the binary

A binary built locally (ssenc rust dev) is not a release and refuses to update.

Documentation

About

Password / ssh-agent encryption of text and binary files into diff-friendly ASCII text, with three interoperable implementations: TypeScript, Rust and Bash.

Made for keeping encrypted files in git: in line mode every line is encrypted on its own, so when one line of the plaintext changes, exactly one line of the encrypted file changes.

plain                       encrypted
----------------------      ------------------------------------------------
server:                     #ssenc1 lines ws=1 pad=16
    host: db.internal       #slot pw argon2id m=65536,t=3,p=4 os3aSYtR… 2y0CzoI8…
    port: 5432              PqXYBv6DPJHnspY2ZLnfpvTlwrVyJyqG3W-7CM1mISE
                                5DoEJCK0j5aaC4fNti2JC_jz5LeQS9rGzzL1ESoKSQntIaD_jpFlzQ…
                                QcTY1sI009UgXjWCZuwOwNikpQhBIdWbf9wVNCkpk-w

What it does

Password Argon2id → key. Cost parameters are stored in the file.
Cipher AES-256-CTR + HMAC-SHA-256 in SIV composition: authenticated and deterministic.
Lines mode Line by line. Leading/trailing spaces and tabs stay in clear (optional), line endings are kept.
Blob mode Any bytes, 64 KiB authenticated chunks, base64url wrapped at 76 columns.
SSH key Key derived from a signature made by ssh-agent (Ed25519 or RSA). The private key never leaves the agent.
Several keys A file can have several key slots, e.g. your ssh key and a backup password.
Rekey Replace the keys, either re-encrypting everything or only rewrapping the data key.

Command line

Every implementation has the same CLI: rust/bin/ssenc, typescript/bin/ssenc, bash/bin/ssenc.

export SSENC_PASSWORD='…'                       # or --password-file F, or a prompt on a terminal

ssenc encrypt -i config.yml -o config.yml.enc   # lines mode
ssenc decrypt -i config.yml.enc -o config.yml
ssenc encrypt --mode blob -i photo.jpg -o photo.jpg.enc
ssenc encrypt --mode auto -i "$file" -o "$file.enc"   # lines for text, blob for anything else

# after editing config.yml: the existing output is reused, only changed lines differ
ssenc encrypt -i config.yml -o config.yml.enc

# ssh key (must be loaded in ssh-agent), optionally together with a password
ssenc encrypt --ssh-key ~/.ssh/id_ed25519.pub -i config.yml -o config.yml.enc
ssenc decrypt --ssh-key ~/.ssh/id_ed25519.pub -i config.yml.enc

# change the key
SSENC_NEW_PASSWORD='…' ssenc rekey -i config.yml.enc -o config.yml.enc
ssenc inspect -i config.yml.enc                 # mode and key slots, no key needed

Options: --mode lines|blob|auto, --no-preserve-ws, --pad N, --chunk N, --kdf default|strong|m=..,t=..,p=.., --seal, --previous FILE, --fresh, --rewrap-only. Exit codes: 1 usage, 2 wrong key or modified data, 3 malformed input, 4 environment (ssh-agent, unsupported key). Everything about the command line: docs/cli.md.

Libraries

Same four operations everywhere: encrypt, decrypt, rekey, inspect.

TypeScript — one file, no dependencies, ES module. Copy the one you need from typescript/dist/:

File For
ssenc.node.ts / ssenc.node.js Node.js ≥ 20 (password and ssh-agent)
ssenc.browser.ts / ssenc.browser.js browsers (password; ssh only with your own signer)
import { encrypt, decrypt, rekey, inspect } from "./ssenc.node.ts";

const key = { type: "password", password: "…" } as const;
const enc = await encrypt("host: db\nport: 5432\n", key);            // string (ASCII)
const next = await encrypt("host: db\nport: 6543\n", key, { previous: enc }); // one line differs
const plain = await decrypt(next, key);                               // Uint8Array
await encrypt(bytes, { type: "ssh", publicKey: pubFileContent }, { mode: "blob" });

Options of encrypt: mode ("lines", "blob", "auto"), preserveWhitespace, pad, chunk, kdf, previous, seal. Full reference, including ssh keys, errors and the browser build: docs/typescript.md.

Rust — crate in rust/: ssenc::encrypt, decrypt, rekey, inspect. Full reference: docs/rust.md.

Bash — source bash/ssenc.sh, then ssenc_encrypt, ssenc_decrypt, ssenc_rekey, ssenc_inspect (stdin → stdout). Needs bash ≥ 4 and OpenSSL ≥ 3.2.

What you should know before relying on it

  • Lines mode shows structure on purpose: number of lines, indentation, blank lines, rough line lengths, and which lines of one file are identical. Use blob mode when that is too much.
  • Lines mode does not notice removed or reordered lines unless --seal is used (and a sealed file conflicts on every concurrent git merge).
  • Stable diffs need the previous encrypted file (--previous, or simply writing to the same output file). Without it a new data key is made and every line changes.
  • The Bash implementation is slow and less private: roughly 15–20 ms per line, and openssl receives keys as command-line arguments, visible to other processes on the same machine while it runs. Prefer the Rust CLI on shared machines.
  • SSH mode: anyone who can make your agent sign can derive the key, so do not use it with agent forwarding to hosts you do not trust. ECDSA and hardware (sk-) keys are refused because their signatures are not repeatable. Add a password slot as a backup.
  • The cipher construction is built from standard primitives but is specific to this project and has not been independently audited.

Development

Node.js version is pinned in .tool-versions (asdf); CI uses the same file.

./install.sh      # dependencies of every part
./compile.sh      # build all implementations
./envverify.sh    # is everything needed present? reports every problem with a fix
./test.sh         # unit tests + cross matrix incl. browser, builds tests/out/report/index.html
./examples/examples.sh   # every usage example; they check their own results

Each of typescript/, rust/, bash/ has its own envverify.sh, install.sh, compile.sh, test.sh. All of them are also in the xx menu (xx.ts): xx test, xx rust compile, xx report open, …

Releasing

Only the Rust ssenc binary is released. The pushed tag is the version: ssenc --version of a released binary prints ssenc rust <tag>.

  1. add a section ## <new tag> to changelog.md: it becomes the top of the release page
  2. xx "release notes preview" <new tag> prints that page without releasing anything
  3. xx publish (or /bin/bash tag.sh [patch|minor|major]) creates and pushes the tag
  4. the pushed tag starts .github/workflows/test.yml: all tests on Linux and macOS, then the three binaries, SHA256SUMS.txt and the GitHub release. Nothing is released when tests fail. That release is what ssenc --update installs

Tests encrypt every case with every participant (Rust, Bash, Node running the .ts, Node running the .js, and the browser build in headless Chromium), save the results to files, then decrypt every file with every participant. The ssh tests use a private throwaway ssh-agent with the test keys in tests/keys/; your own agent is never used.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages