Repository navigation
feat(api): sign requests to the API of /dev/null - #22
Merged
Merged
Conversation
/dev/null's signed API (dev-null-sh/dev-null.sh#130) checks an SSHSIG of the timestamp, the nonce, the method, the path and query as sent, and the raw body, one a line. The nonce is 32 hexadecimal digits, drawn here from 16 random bytes the caller gives, so that tests stay deterministic. First step towards reading the log through the API instead of the cookie. 🤖 Généré avec Claude Code
/dev/null identifies a device of the signed API by the fingerprint of the ed25519 key its requests are signed with, an SSHSIG in the devnull-api namespace. hooks/device-key.sh creates such a key and signs a message read on stdin with ssh-keygen, the only tool the host offers for it. The private key comes in DEVNULL_KEY, never as an argument other processes could read, and lives in a file of its own, 0600, only while ssh-keygen reads it. tests/device_key_test.sh checks the signatures with the real ssh-keygen, as /dev/null does, and runs in CI and under the bash 3.2 of macOS. 🤖 Généré avec Claude Code
hooks/infrastructure/device-key.ts runs hooks/device-key.sh through the host's process runner to create the key of the device and to sign a message with it. It checks what the script prints: an ed25519 public key, a SHA256 fingerprint as /dev/null stores it, an OpenSSH private key, and a signature in base64 on one line. The private key goes in the environment of the script and the message on its stdin; the arguments name the command only. 🤖 Généré avec Claude Code
hooks/infrastructure/api.ts reads /api/v1 on dev-null.sh, each request signed as /dev/null checks it: X-Devnull-Timestamp in seconds, a nonce of its own and the SSHSIG of the message in X-SSH-Signature. It refuses a path it would not send as it signed it, or outside the API. It reads only: the API also takes commits, which the plugin sends through the official script alone. It tells a device that is not approved yet, and a limit of requests with how long to wait, from the other refusals. 🤖 Généré avec Claude Code
The API of /dev/null takes commits, deletions and follows from an approved device: the plugin reads it only, as it reads the web app, since commits go through the official script alone. The private key of the device is a secret like the session cookie: the plugin creates it, keeps it in its store and hands it to ssh-keygen only, through its environment; only signatures leave, for dev-null.sh. 🤖 Généré avec Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First of a stack of pull requests moving the log from the session cookie to the signed API of /dev/null (dev-null-sh/dev-null.sh#130), whose device approval dev-null-sh/dev-null.sh#585 proposes for terminals.
Changes
hooks/infrastructure/: builds the message a request is signed with (timestamp, nonce, method, path and query as sent, raw body)hooks/device-key.sh: creates the ed25519 key of the device and signs a message read on stdin withssh-keygen(SSHSIG,devnull-apinamespace); the private key comes inDEVNULL_KEY, never as an argument, and lives in a 0600 file only whilessh-keygenreads ithooks/infrastructure/device-key.ts: runs the script through$.process.runand checks what it printshooks/infrastructure/api.ts: reads/api/v1on dev-null.sh with signed requests; it reads only (commits go through the official script alone), and tells an unapproved device and a rate limit from the other refusalsNot yet
The state module (
deviceKeyOf/apiOf, store keydeviceKey) and the sign-in come with a later pull request: nothing reads the API yet.Tests
tests/device_key_test.shchecks the signatures with the realssh-keygen, as /dev/null does, in CI and under the bash 3.2 of macOS🤖 Generated with Claude Code
https://claude.ai/code/session_01Fh4vxQUEH5yYphfgVatQKF