Skip to content

1bit OS updater: signed SHA256SUMS (tools/release_sign.py) + the release public key baked into the image - #3442

Merged
bong-water-water-bong merged 3 commits into
mainfrom
1bit/release-image-signing
Nov 24, 2026
Merged

bong-water-water-bong merged 3 commits into
mainfrom
1bit/release-image-signing

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

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

  • What is signed: 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.
  • The message: a fixed domain prefix "1bit-os release SHA256SUMS v1\n" + the exact SHA256SUMS bytes. A release signature can never be read as another document's: the NPU kernel manifests start npumanifest 2.
  • Asset: 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 .sig whose pub names another key, so a forged signature can't bring its own key.
  • Standard library only. It reuses 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's npu.sec form) 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.sh installs the tool too; its release-pub mount is a follow-up, since woof mode isn't the release path today.
  • Tests:
    • 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's SHA256SUMS.

Open decision (orchestrator): which key signs releases.

  • (a) Reuse the NPU release key npu-v2. No owner step. Domain separation makes the two signature kinds distinct, and npu.pub is already the release public key. My recommendation for now.
  • (b) A dedicated OS key, which needs an owner keygen step. Cleaner key separation; rotation is independent of the NPU sets.

🤖 Generated with Claude Code

bong-water-water-bong and others added 3 commits November 23, 2026 21:31
…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]>
@bong-water-water-bong
bong-water-water-bong enabled auto-merge (squash) November 24, 2026 01:34
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Key decided: option (a). Releases are signed with the existing NPU release key npu-v2. The signed message is domain-separated, so a release signature can't pass as an NPU manifest signature. The image bakes that key's public half via cut.sh RELEASE_PUB=<key dir>/npu.pub, and the private release-sign.sh already defaults to it. No owner keygen step. Nothing is signed with it yet; the first use is the next release's SHA256SUMS.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Downgrade / freeze: the signature does not bind the release identity. The signed message is DOMAIN + SHA256SUMS bytes. Unless SHA256SUMS itself names the release tag, anyone who can serve files to the box can pair an older, validly signed SHA256SUMS + .sig + image with whatever tag or "newer" label --check reads. 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> and channel <stable|test> lines into the signed message: in SHA256SUMS itself, or as extra domain lines;
    • (b) have 1bit-update refuse 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.

  2. Time-of-check / time-of-use on the image. verify-image hashes 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: verify and verify_image each read SHA256SUMS through _message, so the file is read twice. Reading it once and passing the bytes would remove that window.

  3. Non-canonical points are accepted. _decode masks off bit 255 but doesn't reject y >= 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 bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 signed RELEASE line;
  • verify takes --tag/--channel and refuses a mismatch;
  • U2 then refuses a signed tag that isn't newer than /etc/1bit/release-identity, keeping --rollback for 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

@bong-water-water-bong
bong-water-water-bong merged commit 91a4aa0 into main Nov 24, 2026
11 of 12 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/release-image-signing branch November 24, 2026 01:49
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Key Handling Security

The tool reads the Ed25519 seed key in place and never prints or writes it, which is good for security. However, the code does not explicitly enforce that the seed file is only readable by the owner (e.g., using os.chmod or similar) to prevent accidental exposure. This could be a concern if the tool is run in an environment where file permissions are not strictly enforced.

def _read_key(path, what):
    """A 32-byte key file: raw bytes, or one line of hex. Its bytes are returned and never echoed."""
    try:
        with open(path, "rb") as f:
            data = f.read(200)
    except OSError as e:
        _die("cannot read the %s key %s: %s" % (what, path, e.strerror))
    if len(data) == 32:
        return data
    try:
        text = data.decode("ascii").strip()
        if len(text) == 64:
            return bytes.fromhex(text)
    except (UnicodeDecodeError, ValueError):
        pass
    _die("the %s key %s is neither 32 raw bytes nor 64 hex characters" % (what, path))
Signature Verification Logic

The verify function checks that the signature's public key matches the expected one, but it does not validate that the public key is a valid Ed25519 public key. This could lead to a scenario where an invalid or malformed public key is accepted, potentially causing verification to pass incorrectly.

def verify(sums_path, sig_path, pub):
    """(True, key id) or (False, why)."""
    s, why = _parse_sig(sig_path)
    if s is None:
        return False, why
    if s["pub"] is not None and s["pub"] != pub:
        return False, "%s was signed by key %s (%s...), not by this release key (%s...)" % (
            sig_path, s["key"], s["pub"].hex()[:16], pub.hex()[:16])
    msg, _ = _message(sums_path)
    if not _ed.verify(pub, msg, s["sig"]):
        return False, "the signature in %s does not match %s: the file was changed, or signed by another key" % (
            sig_path, sums_path)
    return True, s["key"]

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review from cl-hyperloom (head 2c86271). I read tools/release_sign.py and the reused seal_manifest.py Ed25519; nothing run.

The design is sound:

  • the domain-separated message (1bit-os release SHA256SUMS v1\n + bytes);
  • signing the SUMS rather than the 9 GB image;
  • the baked key, with a .sig whose pub names another key refused;
  • seal_manifest.verify rejects s >= L, so the S half is not malleable.

One real issue: verify_image reads SHA256SUMS twice (time-of-check / time-of-use).

  • verify_image first calls verify(sums_path, sig_path, pub). That reads the file via _message(sums_path) and checks the signature over those bytes.
  • It then calls _message(sums_path) again and looks up the image's digest (_sums_entry) in the second read.
  • Anyone who can replace SHA256SUMS between the two reads (a download directory under /data, a second process, a slow or network filesystem) passes the signature check with the genuine file and then supplies a forged digest for the lookup. The image check then accepts any image whose hash they chose.
  • The fix is small: read the bytes once, verify the signature over those bytes, and parse the entry from the same bytes. For example, have verify() return the verified bytes, or take them as an argument.

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 1bit-update when it calls this.

Minor (RFC 8032 conformance, not a forgery): seal_manifest._decode masks the high bit but does not reject y >= p, nor x == 0 with the sign bit set (if _x_recover doesn't already). RFC 8032 section 5.1.3 says decoding fails in those cases. With a fixed baked public key this only admits non-canonical encodings of R. Since k hashes the raw R bytes, that is not a practical forgery, but rejecting them is two lines and keeps the verifier strictly to spec.

The rest (exit codes, .sig parsing bounded to 4 KiB, basename matching inside a signed list) looks right.

🤖 Generated with Claude Code

bong-water-water-bong pushed a commit that referenced this pull request Nov 24, 2026
…, 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]>
bong-water-water-bong added a commit that referenced this pull request Nov 24, 2026
…, 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]>
bong-water-water-bong added a commit that referenced this pull request Nov 24, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant