mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-31 13:00:49 +00:00
Dash OTA dogfooding nits
This commit is contained in:
1 parent
73037880e6
commit
27459efc61
29 files changed
+2635
-1478
No files matched your search
+16
-9
@@ -64,15 +64,22 @@ bool mg_ota_flash_end(struct mg_flash *flash) {
|
||||
MG_DEBUG(("CRC: %x/%x, size: %lu/%lu, status: %s", s_crc32, crc32, s_size,
|
||||
size, ok ? "ok" : "fail"));
|
||||
#ifdef MG_OTA_PUBLIC_KEY
|
||||
if (ok && s_size > 64) {
|
||||
static const uint8_t s_pubkey[] = MG_OTA_PUBLIC_KEY;
|
||||
uint8_t hash[32];
|
||||
size_t fw_size = s_size - 64;
|
||||
mg_sha256(hash, (uint8_t *) base, fw_size);
|
||||
ok = mg_uecc_verify(s_pubkey, hash, sizeof(hash),
|
||||
(uint8_t *) base + fw_size,
|
||||
mg_uecc_secp256r1()) == 1;
|
||||
MG_INFO(("Signature: %s", ok ? "ok" : "fail"));
|
||||
if (ok) {
|
||||
bool signed_fw = s_size > 68 &&
|
||||
memcmp((uint8_t *) base + s_size - 4, "MGSG", 4) == 0;
|
||||
if (signed_fw) {
|
||||
static const uint8_t s_pubkey[] = MG_OTA_PUBLIC_KEY;
|
||||
uint8_t hash[32];
|
||||
size_t fw_size = s_size - 68; // strip 64-byte sig + 4-byte magic
|
||||
mg_sha256(hash, (uint8_t *) base, fw_size);
|
||||
ok = mg_uecc_verify(s_pubkey, hash, sizeof(hash),
|
||||
(uint8_t *) base + fw_size,
|
||||
mg_uecc_secp256r1()) == 1;
|
||||
MG_INFO(("Signature: %s", ok ? "ok" : "fail"));
|
||||
} else {
|
||||
ok = false;
|
||||
MG_ERROR(("Unsigned firmware rejected"));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
s_size = 0;
|
||||
|
||||
Reference in new issue
Block a user