|
SimpleOTA client v1.0.0
Shared core of the SimpleOTA Arduino and ESP-IDF clients
|
Ed25519 firmware-signature helpers for the SimpleOTA clients. More...
Go to the source code of this file.
Data Structures | |
| struct | sota_sig_verifier_t |
| A streaming signature check against each candidate key at once. More... | |
Macros | |
| #define | SOTA_VERIFIER_MAX_KEYS 2 |
| Streaming Ed25519 verifier over one firmware image, for up to two candidate public keys (key rotation windows). | |
Enumerations | |
| enum | sota_signed_gate_t { SOTA_GATE_SKIP , SOTA_GATE_VERIFY , SOTA_GATE_FAIL_CLOSED , SOTA_GATE_WARN_UNVERIFIED } |
| Outcome of the signed-firmware policy decision (see sota_signed_gate). More... | |
Functions | |
| sota_signed_gate_t | sota_signed_gate (bool device_reports_signed, uint8_t num_keys, bool offer_signed, bool offer_has_signature) |
| Decide how to handle a (possibly signed) offer, from device policy and the offer's own claims. | |
| bool | sota_parse_ed25519_public_key_pem (const char *pem, uint8_t out[32]) |
| Parse a PEM "BEGIN PUBLIC KEY" (SubjectPublicKeyInfo) Ed25519 key, the exact format the SimpleOTA dashboard and API hand out. | |
| bool | sota_decode_signature_b64 (const char *b64, uint8_t out[64]) |
| Decode a base64 Ed25519 signature (as sent in the OTA check response) into its raw 64 bytes. | |
| bool | sota_verifier_begin (sota_sig_verifier_t *v, const uint8_t sig[64], const uint8_t keys[][32], uint8_t num_keys) |
| Start checking sig against each of the candidate keys. | |
| void | sota_verifier_update (sota_sig_verifier_t *v, const uint8_t *data, size_t len) |
| Feed the next chunk of the image, in download order. | |
| bool | sota_verifier_final (sota_sig_verifier_t *v) |
Ed25519 firmware-signature helpers for the SimpleOTA clients.
Portable (no platform dependencies) so it can be unit-tested on a host machine with plain cc/g++; see test/host/test_signing.c.
The SimpleOTA server delivers, for artifacts uploaded with security_mode "signed", a base64 Ed25519 signature computed over the raw firmware bytes exactly as downloaded. The device pins the project's PUBLIC key (it is not a secret) and must verify the signature over the downloaded bytes BEFORE the new image is marked bootable.
Verification is incremental (Monocypher's streaming Ed25519 check) so the image never has to fit in RAM: the apply path feeds the same chunks it writes to the OTA partition.
| #define SOTA_VERIFIER_MAX_KEYS 2 |
Streaming Ed25519 verifier over one firmware image, for up to two candidate public keys (key rotation windows).
Runs one Monocypher incremental check context per candidate key; the signature is accepted if it verifies under ANY candidate. Contexts are a few hundred bytes each (embedded SHA-512 state); the whole struct is about 700 bytes, so the apply path allocates it on the heap rather than on a task stack next to the download buffer.
Usage: sota_verifier_begin() once, sota_verifier_update() per downloaded chunk, sota_verifier_final() once.
| enum sota_signed_gate_t |
Outcome of the signed-firmware policy decision (see sota_signed_gate).
| sota_signed_gate_t sota_signed_gate | ( | bool | device_reports_signed, |
| uint8_t | num_keys, | ||
| bool | offer_signed, | ||
| bool | offer_has_signature | ||
| ) |
Decide how to handle a (possibly signed) offer, from device policy and the offer's own claims.
Pure and host-testable.
The guard against stripped signatures lives here: a device that declares signed mode AND has a key pinned MUST see a usable signature, no matter what the offer claims. A compromised server or MITM that strips the security_mode / signature fields from the response therefore cannot silently downgrade the device to checksum-only flashing; it gets SOTA_GATE_FAIL_CLOSED. When the device is not enforcing (not in signed mode, or no key pinned), the offer's own declaration is trusted, which keeps basic-to-signed fleet migration flowing.
| device_reports_signed | Device is configured with security_mode "signed". |
| num_keys | Count of pinned public keys (0..2). |
| offer_signed | The offer's security_mode is "signed". |
| offer_has_signature | A usable (decoded, ed25519) signature is present. |
| bool sota_parse_ed25519_public_key_pem | ( | const char * | pem, |
| uint8_t | out[32] | ||
| ) |
Parse a PEM "BEGIN PUBLIC KEY" (SubjectPublicKeyInfo) Ed25519 key, the exact format the SimpleOTA dashboard and API hand out.
The DER inside an Ed25519 SPKI is fixed-size (44 bytes: a constant 12-byte header followed by the 32 raw key bytes), so no ASN.1 parser is needed.
| pem | Null-terminated PEM text (armor lines + base64 body). |
| out | Receives the raw 32-byte public key on success. |
out is untouched on failure. | bool sota_decode_signature_b64 | ( | const char * | b64, |
| uint8_t | out[64] | ||
| ) |
Decode a base64 Ed25519 signature (as sent in the OTA check response) into its raw 64 bytes.
| bool sota_verifier_begin | ( | sota_sig_verifier_t * | v, |
| const uint8_t | sig[64], | ||
| const uint8_t | keys[][32], | ||
| uint8_t | num_keys | ||
| ) |
Start checking sig against each of the candidate keys.
| v | Verifier state (zero-init not required; begin() resets it). |
| sig | Raw 64-byte signature from the OTA offer. |
| keys | Array of raw 32-byte public keys. |
| num_keys | 1..SOTA_VERIFIER_MAX_KEYS candidate keys (extra ignored). |
| bool sota_verifier_final | ( | sota_sig_verifier_t * | v | ) |