Files
MeshCore/src/helpers/ota/OtaVerify.h
T

44 lines
2.1 KiB
C++

#pragma once
#include "MotaContainer.h"
#include "SignerAllowlist.h"
#include "OtaStore.h"
// Full verification of a staged `.mota` (device-side: uses Ed25519 via mesh::Identity, so NOT compiled
// on the native host - the portable integrity checks live in MotaContainer and are unit-tested there).
namespace mesh {
namespace ota {
struct VerifyResult {
bool parsed = false; // container + manifest parsed
bool root_ok = false; // merkle_root recomputed from leaves[] matches
bool payload_ok = false; // every staged payload block hashes to its stored merkle leaf
bool image_ok = false; // full: sha2-256(payload)==image_hash; delta: deferred to apply (set true)
bool is_signed = false;
bool sig_ok = false; // Ed25519 signature valid for signer_pubkey
bool trusted = false; // signer_pubkey is in the allowlist
bool container_hash_ok = false; // normalized full-container SHA was produced from the verified stream
uint8_t container_hash[32] = {0}; // SHA256(container with approval bytes normalized to zero)
// Integrity holds (safe to keep/serve). For a signed image, the signature must also verify.
bool integrity_ok() const { return parsed && root_ok && payload_ok && image_ok && (!is_signed || sig_ok); }
// Eligible for AUTO-apply: integrity + signed by an allowlisted key (decision D2).
bool auto_appliable() const { return integrity_ok() && is_signed && sig_ok && trusted; }
};
VerifyResult ota_verify(const uint8_t* buf, uint32_t len, const SignerAllowlist& allow);
// Streaming verification for a persistent store that cannot expose one
// contiguous memory view (notably the MeshTower V2 SD-backed nRF52 store).
VerifyResult ota_verify(const OtaStore& store, const SignerAllowlist& allow);
// As above, but the store's manifest must be byte-identical to an already
// authenticated local copy. This binds removable-media payload verification
// to the exact signed anchors later written into an internal approval token.
VerifyResult ota_verify(const OtaStore& store, const SignerAllowlist& allow,
const uint8_t expected_manifest[MOTA_MFL]);
} // namespace ota
} // namespace mesh