SimpleOTA client main
Shared core of the SimpleOTA Arduino and ESP-IDF clients
Loading...
Searching...
No Matches
sota_manifest.h File Reference

The signed manifest: proof, from the project's own key, of which build number and which project an image belongs to. More...

Go to the source code of this file.

Macros

#define SOTA_MANIFEST_V1_MAGIC   "SimpleOTA-Manifest-v1"
 The first line of a version 1 manifest.
 

Enumerations

enum  sota_manifest_gate_t { SOTA_MANIFEST_SKIP , SOTA_MANIFEST_VERIFY , SOTA_MANIFEST_FAIL_CLOSED }
 What to do about an offer's manifest (see sota_manifest_gate()). More...
 

Functions

static sota_manifest_gate_t sota_manifest_gate (bool required, bool has_project, uint8_t num_keys, bool offer_has_manifest)
 Decide from the device's own settings, never from what the offer claims about itself.
 
bool sota_manifest_field_ok (const char *s)
 True for a project id or key id that can stand on a manifest line: no control characters, so no line break.
 
bool sota_manifest_feed (sota_sig_verifier_t *v, const char *project_id, const char *key_id, uint32_t build, const char *checksum)
 Feed a version 1 manifest's bytes to a verifier that sota_verifier_begin() has started with the manifest signature.
 

Detailed Description

The signed manifest: proof, from the project's own key, of which build number and which project an image belongs to.

The image signature covers the firmware bytes and nothing else, and the server assigns the build number after it was made. So a server that has been taken over could offer an old signed image under a higher number, or another project's image when two projects share a key, and the signature would still verify. The manifest closes that: once the server has said which build an upload became, the SimpleOTA CLI signs these bytes with the same key, on the developer's machine,

SimpleOTA-Manifest-v1\n
<project id: the project's UUID, lowercase with hyphens>\n
<signing key id>\n
<build number, decimal>\n
<sha256 of the image, 64 lowercase hex digits>\n

and the server hands the signature out with the offer. The device never parses a signed document. It writes the same lines from what it holds itself (its configured project id, the offer's key id, build number and checksum) and checks the signature over them. The download then has to match that checksum, as it always did.

Portable and host-tested (test/host/test_signing.c).

Macro Definition Documentation

◆ SOTA_MANIFEST_V1_MAGIC

#define SOTA_MANIFEST_V1_MAGIC   "SimpleOTA-Manifest-v1"

The first line of a version 1 manifest.

No firmware image starts with it (an ESP32 image starts with 0xE9), so neither signature can pass for the other.

Enumeration Type Documentation

◆ sota_manifest_gate_t

What to do about an offer's manifest (see sota_manifest_gate()).

Enumerator
SOTA_MANIFEST_SKIP 

Not checked: the image signature decides.

SOTA_MANIFEST_VERIFY 

Check it before the download.

SOTA_MANIFEST_FAIL_CLOSED 

Required, and absent or uncheckable: refuse.

Function Documentation

◆ sota_manifest_gate()

static sota_manifest_gate_t sota_manifest_gate ( bool  required,
bool  has_project,
uint8_t  num_keys,
bool  offer_has_manifest 
)
inlinestatic

Decide from the device's own settings, never from what the offer claims about itself.

A device that requires manifests refuses an offer without one, so a server cannot strip it. Any other device checks a manifest it is able to check (a project id is configured and a key pinned), which lets a fleet try its manifests before it starts to require them. That is no protection: a server can strip the manifest from such a device.

Parameters
requiredThe device requires a manifest.
has_projectA project id is configured.
num_keysPinned public keys.
offer_has_manifestThe offer carries a usable manifest signature.

◆ sota_manifest_field_ok()

bool sota_manifest_field_ok ( const char *  s)

True for a project id or key id that can stand on a manifest line: no control characters, so no line break.

Empty is fine.

◆ sota_manifest_feed()

bool sota_manifest_feed ( sota_sig_verifier_t *  v,
const char *  project_id,
const char *  key_id,
uint32_t  build,
const char *  checksum 
)

Feed a version 1 manifest's bytes to a verifier that sota_verifier_begin() has started with the manifest signature.

False, with nothing fed, when a field cannot be on a manifest line, the project or key id is empty, or the checksum is not 64 lowercase hex digits; the caller still ends the verifier.