SimpleOTA client main
Shared core of the SimpleOTA Arduino and ESP-IDF clients
Loading...
Searching...
No Matches
sota_signing.h
Go to the documentation of this file.
1
20#ifndef SOTA_SIGNING_H
21#define SOTA_SIGNING_H
22
23#include <stddef.h>
24#include <stdint.h>
25#include <stdbool.h>
26
33#ifdef SIMPLEOTA_DISABLE_SIGNED_UPDATES
34#define SOTA_SIGNED_UPDATES 0
35#else
37#define SOTA_SIGNED_UPDATES 1
38#include "monocypher-ed25519.h"
39#endif
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
52
71sota_signed_gate_t sota_signed_gate(bool device_reports_signed, uint8_t num_keys,
72 bool offer_signed, bool offer_has_signature);
73
85bool sota_parse_ed25519_public_key_pem(const char *pem, uint8_t out[32]);
86
92bool sota_decode_signature_b64(const char *b64, uint8_t out[64]);
93
107#define SOTA_VERIFIER_MAX_KEYS 2
108
109#if SOTA_SIGNED_UPDATES
110
112typedef struct {
113 crypto_check_ed25519_ctx ctx[SOTA_VERIFIER_MAX_KEYS];
114 uint8_t num_keys;
116
126bool sota_verifier_begin(sota_sig_verifier_t *v, const uint8_t sig[64],
127 const uint8_t keys[][32], uint8_t num_keys);
128
130void sota_verifier_update(sota_sig_verifier_t *v, const uint8_t *data, size_t len);
131
134
135#else /* !SOTA_SIGNED_UPDATES */
136
138typedef struct {
139 uint8_t num_keys;
141
143static inline bool sota_verifier_begin(sota_sig_verifier_t *v, const uint8_t sig[64],
144 const uint8_t keys[][32], uint8_t num_keys)
145{
146 (void)sig;
147 (void)keys;
148 (void)num_keys;
149 v->num_keys = 0;
150 return false;
151}
152
154static inline void sota_verifier_update(sota_sig_verifier_t *v, const uint8_t *data, size_t len)
155{
156 (void)v;
157 (void)data;
158 (void)len;
159}
160
162static inline bool sota_verifier_final(sota_sig_verifier_t *v)
163{
164 (void)v;
165 return false;
166}
167
168#endif /* SOTA_SIGNED_UPDATES */
169
170#ifdef __cplusplus
171}
172#endif
173
174#endif /* SOTA_SIGNING_H */
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 das...
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.
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_verifier_final(sota_sig_verifier_t *v)
#define SOTA_VERIFIER_MAX_KEYS
Streaming Ed25519 verifier over one firmware image, for up to two candidate public keys (key rotation...
Definition sota_signing.h:107
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.
sota_signed_gate_t
Outcome of the signed-firmware policy decision (see sota_signed_gate).
Definition sota_signing.h:46
@ SOTA_GATE_VERIFY
Verify the signature during download.
Definition sota_signing.h:48
@ SOTA_GATE_SKIP
Not a signed update; apply normally.
Definition sota_signing.h:47
@ SOTA_GATE_WARN_UNVERIFIED
Signed offer but no key to check it; apply + warn.
Definition sota_signing.h:50
@ SOTA_GATE_FAIL_CLOSED
A signature is required but absent/unusable; reject now.
Definition sota_signing.h:49
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.
A streaming signature check against each candidate key at once.
Definition sota_signing.h:112
uint8_t num_keys
Checks in use.
Definition sota_signing.h:114