Skip to content
marrasenPublic

About

Split an encryption key across several people using SLIP-39 shares and age, so a threshold of them is needed to decrypt

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

escrowkit

Split an encryption key across several people, and allow a subset of them to decrypt.

The problem it solves

You have data that you want to store encrypted, and access in case of an emergency.

But how do you store the encryption key? This app uses established standards to split an encryption key into several parts, where a subset of them is enough to reconstruct the original key and decrypt the secrets.

For instance, you can split the encryption key into 5 parts, but allow combining only 2 of the parts into a working decryption key.

escrowkit gives you:

  • A public key to use for encryption that can't be used to read the data back.
  • A private key that only exists as a number of word lists, held by different people in different places.
  • Decrypting requires only a defined number (two or more) of those people to cooperate.
  • Losing one word list is therefore fine.

Using standard algorithms

escrowkit writes only standard artefacts — age v1 files and SLIP-39 shares.

Everything it produces can also be handled with the stock age and shamir tools. This app does not invent a new format.

RECOVERY.md is the step-by-step for doing exactly that, for when escrowkit is not available. Keep a copy of it with your encrypted files.

Install

go build -o escrowkit .

Or download a binary for your system from the releases page. Builds are published for Windows (amd64) and Linux (amd64, arm64, armv7), with a SHA256SUMS file to check them against:

sha256sum -c SHA256SUMS --ignore-missing

Quick start

# 1. Create a key and split it three ways (the default values)
escrowkit keygen -o pubkey.txt

# 2. Encrypt something to the public key (usually your system does this)
escrowkit encrypt -r "$(cat pubkey.txt)" -H label=web-01 -o web-01.age secrets.txt

# 3. Survey what you have, without needing any key
escrowkit verify .

# 4. Decrypt, with two custodians present
escrowkit open web-01.age

Commands

escrowkit keygen

Creates a key pair and splits the private key into shares. Each share is a list of words.

escrowkit keygen [-t N] [-n N] [-o FILE] [-qr DIR]
Flag Default Meaning
-t N 2 Threshold — how many shares are needed to decrypt.
-n N 3 Number of shares to produce in total.
-o FILE — Also write the public key to FILE. It is printed either way.
-qr DIR — Write one printable PNG per share into DIR.

The public key is not secret. It is what age uses to encrypt. Store each share in a way that suits you, but never in the same location (which would defeat the purpose).

The shares are the private key. Anyone who gathers enough of them can decrypt everything, so handle them the way you would handle the key itself.

Mind what you leave behind. keygen puts the words in your terminal scrollback and in any session log, -qr writes them to disk, and printing them sends them through a spooler that may keep a copy.

Generating shares on a machine that is offline, or kept apart from your normal network, is a sensible precaution. It removes the routes by which those leftovers could reach anyone else.

Printable share sheets

-qr DIR writes one A4 page per share, share-1-of-3.png and so on. Each page has the words numbered so a transcription can be checked one word at a time, a QR code holding the same words, and blank lines for who holds the sheet and where it is kept.

escrowkit keygen -t 2 -n 3 -qr ./sheets -o pubkey.txt

Example share sheet: numbered words, a QR code, and blank custody lines

The QR code contains the share text word list and nothing else.

This is the one command that puts share material on disk. The PNGs hold the words in the clear, and they all land in the same directory, so anything with read access to it has enough to rebuild the private key. Print them, delete the files, and keep the directory out of backups and off shared disks.

escrowkit check-share

Validates a single share on its own.

escrowkit check-share [the words...]

Takes the words as arguments, or prompts if you give none. Uses the checksum built into SLIP-39 to confirm the share is intact and correctly transcribed. One share can tell how many shares are required to produce the private key.

escrowkit pubkey

Rebuilds the public key from shares.

escrowkit pubkey [-shares FILE] [-expect PUBKEY]
Flag Meaning
-shares FILE Read shares from a file, one per line. Prompts if omitted.
-expect PUBKEY Compare against this public key. Exits non-zero if they differ.

escrowkit open

Decrypts a file.

escrowkit open [-shares FILE] [-o FILE] <encrypted-file>
Flag Meaning
-shares FILE Read shares from a file, one per line. Prompts if omitted.
-o FILE Write the plaintext here (mode 0600) instead of standard output.

When prompting, enter one share per line and press Enter on a blank line to finish. Input is echoed on purpose: a mistyped word among 33 is far easier to spot on screen than to debug afterwards.

Supplying more shares than the threshold is fine — duplicates and surplus are dropped. Plain SLIP-39 rejects extras, which is a poor fit for a recovery where everyone turns up.

escrowkit encrypt

Encrypts a file to a public key.

escrowkit encrypt -r PUBKEY [-H key=value ...] [-o FILE] [input-file]
Flag Meaning
-r PUBKEY Required. The public key to encrypt to (age1...).
-H key=value Add a plaintext header field. Repeatable.
-o FILE Write here instead of standard output.

Reads the named file, or standard input if none is given.

Header fields are optional, for example -H label=web-01 -H version=7. They are stored unencrypted, so put nothing sensitive in them.

escrowkit verify

Surveys a directory of encrypted files using their headers, nothing is decrypted.

escrowkit verify [-c FIELDS] [directory]
Flag Meaning
-c FIELDS Comma-separated header fields to show as columns. Defaults to every field found.

The directory defaults to the current one. Files with no readable header are flagged.

$ escrowkit verify -c label,version ./store
FILE            LABEL    VERSION
db-02.age       db-02    3
web-01.age      web-01   7

2 file(s).

escrowkit version

Prints the version. Set at build time with -ldflags "-X main.version=1.2.3".

File format

# escrowkit encrypted file
# label:   web-01
# version: 7
#
# HOW TO OPEN THIS FILE
#   with escrowkit   escrowkit open <this file>
#   with plain age   first delete every line starting with #, then run
#                    age -d -i <key file> <this file>
#
-----BEGIN AGE ENCRYPTED FILE-----
...
-----END AGE ENCRYPTED FILE-----

See RECOVERY.md for what this format means, and for how to decrypt a file without escrowkit using only the stock age and shamir tools.

Notes for maintainers

  • No passphrase. SLIP-39 supports one and it is a trap: like BIP-39, any passphrase yields a valid-looking secret, so a typo silently produces the wrong key instead of an error. The threshold is the access control.
  • 256-bit secrets only. An age X25519 key is exactly 32 bytes. SLIP-39's own default is 128-bit, which cannot be turned into an age key. If you drive the shamir CLI by hand, -s 256 is mandatory.
  • Bech32 is the only custom code here (key.go), converting between raw bytes and the AGE-SECRET-KEY-1… text form. No cryptography, and it is checked against the age tool's own output in the tests.
  • go-slip39 is v0.1.x with a single maintainer. It does ship the official SLIP-39 test vectors. Pin it, and keep the cross-implementation fixtures so we notice if it drifts. At ~1500 lines, owning a fork is a realistic fallback.
  • Not hardened against side-channel attacks, per that library's own README. Acceptable here: this runs occasionally, on a machine you control, with an operator present. It is why the writing side should only ever hold the public key and only ever encrypt.
  • CI must test against the other implementations, not just itself. The day our output stops being readable by stock age, the build should fail.
  • The QR tests run over fixed shares on purpose. gozxing, which reads the sheets back in the tests, fails on roughly 2% of valid QR codes; the same images decode correctly in OpenCV, so the codes are fine and the decoder is not. Random shares would therefore make CI flaky for a reason that has nothing to do with this program. Sweep random ones with ESCROWKIT_QR_STRESS=1 go test -run QRRandom -v.

Licence

escrowkit is MIT licensed, see LICENSE.

age is BSD-3-Clause. go-slip39 is MIT.

About

Split an encryption key across several people using SLIP-39 shares and age, so a threshold of them is needed to decrypt

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages