Signed, bandwidth-efficient over-the-air software updates
README.md

uplink #

Signed, bandwidth-efficient over-the-air software updates.

Updating a satellite, an embedded board or a fleet endpoint means sending a new
release over a link that is slow, expensive or only up part of the time. The
device must refuse anything that is not signed or that is older than what it
runs, and it must never end up half updated. uplink packages an update as one
signed bundle and applies it on the far side of such a link. The ground side
signs a bundle from a set of per-partition images; the device verifies it
against pinned keys, refuses a version below its anti-rollback floor, and
reconstructs the images.

The bundle is a standard SUIT envelope, with no custom wrapper. Each partition
is a SUIT component, its bytes travel as a SUIT_Integrated-payload
authenticated by the component's suit-parameter-image-digest, and the
anti-rollback version is the manifest's sequence-number, so any SUIT tool can
parse and check it. The signature is a plain COSE_Sign1 whose algorithm follows
from the key. The device's signed health witness, the report it signs and
sends back after booting a release, is a SUIT_Report in a
COSE_Sign1. A sealed bundle carries each payload's key in a
SUIT_Encryption_Info of draft-ietf-suit-firmware-encryption: a
COSE_Encrypt, which carries one recipient structure per device key (RFC 9052,
section 5), whose recipients take the content key by AES Key Wrap, ES-DH or
ML-KEM. AES Key Wrap (RFC 3394) encrypts a content key under a pre-shared key,
ES-DH derives it from an elliptic-curve Diffie-Hellman exchange, and ML-KEM
(FIPS 203) is NIST's post-quantum key-encapsulation mechanism: the sender
derives a shared secret and a ciphertext from the device's public key, and
only the device can recover the secret. ML-KEM uses Private Use code points
until IANA assigns them. The manifest's shared sequence names the vendor and
class identifiers of the devices the release is for and checks both
(draft-ietf-suit-manifest-37 section 7.1), so a device refuses a bundle built
for other hardware, as RFC 9124 section 4.3 (REQ.SEC.COMPATIBLE)
requires. Bandwidth is saved by deduplicating whole images: the bundle
names every partition by its target digest but
carries bytes only for the partitions the device's store does not already hold,
so an unchanged partition crosses the link as a digest. A changed partition
whose precursor the store holds crosses as an RFC 3284 (VCDIFF)
delta, bound to the precursor's signed digest as RFC 9124 section
4.3.9 requires. SUIT standardises no delta codec, so the directive that decodes
it is a custom command from the Private Use range of the SUIT registries.

A partition names its target by digest and size, and an image the store
holds under that digest is signed from those two alone, its bytes never
read. So the ground signs a release whose images the device built or
already holds, the bundle a descriptor and a signature, as a build farm's
queue signs the environments its worker built.

uplink is both a library, parameterised over the content-addressed store, and
a command-line tool. It is responsible for moving trusted releases and nothing
else. Alongside it, uniboot builds
the images and is the only tool that writes image bytes to a medium, and
caravan decides which target
should run which release. One digest identifies a release across all three:
uniboot computes it at build time, uplink carries it, caravan asserts it and the
device reports it back.

Standards #

Layer Standard
Bundle and manifest SUIT: RFC 9019 (architecture), draft-ietf-suit-manifest-37 (manifest)
Release identity draft-ietf-suit-trust-domains, section 5.2.2 (the manifest digest as identity)
Signature COSE_Sign1: RFC 9052, Ed25519 (RFC 8032)

Security #

  • Trust anchors. A bundle verifies only when enough of the pinned public
    keys (the caller's threshold) sign it, and only with an authorised algorithm
    (Ed25519 by default, P-256, P-384 or P-521 on request). A foreign key, an
    unauthorised algorithm or any tampering fails verification.
  • Anti-rollback. receive refuses a bundle whose version is below the
    caller's floor, and Apply.apply refuses one below the floor the target
    itself stands on, read under the target's lock, which no argument can lower.
    Replaying an older, authentic bundle is therefore rejected.
  • Content addressing. Every payload is checked against its
    suit-parameter-image-digest on arrival, so a corrupted or substituted blob
    is rejected whatever the link did.
  • Atomic commit. A partition's precondition is its signed
    expected_current_digest, the SHA-256 of the image the device's active slot
    must already hold (the empty string sets no precondition). Nothing is
    committed unless every partition's precondition holds, and a target commits
    every image or none, so an update is never seen half applied. Applying the
    same bundle twice changes nothing.

Some limits apply. uplink has no transport: a bundle is self-contained, and
the link that carries it (CFDP, a file, HTTP) belongs to the caller and sits
outside the trust boundary. uplink does not sign what a device boots; a target
may commit an uplink release beneath a boot chain with its own trust anchor, as
uniboot.uplink does. A differential payload is applied against the precursor
the device's uplink store holds, in memory, so a device that keeps no store
receives every changed image whole. The directory target syncs every image and directory to the
device, using F_FULLFSYNC on macOS, where plain fsync only reaches the
drive's cache.

Installation #

This package is not yet in the public opam-repository. Add the overlay
repository, then install it:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install uplink

Usage #

Command line #

The ground signs a bundle from a key and image files for a vendor and class of
device; the device takes the bundle, a public key, a floor and its own vendor
and class, and publishes the verified images. Both commands read the identity
from --vendor-id and --class-id, or from UPLINK_VENDOR_ID and
UPLINK_CLASS_ID. --store
is a content-addressed directory used for deduplication by build and for
reassembly by apply.

# Ground: mint the release signing key (private key 0600, public key beside it)
$ uplink keygen -o release.pem
wrote release.pem and release.pub (ed25519)

# Ground: sign a bundle (anti-rollback sequence number 7)
$ uplink build --key release.pem --seq 7 --store ./cache \
    --vendor-id fa6b4a53-d5ad-5fdf-be9d-e663e4d41ffe \
    --class-id 1492af14-2569-5e48-bf42-9b2d51f2ab45 \
    --image root=root.squashfs --image app=app.squashfs -o update.bundle

# Anyone: check the signature and print the release it names
$ uplink verify --key release.pub update.bundle
signature OK; version 7
  root  7b4cfd28...
  app   5736f474...

# Device: verify, refuse anything below the floor, publish the images
$ uplink apply --key release.pub --floor 5 --store ./cache -o ./slot \
    --vendor-id fa6b4a53-d5ad-5fdf-be9d-e663e4d41ffe \
    --class-id 1492af14-2569-5e48-bf42-9b2d51f2ab45 update.bundle
$ cat ./slot/current/root

# Operator: prune old releases, keeping the current one and a rollback target
$ uplink gc -o ./slot --keep 2

apply -o DIR publishes each release as an immutable content-addressed
directory under DIR/releases/, named only once it is written and synced in
full, with DIR/current a symlink swapped by a single rename. It keeps every
release it publishes, and gc prunes them. Pruning is a separate command so
that an update never collects the release an operator is about to roll back to.
uplink --help lists every command and flag.

apply -o DIR is the reference target, used on the ground; a flight device does
not run it. There the same verified bundle is committed through a boot-slot
TARGET (uniboot.uplink), which stages the images into the inactive A/B slot
behind a trial boot and a monotonic anti-rollback floor.

Library #

The library is parameterised over the content-addressed store (the functor
argument), so the same code runs against Uplink.Memory_store in tests and the
OCI blob cache in production. Every store keeps the content-addressing contract:
put checks that the bytes hash to the digest and rejects a mismatch.

(* Uplink.Memory_store is the ready-made in-memory store, keyed by digest;
   Uplink.Make binds a store as an uplink handle. *)
module Store = Uplink.Make (Uplink.Memory_store)

(* The devices this release is for, and the identity a device matches it
   against: RFC 9562 UUIDs naming the vendor and the device class. *)
let identity =
  { Uplink.vendor_id = String.make 16 'v'; class_id = String.make 16 'c' }

(* Bind the store once; the handle packs bundles and reassembles them. *)
let up = Store.v (Uplink.Memory_store.v ())

(* Ground: sign a bundle for one partition at sequence number 7. The signer
   wraps a key held anywhere -- in process, or an OS keychain, TPM or HSM. *)
let build ~signer =
  let image = "the new root filesystem image" in
  Uplink.build up ~signer ~identity ~version:7L
    [ { Uplink.name = "root";
        source_size = 0;
        expected_current_digest = "";
        expected_target_digest = "";
        size = String.length image;
        payload = Uplink.reader_of_string image } ]

(* Device: authenticate against the pinned anchors -- any one of them here --
   refusing anything below the floor. *)
let receive ~keys bundle =
  Uplink.receive up ~keys ~threshold:1 ~floor:5L ~identity bundle

receive returns the verified release. Each partition carries a payload
reader that can be run more than once, which the caller drives to write the
image, so reconstruction follows the caller's own fail-closed rules (write, read
back, check the content address).

receive verifies; a TARGET is where the result lands. Apply takes the
release receive returned, checks each partition's precondition against what
the target currently serves, then commits the whole release atomically under
its content address. There are two steps so that a consumer can decide what to
do with a release (route it, hold it, refuse it) in between, on a release that
was authenticated once.

(* Commit onto a directory of releases. *)
module Apply = Uplink.Apply (Uplink_eio)

let apply ~store ~dir ~keys bundle =
  let ( let* ) = Result.bind in
  let* release = Uplink.receive store ~keys ~threshold:1 ~floor:5L ~identity bundle in
  let* () = Apply.apply (Uplink_eio.v ~keep:2 dir) release in
  Ok release

Two backends ship:

Target Storage A release is Serving it is
uplink.eio (Uplink_eio) POSIX directory a directory under releases/ a current symlink, swapped by one rename
uniboot.uplink (Uniboot_uplink) GPT block device blobs in a content-addressed store an A/B slot pinning the release's address

Both name a release by its content address: the SUIT manifest digest that
the envelope's authentication wrapper signs, which the standard already treats
as an identity. Deduplication does not change it. The signature and the content
address cover the manifest, which names each image by its SHA-256 digest and
size; the image bytes travel beside it as integrated payloads in the envelope
and are checked against those digests on arrival. Omitting an integrated payload
therefore changes only the envelope, so one 32-byte digest in an A/B slot stands
for a whole set of named images.

A target below a filesystem cannot make a commit final by writing it, since a
release that does not boot cannot be undone. Such a target commits on trial and
rolls back unless the system that came up calls confirm. A directory on a
working filesystem has nothing to confirm.

Descriptor-only signing #

A signing machine that holds no image bytes reads a release descriptor:
uplink sign --descriptor release.json --key signing.pem --vendor-id UUID --class-id UUID --output release.bundle. The JSON contains version and
images; each image names name, a lowercase hexadecimal SHA-256 digest,
and a nonnegative byte size. --algorithm is a repeatable allowlist,
defaulting to Ed25519. --max-descriptor-bytes bounds input before parsing
(default 16 MiB). The output is atomic and contains no integrated payload.
An empty images list signs removal of every image at the given version;
its logical release component still checks the recipient's vendor and class.

API #

See uplink.mli for the partition and release types,
Descriptor (what a release's manifest bytes decode to), the STORE interface
and Make (S : STORE), the TARGET interface with Apply (T : TARGET),
INSTALL_TARGET with Install, Memory_target, and Witness, the signed
health report a device sends back. The directory backend is
uplink_eio.mli; the block-device backend ships with
uniboot as uniboot.uplink.

Documentation #

Updating a secure OS from the ground up builds the
update protocol from first principles, for readers new to it.

Licence #

ISC License. See LICENSE.md for details.