pamoja-update
Signed firmware manifests, streaming image verification, and A/B slots that fall back on their own. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.
Install
pip install pamoja-update
from pamoja import update
This pulls in pamoja-native, the compiled engine, and pamoja-security. pip install pamoja is the whole framework in one package.
Example
The script the test suite runs, spliced here as it ran.
From bindings/python/guides/update.py:
from pamoja.core import PamojaError
from pamoja.security import DeviceIdentity
from pamoja.update import (
BootAction,
Manifest,
SlotState,
Updater,
image_digest,
sign_manifest,
verify_envelope,
)
# The publisher's key signs releases; devices in the field are anchored to its public half
# and will take firmware from nobody else.
publisher = DeviceIdentity.from_seed(bytes([7]) * 32)
vendor = bytes([0x0A]) * 16
device_class = bytes([0x0B]) * 16
# The release. A manifest says who the image is for, which slot it belongs in, how big it
# is and what it hashes to; nothing about the image itself is taken on trust.
image = b"firmware for a flow meter, version two"
manifest = Manifest(
sequence=2,
vendor_id=vendor,
class_id=device_class,
storage=1,
digest=image_digest(image),
size=len(image),
)
envelope = sign_manifest(manifest, publisher)
print(f"published sequence {manifest.sequence} in a {len(envelope)}-byte envelope")
# On the device. It checks the envelope against the key it was anchored to before it
# accepts a single byte of the image.
opened = verify_envelope(envelope, publisher.public_key)
print(f"accepted a release for slot {opened.storage}")
# It left the factory running sequence 1 from slot 0, so the release goes to the spare slot
# and the image it is running stays where it is.
fleet = Updater(vendor, device_class, publisher.public_key, 2, 4096)
fleet.provision(0, 1)
fleet.begin(envelope)
for at in range(0, len(image), 16):
fleet.write(image[at : at + 16])
print(f"staged {fleet.progress().written} of {len(image)} bytes")
slot = fleet.finish()
print(f"written to slot {slot}, leaving the running image alone")
# The first boot into a new image is a trial. It reverts on the next boot unless the device
# confirms that it came up, which is what makes a bad release survivable.
def said(decision):
if decision.action == BootAction.TRYING:
return f"slot {decision.slot} on trial"
if decision.action == BootAction.CONFIRMED:
return f"slot {decision.slot}, already confirmed"
return f"slot {decision.slot} never confirmed, so the device runs slot {decision.fallback} again"
decision = fleet.on_boot()
print(f"booting {said(decision)}")
fleet.confirm()
print(f"confirmed slot {slot} is now {fleet.slot_record(slot).state}")
# The same release offered again would take the device nowhere new, so it is refused as a
# rollback, and so would any older one.
try:
fleet.stage(envelope, image)
print("an old release was accepted, which should never happen")
except PamojaError as error:
print(f"old refused: {error}")
# The next release goes to the slot the device is not running, slot 0 now. An image damaged
# on the way still arrives in full, but it does not hash to what was signed.
upgrade = b"firmware for a flow meter, version three"
third = Manifest(
sequence=3,
vendor_id=vendor,
class_id=device_class,
storage=0,
digest=image_digest(upgrade),
size=len(upgrade),
)
release = sign_manifest(third, publisher)
damaged = bytes([upgrade[0] ^ 0xFF]) + upgrade[1:]
try:
fleet.stage(release, damaged)
print("a damaged image was accepted, which should never happen")
except PamojaError as error:
print(f"corrupt refused: {error}")
# The same release signed by a key this device is not anchored to gets nowhere.
impostor = DeviceIdentity.from_seed(bytes([90]) * 32)
try:
fleet.stage(sign_manifest(third, impostor), upgrade)
print("a forged release was accepted, which should never happen")
except PamojaError as error:
print(f"forged refused: {error}")
# The genuine release stages and boots on trial, but never confirms: the next boot fails it
# and goes back to the image that worked.
fleet.stage(release, upgrade)
trial = fleet.on_boot()
print(f"booting {said(trial)}, running sequence {third.sequence}")
after = fleet.on_boot()
print(f"reverted {said(after)}")
# A release that failed cannot be offered again, or a captured image could be replayed; the
# fix goes out as sequence 4.
try:
fleet.stage(release, upgrade)
print("a failed release was accepted again, which should never happen")
except PamojaError as error:
print(f"again refused: {error}")
The same capability in every language
| Language | Package | Reference |
|---|---|---|
| Rust | pamoja-update |
reference, docs.rs, install |
| TypeScript | @pamoja/update |
reference, install |
| Python | pamoja-update |
reference, install |
| C# | Pamoja.Update |
reference, install |
Documentation
pamoja.updatereference, every class and function in this module.- The Signed updates guide, with the same example in Rust, TypeScript, and C#.
- Every capability, and the install page.
License
MIT
Metadata
Release files for pamoja-update 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pamoja_update-0.2.1.tar.gz | 5.7 kB | Without provenance | Details for pamoja_update-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pamoja_update-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for pamoja_update-0.2.1-py3-none-any.whl |
Total release size: 12.2 kB
Release files / pamoja_update-0.2.1.tar.gz
| Download URL | pamoja_update-0.2.1.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
daefd8bc294dfb4a0755716207c6666fa100668a2f1352b99dd5cd4a7204675c
|
|
BLAKE2b-256 checksum How to use checksums |
315d04e9a8b3d0f631305b8964c10aef2dcc2d133a00486c9208269a2bbc66cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Release files / pamoja_update-0.2.1-py3-none-any.whl
| Download URL | pamoja_update-0.2.1-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e000a7b19206058b69e97a088752e3b59a8c993df7ff7dc4e48f487b21b30f8d
|
|
BLAKE2b-256 checksum How to use checksums |
6f7899a71a6a374f78a35e634f6f5dcb6166597555127b7feef1bccb2dd525c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Security for pamoja-update 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.