S1 loader keys upgrade: moving a loader panel's boot image to hybrid signatures over the air
Status (2026-12-03): verified on the dev S1 and in CI; the byte-for-byte comparison is still to run. The boot
writer's new keys mode adds the hybrid verifier, the loader that requires both signatures, the frame config that loader
reads and the keyring to a loader image, and leaves every other byte as it was. Two runs on the dev S1 (What we tried,
3 and 4) found and then verified the four-file upgrade end to end, with the backup restored after each. CI's root
job ran the shell cases: 719 of 719. The byte-for-byte comparison with a fresh patch is written but couldn't run on the
development Mac, whose Docker engine hung twice that day.
Device: Aqara S1 Plus, firmware 4.5.80, a frame loader boot image (frame 1.0.0). Tools: Magisk v31.1 (magiskboot,
arm64 on the host, armeabi-v7a on the panel), frame-agent/verify/build.sh --pq (the hybrid verifier, sha256
3f94b6aa…3ce1), the repo's patch-boot-magisk.sh and patch-ramdisk.sh.
Question
#1430 step 4: every S1 that runs the frame loader trusts one Ed25519 key, baked into its boot image. For the
post-quantum signature to protect a panel, its boot image needs new files: the hybrid verifier, the keyring
(frame-agent/glassworks_bundle.keys) and a loader that calls glassworks_verify --hybrid, plus the frame config that
loader reads (see 3 below). Can a signed frame bundle
put them there over the air, as the boot writer put the loader into 0.4.3 images (docs/research/s1-boot-writer.md),
without disturbing anything else in the image? And what does the panel need so that the bundle it already runs keeps
loading after the switch?
How we got here
The boot writer already does the dangerous part safely: two matching exports, a backup, refusing images it doesn't know, a write that is read back, the backup written back on a mismatch, one restart, and the agent's check after it. So the question was what changes between "0.4.3 image to loader image" and "loader image to hybrid loader image".
-
Full re-patch or a three-file swap. The 0.4.3 route reruns Magisk's
boot_patch.shand the FEL install's overlay. For a loader image only three overlay files change, so adding them withmagiskboot cpio addtouches the least and needs noboot_patch.shon a live panel. That only works if the result equals what a fresh install would write, so a later Kiln reinstall or the CLI agrees with the panel. The comparison below is built to answer that, and hasn't run yet. -
The loaded bundle would stop loading. The first dual-signed frame release (step 3) reaches a loader panel through today's loader, which copies only
manifest,manifest.sigand the listed files. So/data/glassworks/bundle/currenthas nomanifest.pqsig. After the boot rewrite, the new loader would refuse that bundle ("bad signature") and run the boot image's own copies: the frame version would drop to the boot image's, and the next update would need another restart. The signature can't travel inside the bundle (the manifest would have to list a file holding its own signature). The app has it, though: the zip it staged heldmanifest.pqsig. -
Where the app keeps it.
FrameInstallerdeletes the staging dir right before it restarts the panel, so the writer can't take the file fromfiles/frame/bundle-in/later. The app now copies the stagedmanifest.pqsigtofiles/frame/manifest.pqsigfirst, and deletes it when a bundle has none, so a kept signature always belongs to the bundle staged last. The writer takes it only withglassworks_verify --copy(kiosk-owned, no symlinks, one link, at most 16 KiB), checks it with the new verifier against the keyring and the loaded manifest, and only then puts it into the loaded bundle, before the write. Without a signature that checks, it refuses and writes nothing. Any app could plant a file there, but only a signature made with the release key passes. -
Why the bundle's own verifier proves it. The check runs the verifier binary that goes into the image, with the keyring that goes into the image, on the bundle the new loader will load. If any of the three is wrong (a classic verifier without
--hybrid, a keyring the release key isn't in, a signature of another bundle), the writer refuses before Magisk or boot are touched. -
Who starts it. On a loader panel the frame agent runs from the loaded bundle (
GW_BUNDLE,GW_SOURCE=bundle <version>). When that bundle carriesbootwriter/and the boot image has no keyring, the agent starts the writer in keys mode in the background, with its own state dir (/data/s1kiosk/radio/boot-upgrade), so the 0.4.3 route's backup and state stay apart. The boot copy of the agent and a developer override never start it. -
The frame config (found on the panel). The shared loader (
frame-agent/glassworks_loader.sh) reads the frame's settings fromglassworks_frame.shnext to it in the boot image and exits if it is missing. Images made before the shared loader, which means every S1 in the field, carry those settings inside their old loader instead and have noglassworks_frame.sh. The first panel run swapped three files, and the new loader then loggedmissing frame config /sbin/glassworks_frame.shon every start, so no frame service ran (3 under What we tried). The off-device tests had missed it because their loader runs from a dir that already held the config. The upgrade now adds four files, the S1'sglassworks_frame.shamong them (0644, as a fresh patch adds it), and a test checks that the fixture image, which lacks it like a real one, gets it.
What we tried
-
The swap against a fresh patch (2026-12-03, untested: the run hung pulling
arm64v8/ubuntu:22.04when the Mac's Docker engine stopped answering). The harness,frames/aqara-s1-plus/tools/root/keys-swap-proof.sh(host only, writes nothing to a device; the stock image and Magisk APK stay outside the repo), builds five images inarm64v8/ubuntu:22.04with Magisk v31.1's arm64magiskboot, from the stockboot-4.5.80.img:Image How A patch-ramdisk.shwith today's overlay: a loader image as panels run itB A with the three files added by magiskboot cpio addand repacked: the keys modeC patch-ramdisk.shof stock with the new overlay (hybrid verifier, new loader, keyring after the.publine)D the full re-patch of A with the new overlay E C with BOOTMODE=true, the panel's settingThe question is whether B equals C byte for byte (and D and E, as the 0.4.3 route's re-patch already did,
docs/research/s1-boot-writer.md). Expected, not shown:magiskbootwrites cpio entries sorted, with fixed metadata, and the repack recompresses the same way, so adding three entries should give what a patch with them in the list gives. Until it runs, the writer doesn't rely on it: it checks its own output against the old ramdisk plus the three files instead. -
The writer, off the panel (2026-12-03, verified in the armhf shell tests,
frames/aqara-s1-plus/tools/radio/test/run.sh). A pinned Alpine 3.22 container (OpenSSL 3.5) signs two throwaway frame bundles both ways; the stand-in Magisk APK and toy image format of the 0.4.3 writer's tests do the rest, with the real hybrid armhf verifier. About 45 cases: the whole flow, the carried signature loading under the hybrid loader (and refused without it), every refusal (no kept signature, another bundle's, a symlinked or foreign one, a keyring it isn't from, a verifier without--hybrid, no loaded bundle, an image without the loader or already hybrid, a ramdisk with more than the three files, exports that differ), a staged update it waits for, the readback mismatch and the forced one, a cut after the write, the agent's trigger and its check after the restart. Not yet run (the Docker engine hung on 2026-12-03); CI'srootjob is their first run. The app's half (FrameInstallerTest, keeping the signature and dropping a stale one) passed, 27 of 27. CI'srootjob then ran them (2026-12-03): after four fixes to the test harness (none in the writer), the S1 suite passed 718 of 718. -
The dev S1, run 1 (2026-12-03, verified; Aqara S1 Plus, app 0.9.4, frame 1.0.0 loaded, a dev image with adb root, radio mode
thread_router). The writer ran by hand as root with the environment the frame agent passes it (GWB_MODE=keys,GWB_FILESwith the writer, the loader and the published hybrid verifier,GWB_BOOTFILES=/sbin,GWB_CURRENT=/data/glassworks/bundle/current). Production keys sign only in CI, so the keyring was a test one: the production Ed25519 public key (which signed the loaded 1.0.0 bundle) with a throwaway SLH-DSA key that signed the loaded manifest, its signature put where the app keeps it. The official Magisk v31.1 APK went where the app downloads it.bootwas backed up first: two reads and the copy on the Mac all hashedd88098ec…5742.- Forced mismatch (switch made by root): written, read back "wrong", the backup written back and read back
d88098ec…, staterestored, no restart, the switch used up. 21 s. - The real write:
restarting, the new image8d126ce9…read back, one restart, booted in about 35 s. In/sbin: the hybrid verifier (3f94b6aa…, 0700), the loader (0700) and the keyring (0644). Dev su still worked, radio mode kept. But dmesg showedglassworks_loader: missing frame config /sbin/glassworks_frame.shand no frame service ran:sys.glassworks.bundle.stateandro.glassworks.frame.versionwere empty (3 under How we got here). - The undo: the backup written back with
dd conv=fsync, read backd88098ec…, the carried signature removed, a restart. The panel came back as before: frame 1.0.0ok, agent v5,thread_router, dev su.
-
The dev S1, run 2 (2026-12-03, verified; the same panel and setup, the four-file upgrade).
- The writer:
restarting, the new image09083917…read back, one restart, booted in about 40 s. In/sbin: the hybrid verifier, the loader, the keyring andglassworks_frame.sh, each byte for byte what the bundle carried. - The hybrid loader loaded the carried bundle:
sys.glassworks.bundle.stateok 1.0.0,ro.glassworks.frame.version1.0.0, the published stateok 1.0.0 1000000 -. The agent ran (contract v5) and the radio came back as a Thread router (thread_router: joined as router). Dev su still worked. - The boot image's loader,
glassworks_loader.sh check: the loaded bundle1.0.0 1000000; a root copy of it withoutmanifest.pqsigrefused (manifest.pqsig missing); one with amanifest.pqsigchanged by a byte refused (bad signature (not signed with both of the project's keys)). - The undo: the backup written back, read back
d88098ec…, the carried signature and the staged files removed, a restart. The panel came back exactly as before (frame 1.0.0ok, agent v5,thread_router, app 0.9.4, dev su).
- The writer:
Result
| Step | What the keys mode does | Evidence |
|---|---|---|
| Trigger | The frame agent of a loaded bundle that carries bootwriter/, while the boot image has no keyring. Never the boot copy or a developer override |
shell tests |
| Signature | Takes files/frame/manifest.pqsig with verify --copy and checks it with the new verifier and keyring against the loaded manifest, before Magisk or boot. Refuses a missing, symlinked, foreign or mismatched one |
shell tests, FrameInstallerTest |
| Image | Magisk-patched, with the loader, its verifier and glassworks.rc, and no keyring. One that has it already is left alone |
shell tests |
| Patch | magiskboot cpio add of the four files (verifier and loader 0700, frame config and keyring 0644, as patch-boot-magisk.sh), repacked. Refused unless the ramdisk read back is the old one plus exactly those four, and kernel, dtb and header are the panel's |
shell tests; verified on the dev S1 (run 2); the byte-for-byte comparison above (not yet run) |
| Carry | manifest.pqsig into the loaded bundle (root 0600) just before the write. Today's loader ignores it, so a restored backup still loads the bundle |
shell tests |
| Write | The writer's own: backup, readback, restore on a mismatch, forced-mismatch switch, one restart | shell tests |
| After | The agent checks the loader ran, the services are up, boot holds the image written, the radio mode kept, and the keyring is in the boot image. Its record goes to Manage's Frame loader row | shell tests |
Shipping: bootwriter-files.sh <dir> <hybrid verifier> stages the writer, the loader and the boot image's files,
plus the hybrid verifier and the keyring, both or neither (a verifier without --hybrid is refused).
frame-bundle.sh adds bootwriter/ when the release input holds the hybrid verifier, and release.yml puts the
pinned verify asset there only when it is the hybrid build. A 0.4.3 panel's writer then writes the hybrid loader
directly (the keyring line follows the .pub line, as in patch-boot-magisk.sh).
How to reproduce
- The byte-for-byte check:
frames/aqara-s1-plus/tools/root/keys-swap-proof.sh <repo> <stock boot.img> <Magisk-v31.1.apk> <out dir>(its header says what it touches). It needs the hybrid armhf verifier (frame-agent/verify/build.sh --pq --arch armhf) andbuild-verify.sh's output. - The off-device tests:
frames/aqara-s1-plus/tools/root/build-verify.sh && frame-agent/verify/build.sh --pq --arch armhf && frames/aqara-s1-plus/tools/radio/test/run.sh(CI'srootjob). - On the dev S1 (hard rule 5, owed): install a dual-signed frame bundle with
bootwriter/through the app, check/data/glassworks-pub/boot-writerand/data/s1kiosk/radio/boot-upgrade/statethroughneed-magisk,checkingandrestarting, the forced mismatch first (touch /data/s1kiosk/radio/boot-upgrade/force-readback-mismatchas root), then the real write, the restart,ro.glassworks.frame.versionunchanged,sys.glassworks.bundle.stateok, and the agent'sok. The undo writesbackup.imgback the same way and reads it back.
Open questions
- The whole path through the app (a frame update installed from Home Assistant, the agent starting the writer, the
app's kept signature) needs a bundle signed with the production keys, so it can only run once a dual-signed release
exists. Runs 1 and 2 ran the writer by hand with the environment the agent passes it; the agent's trigger and the
app's half are covered off-device (the S1 suite and
FrameInstallerTest). - The byte-for-byte comparison (attempt 1) and a local run of the shell cases, once Docker works on the Mac.
- A panel that installed the first dual-signed release with an app from before this change has no kept signature: the writer refuses, and the next frame update (installed by the new app) brings the upgrade again.