Repository navigation
1bit OS updater: signed SHA256SUMS (tools/release_sign.py) + the release public key baked into the image - #3442
Conversation
…ase public key baked into the image
OS-UPDATER item 3 (owner "go for it", 24 Nov): checksums alone are not enough for a self-updating OS. The release
flow signs SHA256SUMS with the release key and publishes SHA256SUMS.sig; the box verifies it against the public key
baked into its image BEFORE it trusts any digest, then checks the image's sha256 against the signed line.
- tools/release_sign.py (standard library only, RFC 8032 Ed25519 from tools/seal_manifest.py, which 1bit OS ships):
sign / verify / verify-image / pubkey / --self-test. The signature is over a domain prefix
("1bit-os release SHA256SUMS v1\n") + the exact SHA256SUMS bytes, never over the 9 GB image (Ed25519 signs the whole
message; the image is covered by its sha256 line, verified streamed). Seed read in place, raw 32 bytes (kmanifest's
npu.sec form) or hex; never printed. A .sig that names another public key is refused, so a forged signature
cannot bring its own key. Cross-checked: byte-identical signature to python-cryptography's Ed25519.
- cut.sh (BASE): installs tools/release_sign.py as /usr/lib/1bit/release_sign.py; RELEASE_PUB=<key> bakes the public
key as /etc/1bit/release-pub (hex). Without RELEASE_PUB it says the image carries no key (the updater will refuse).
container-build.sh installs the tool too (its release-pub mount is a follow-up).
- tests/release_sign_test.sh (ctest release_sign): self-test 10/10 + the CLI exit codes the updater relies on
(good 0; tampered image, changed SHA256SUMS, other key, missing .sig: 1). CI image, env -i, dash: ok.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n_self), as tool_selftest_wired_check asks Co-Authored-By: Claude Opus 5.5 <[email protected]>
…igure failed at the earlier line) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Key decided: option (a). Releases are signed with the existing NPU release key |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
Review from lane cl-flm. I read tools/release_sign.py and tools/seal_manifest.py's Ed25519 on the PR head; nothing was run.
The core is sound (COMMENT): verify rejects s >= L, _decode → _x_recover raises on a non-point and the verifier returns False on it, and the final check compares canonical encodings. The domain prefix stops cross-document reuse, and refusing a .sig whose pub names another key is right. Three issues, the first worth fixing before --latest relies on it:
-
Downgrade / freeze: the signature does not bind the release identity. The signed message is
DOMAIN + SHA256SUMS bytes. UnlessSHA256SUMSitself names the release tag, anyone who can serve files to the box can pair an older, validly signedSHA256SUMS+.sig+ image with whatever tag or "newer" label--checkreads. A mirror, a captive proxy, or a compromised release asset store would do. The box then verifies OK and installs an old image. That old image may carry a fixed vulnerability (the box kernel CVE note, for example). Two cheap fixes:- (a) put
tag <release tag>andchannel <stable|test>lines into the signed message: inSHA256SUMSitself, or as extra domain lines; - (b) have
1bit-updaterefuse a verified release whose signed tag is not greater than the running/etc/1bit/release-identity, unless the user passes--allow-downgrade.
Together they make "newer" a signed fact rather than a label.
- (a) put
-
Time-of-check / time-of-use on the image.
verify-imagehashes the file, returns OK, and the installer then reads the same path again to write the slot. Whatever process could write that path between the two reads swaps the bytes after verification, for example another user's job if the download dir is shared, or a slow download still in progress. The robust order is to hash the exact bytes being written as they are copied, and to fail the slot write if the digest differs at the end. The alternative is to copy into a root-only staging dir first and verify the copy. A smaller one of the same kind:verifyandverify_imageeach readSHA256SUMSthrough_message, so the file is read twice. Reading it once and passing the bytes would remove that window. -
Non-canonical points are accepted.
_decodemasks off bit 255 but doesn't rejecty >= p. RFC 8032 §5.1.3 says to reject that. It isn't exploitable for forgery with a fixed baked key, but it makes the encoding malleable. A strict decoder costs one comparison.
The design choices in the body (sign SHA256SUMS, stream the image hash, standard library only, cross-checked against python-cryptography) are good.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
CHANGES (cl-kernel, comment-only review). The design is right: sign SUMS with a domain prefix, pin the given key, refuse a .sig bringing its own pub, stream the image. The crypto core holds: seal_manifest.verify rejects S ≥ L and undecodable points, cofactorless as RFC 8032 allows. --self-test passes, and so does tests/release_sign_test.sh.
Two findings, both cheapest to fix before the first real signature, since the second changes the signed format:
1. TOCTOU in verify_image (measured). verify() checks the signature over one read of SHA256SUMS. Then verify_image calls _message(sums_path) again and takes the image digest from that second, unverified read. Probe on ryzen: I wrapped verify, swapped SHA256SUMS to another digest and the image to matching other bytes right after the signature check. Result: verify_image returned (True, 'os.img matches the signed SHA256SUMS (key k)') for an image the signature never covered. Fix: verify() returns the exact bytes it verified, and verify_image parses those, with no second open. A self-test row for this needs the same hook I used.
2. Nothing binds a signature to a release, so rollback and channel confusion are possible. The message is DOMAIN + SUMS, and SUMS names only files. Any old signed SUMS + image verifies forever. #3441 picks 'newer' from GitHub's unsigned tag_name. Anyone who can upload release assets (a leaked token, a compromised account, a mirror) can re-publish v2026.47's signed pair under a tag v2026.60. U2 would then install a known-vulnerable image with a valid signature. The same goes for a test image served as stable. Fix, in the format while it's still free:
- sign the tag and channel:
DOMAIN + b"tag v2026.49\nchannel stable\n" + SUMS, or require SUMS to list a signedRELEASEline; verifytakes--tag/--channeland refuses a mismatch;- U2 then refuses a signed tag that isn't newer than
/etc/1bit/release-identity, keeping--rollbackfor the deliberate case. It should also never take 'newer' from anything outside the signature.
On the key question (a) vs (b): (a) is cryptographically sound only if each verifier checks its own prefix. This tool checks 1bit-os release…. The NPU manifest verifier must reject anything that doesn't start npumanifest 2, and I couldn't check that side; it's in the private repo. Even so, I'd lean (b): an OS key lets you rotate after a leak without re-signing every NPU set, and a compromise of the NPU signing host doesn't become an OS-install compromise. That's the orchestrator's call.
🤖 Generated with Claude Code
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
Review from cl-hyperloom (head 2c86271). I read The design is sound:
One real issue:
The updater side has the same shape for the image: it should install from the bytes it hashed, e.g. hash while copying into the destination slot, or hash the already-copied slot, rather than hash a path and then install from the path again. Worth a line in Minor (RFC 8032 conformance, not a forgery): The rest (exit codes, 🤖 Generated with Claude Code |
…, then the same slot install (OS updater U2) Brief OS-UPDATER.md item 2, on top of U1 (#3441) and cl-buildenv's signing (#3442: tools/release_sign.py shipped as /usr/lib/1bit/release_sign.py, the release public key baked at /etc/1bit/release-pub; key = the NPU release key npu-v2). --latest (root, installed system, like an image install): - picks the channel's newest release (update_pick); not newer -> 'up to date', exit 0; no image asset, or no SHA256SUMS + SHA256SUMS.sig -> refused: only signed releases are installed; - free space first: about 8x the compressed image + 2 GiB in /data/updates, else refused before a byte moves; - downloads to /data/updates/<tag>/ (HTTPS only, also across GitHub's redirect; the image resumes with -C -; SHA256SUMS and its .sig always fresh); - update_verify: release_sign.py verify-image (the release key's signature over SHA256SUMS, then the image's streamed sha256 against its line); any refusal removes the download and installs nothing; no verifier or no public key in the image is a refusal too; - keeps the fetched release + one previous (update_prune), decompresses (zstd) and hands the .img to the existing install, which verifies the set's own SHA256SUMS and never touches the running slot; --rollback stays. --download-only stops after the verified download (the console and web UI install it later). tests/update_latest_test.sh (new, ctest update_latest): a throwaway key signs a fake release with release_sign.py; good -> verified; image or SHA256SUMS changed after signing, unsigned, another key's signature, no public key, no verifier -> refused (exit 2); prune keeps two. 8/8 under dash (env -i) and busybox ash. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, then the same slot install (OS updater U2) (#3444) Brief OS-UPDATER.md item 2, on top of U1 (#3441) and cl-buildenv's signing (#3442: tools/release_sign.py shipped as /usr/lib/1bit/release_sign.py, the release public key baked at /etc/1bit/release-pub; key = the NPU release key npu-v2). --latest (root, installed system, like an image install): - picks the channel's newest release (update_pick); not newer -> 'up to date', exit 0; no image asset, or no SHA256SUMS + SHA256SUMS.sig -> refused: only signed releases are installed; - free space first: about 8x the compressed image + 2 GiB in /data/updates, else refused before a byte moves; - downloads to /data/updates/<tag>/ (HTTPS only, also across GitHub's redirect; the image resumes with -C -; SHA256SUMS and its .sig always fresh); - update_verify: release_sign.py verify-image (the release key's signature over SHA256SUMS, then the image's streamed sha256 against its line); any refusal removes the download and installs nothing; no verifier or no public key in the image is a refusal too; - keeps the fetched release + one previous (update_prune), decompresses (zstd) and hands the .img to the existing install, which verifies the set's own SHA256SUMS and never touches the running slot; --rollback stays. --download-only stops after the verified download (the console and web UI install it later). tests/update_latest_test.sh (new, ctest update_latest): a throwaway key signs a fake release with release_sign.py; good -> verified; image or SHA256SUMS changed after signing, unsigned, another key's signature, no public key, no verifier -> refused (exit 2); prune keeps two. 8/8 under dash (env -i) and busybox ash. Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…d refuse a point with y >= p (security, #3442 review) (#3447) cl-hyperloom's review of #3442 (orchestrator: the updater must not ship without this): - verify_image read SHA256SUMS TWICE: verify() opened it to check the signature, then verify_image opened it again for the image's digest. A file swapped between the two reads passed with the attacker's digest under a genuine signature. Measured on main's code with an open() that serves the genuine signed bytes first and a forged digest after: the attacker's image is reported '... matches the signed SHA256SUMS', after 2 reads. Now _read_sums reads it ONCE (capped at 1 MiB + 1); verify_bytes checks the signature over those bytes and verify_image takes the digest from the same in-memory bytes. verify() is a thin wrapper. - seal_manifest._decode masked y to 255 bits but never refused y >= p: RFC 8032 5.1.3 says decoding fails, else one key or R has several encodings. It raises now (covers the public key and the signature's R). tests/release_sign_toctou_check.py (new, run by tests/release_sign_test.sh, ctest release_sign): the swap scenario (refused, SHA256SUMS read exactly once), y = p and y = p + 1 refused, a genuine signature still verifies: 5/5; the same check against main's code FAILs 4 (the attack passes). release_sign self-test, seal_manifest self-test, release_sign_test (dash + busybox ash) and update_latest_test: ok. Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
OS-UPDATER item 3 (cl-buildenv with cl-release): the release side of "images signed with our release key and verified on the box before install". This is the tool and the image half. cl-release's
1bit-update --latest(item 2) calls the verifier.Design
SHA256SUMS, not the 9 GB image. Ed25519 signs the whole message, so signing or verifying the image itself would read it into memory. The image is covered through its sha256 line, which the box checks streamed after the signature verifies."1bit-os release SHA256SUMS v1\n"+ the exactSHA256SUMSbytes. A release signature can never be read as another document's: the NPU kernel manifests startnpumanifest 2.SHA256SUMS.sig, four text lines (1bit-release-sig 1,key,pub,sig). The verifier uses the key it is given (the baked one) and refuses a.sigwhosepubnames another key, so a forged signature can't bring its own key.tools/seal_manifest.py's RFC 8032 Ed25519; 1bit OS ships python3 (checked in the rc1 image). Cross-checked: the signature is byte-identical to python-cryptography's Ed25519.Change
tools/release_sign.py:sign,verify,verify-image,pubkey,--self-test. The seed is read in place, as raw 32 bytes (kmanifest'snpu.secform) or hex, and is never printed or written.os/v3/puppy/cut.sh(BASE): ships it as/usr/lib/1bit/release_sign.py.RELEASE_PUB=<public key>bakes/etc/1bit/release-pub(hex); without it the cut says the image carries no key.container-build.shinstalls the tool too; itsrelease-pubmount is a follow-up, since woof mode isn't the release path today.release_sign_self: the tool's self-test, 10 rows (RFC key, tampered image, changed SUMS, other key, own-key forgery, junk.sig, unlisted image).release_sign(tests/release_sign_test.sh): the CLI exit codes the updater relies on, good = 0 and every refusal = 1. CI image,env -i, dash: ok.bash scripts/pre-pr-checks.sh --base origin/main: 17 green, 3 skipped.The private half (not in this repo):
ryzen:~/briefs/buildenv/release-sign.sh <release dir>signs with the key dir read in place, verifies with the public key only, then checks every listed image. Dry-run with a throwaway key: OK. The real key hasn't signed anything yet; the first use is the next release'sSHA256SUMS.Open decision (orchestrator): which key signs releases.
npu-v2. No owner step. Domain separation makes the two signature kinds distinct, andnpu.pubis already the release public key. My recommendation for now.🤖 Generated with Claude Code