Code: Crypto, tokens and certificates with Jennifer
Hashes, keys, tokens and certificates: the code
The programs behind the slides, for Jennifer 0.27.0. Most use only the hash and crypto libraries and the bundled totp, jwt, oauth and acme modules. seal.j uses the @deckyard/sealbox deck listed in deck.toml: run jvc install once in this folder to fill vendor/. Run everything from this folder. Every key and secret is a placeholder or is generated fresh on each run.
hashmac.j: a SHA-256 digest, an HMAC over a webhook body and a constant time comparison ("Hash, MAC, and a comparison that does not leak"). Run:jennifer run hashmac.jencrypt.j: XChaCha20-Poly1305 with a fresh nonce, a tampered box, an Ed25519 signature ("Encryption is authenticated, signatures are public"). Run:jennifer run encrypt.jpasswords.j: argon2id hashing, timing and verification ("Passwords: argon2id, never a digest"). Run:jennifer run passwords.jenrol.j: a TOTP secret, itsotpauth://URI and a QR code written toenrol.png("TOTP: enrolment is a URI and a QR code"). Run:jennifer run enrol.jverify2fa.j: a +/-1 step window and refusing a code a second time ("TOTP: a window, and no second use"). Run:jennifer run verify2fa.jjwt1.j: sign with Ed25519, thenverifyWitha policy ("JWT: sign, then verify against a policy"). Run:jennifer run jwt1.jjwt2.j:alg: none, algorithm confusion, a tampered token, all refused ("JWT: whatverifyWithrefuses"). Run:jennifer run jwt2.jmisuse.j: the"value"errors ofjwtandtotpfor bad parameters ("Errors and their kinds"). Run:jennifer run misuse.jauthsrv.j: a fake OAuth2 authorization server on127.0.0.1:9400, client credentials and authorization code with PKCE, rotating refresh tokens. It stands in for a real identity provider. Run:jennifer run authsrv.j &cc.j: the client credentials grant, and a wrong secret as anOAuthError("OAuth2: a service as itself"). Withauthsrv.jrunning:SHELF_CLIENT_SECRET=PLACEHOLDER-client-secret jennifer run cc.jpkce.j: authorization code with PKCE and a loopback redirect, refresh, reuse of an old refresh token refused, the token saved totoken.json("OAuth2: authorization code with PKCE", "OAuth2: refresh, rotation, and the token file"). Withauthsrv.jrunning:jennifer run pkce.jacme1.j: account, order, HTTP-01 challenge served on127.0.0.1:5002, finalize, andcert.pem/key.pemwritten owner-only ("ACME: account, order, challenge", "ACME: prove it, check it, finalize"). It creates its account keyaccount.pemon the first run. Needs pebble, see below:SSL_CERT_FILE=pebble/pebble-root.pem jennifer run acme1.jacme_wrong.j: the same program serving a wrong answer, ending inauthorization invalid("ACME: prove it, check it, finalize"). Run likeacme1.j.renew.j: reads the validity dates ofcert.pemwithasn1and says when to renew ("When to renew"). Run afteracme1.j:jennifer run renew.jseal.j: seal and open a secret bound to a row id with@deckyard/sealbox("Sealed secrets with@deckyard/sealbox"). Run:jvc install, thenjennifer run seal.jkeys.j: an owner-only key file check and key rotation bykid("Keys: owner-only files, ids, rotation").make-keys.shwrites the two placeholder keys intokeys/, the newer one readable by others on purpose. Run:./make-keys.sh, thenSHELF_KEY_DIR=keys jennifer run keys.j
pebble, the test CA
pebble/start.sh starts Let's Encrypt's test CA pebble 2.8.0 with pebble/pebble-config.json (directory on 127.0.0.1:14000, HTTP-01 challenges to port 5002, ninety-day certificates) and pebble-challtestsrv as its DNS server, which answers 127.0.0.1 for shelf.example.test. Both containers use host networking, because pebble must reach the challenge server on the host's loopback. The script also downloads pebble's throwaway test root into pebble/pebble-root.pem for SSL_CERT_FILE. Stop with docker rm -f academy-crypto-pebble academy-crypto-dns. No certificate or key file is shipped here; acme1.j creates its own.
| File | Size | |
|---|---|---|
| LICENSE | 899 B | raw |
| README.md | 4.0 KiB | raw |
| acme1.j | 2.5 KiB | raw |
| acme_wrong.j | 2.5 KiB | raw |
| authsrv.j | 3.8 KiB | raw |
| cc.j | 586 B | raw |
| deck.toml | 252 B | raw |
| encrypt.j | 1.0 KiB | raw |
| enrol.j | 481 B | raw |
| hashmac.j | 755 B | raw |
| jwt1.j | 701 B | raw |
| jwt2.j | 1.3 KiB | raw |
| keys.j | 1.1 KiB | raw |
| make-keys.sh | 409 B | raw |
| misuse.j | 712 B | raw |
| passwords.j | 925 B | raw |
| pebble/pebble-config.json | 492 B | raw |
| pebble/start.sh | 965 B | raw |
| pkce.j | 1.3 KiB | raw |
| renew.j | 1.1 KiB | raw |
| seal.j | 882 B | raw |
| verify2fa.j | 1.2 KiB | raw |