Back to Blog
46 min Copy as Markdown
Part 5 / 6 · Kleidos firmware: six decisions under hard constraints

Authenticated OTA on ESP32: which check can still say no?

On an open Kleidos build an OTA image is authenticated but not signed, so its board and version checks stop mistakes rather than attackers; only the hardened build's signature makes them binding, and its eFuse version floor, fixed at 1, blocks no downgrade yet.

Cover image for Authenticated OTA on ESP32: which check can still say no?

The previous post in this series ended at a closed door. Once a hardened ESP32-S3 has burned its eFuses in RELEASE mode, the serial download mode is gone, and the only way a new image can reach the chip is over the air. This post is about that way in, as it works today on a hardware password manager I’m building (not yet released): how an image gets from a browser into a flash slot, which checks can still refuse it, and what the board does when the new image turns out to be bad.

The usual way to describe this kind of feature is a list of check marks: authenticated upload, version check, signature, automatic rollback. All four exist in Kleidos. The more useful question is which of them can still say no in a given situation, because each one covers a different failure, and on an open build two of them are reading data the uploader wrote. My thesis is short: an OTA path is only as strong as the weakest check that can still refuse, and on an open build those checks protect against mistakes, not attackers. The signature, the version floor and the bootloader’s rollback each cover a different failure, and today two of them have gaps I can name.

As in the last post, I’ve kept the evidence labels from the bench. Some figures were measured, and I give the board, the image, the network and the date. Some behavior I read from code but did not run, in ESP-IDF 6.0.3 or in the firmware. One check is host-tested only. A set of hardened tests is designed, with no recorded result. One failure mode is predicted from the code. And a long list has not been observed by anyone: no OTA has ever run on a hardened build, no RELEASE image has ever booted, and no OTA has been measured over the device’s own access point. Every OTA I can give you a number for ran on an M5StickC Plus2 with an open debug build, over the lab network.

TL;DR: what can still refuse an OTA image on Kleidos

5 key points
  • An OTA update is app-only: it writes the inactive app slot and otadata, never the bootloader, the partition table, NVS or the vault. It enters through one route, POST /update, on the device’s own access point, behind a per-session upload password shown only on the device’s screen and, since 2026-11-20, a session token that proves the request came from the device’s own page.
  • Before the boot slot moves, the firmware compares the candidate’s descriptor with the running image’s: first the board identity (project_name), then a strict major.minor.patch version that may not go down. On an open build the uploader wrote both fields and nothing signs them, so these checks stop mistakes, not someone who already has the password.
  • Only the hardened _secure build verifies an RSA-3072 signature when the upload closes and again on every boot. Its eFuse anti-rollback floor exists but is fixed at 1, so it blocks no downgrade yet; on the S3 it can be raised 16 times in the chip’s life.
  • The ESP-IDF 6.0.3 bootloader rolls back on any reboot while the new image is unconfirmed: there is no timer. Kleidos confirms early, before the vault is mounted and before the main loop joins the task watchdog, so a hang without a panic in that window does not revert by itself, and a failure after confirmation does not revert at all.
  • Measured: about 37 s per update (2026-10-06) and 58 to 62 s with a full vault (2026-11-14), both on an M5StickC Plus2 with an open debug build over the lab network. No OTA has run on a hardened build, and none has been measured over the device’s own access point.
Quick glossary (if ESP32 updates aren't your background)
  • OTA (over-the-air update): installing new firmware through a network connection instead of a cable.
  • App slot · ota_0 · ota_1: the two flash partitions that each hold a complete application image. One runs; the other receives the update.
  • otadata: a small partition that records which slot to boot and the state of each slot’s image.
  • App descriptor (esp_app_desc_t): a fixed structure inside every ESP-IDF image that carries, among other things, the project name, the version string and a security version.
  • Open build · _secure build: Kleidos’s builds without Secure Boot and flash encryption (the base, _release and _debug environments), and the hardened ones from the previous post.
  • Signature · integrity hash: a signature proves who made an image; a hash appended to the image only proves it was not corrupted on the way.
  • PENDING_VERIFY: the state of a new image on its first boot, before the application has confirmed that it works.
  • Anti-rollback · SECURE_VERSION: an eFuse counter that the bootloader compares with each image’s security version, refusing lower ones.
  • Basic-Auth: HTTP’s simplest login: a user name and password the browser remembers and sends again with each request to the same site.
  • CSRF (cross-site request forgery): a page from one site making your browser send a request to another site, with the credentials the browser holds for that other site.
  • CORS preflight: the permission check a browser runs before it sends certain cross-site requests, for example any that carries a custom header.
  • SoftAP: the Wi-Fi access point the device itself brings up.

What does an OTA update on Kleidos actually replace?

Less than people expect, and that is deliberate. An OTA update in Kleidos writes the inactive app slot and otadata, and nothing else. It never writes the bootloader, the partition table, NVS or the vault, which is a LittleFS filesystem in its own partition. That is also why “the vault survives an update” is a property of the layout rather than a promise of the update code: the update has no path to those sectors.

This is the open 8 MB table, used by the M5StickS3, the Cardputer ADV and the M5StickC Plus2 in their base and _release environments (and by the M5StickC Plus2’s debug environments; the other debug builds use a debug variant of it):

variants/partitions_8mb.csv (data rows) text
# Name,   Type, SubType,  Offset,   Size
nvs,      data, nvs,      0x9000,   0x4000
nvs_key,  data, nvs_keys, 0xD000,   0x1000
otadata,  data, ota,      0xE000,   0x2000
app0,     app,  ota_0,    0x10000,  0x2C0000
app1,     app,  ota_1,    0x2D0000, 0x2C0000
littlefs, data, littlefs, 0x590000, 0x260000

The two slots are the same size, 2,816 KB each, so whichever one is running, the other can hold the next image. The hardened variant from the previous post keeps that property while it moves things: its table sits at 0x10000 because the signed bootloader does not fit below 0x8000, its slots start at 0x20000 and 0x2E0000, and its vault carries the encrypted flag. The 16 MB boards (CoreS3 SE, T-Deck and Core2 v1.3) have two slots of 4,544 KB and a 7 MB vault.

How much room is left matters more than it looks, because the slot size is fixed by the table and the table can’t change over the air. On 2026-11-28 the Cardputer ADV’s base image was 2,308,800 bytes, 80.1% of its slot. An earlier size rule from 2026-08-19 no longer holds.

Two consequences follow from “app-only”, and both are limits rather than features:

  • A release that changes the partition table can’t be delivered by OTA. It goes by cable, once, and the firmware’s versioning policy treats a table change as an incompatible one.
  • The bootloader is never updated over the air. On a hardened board it isn’t rewritten by a later cable upload either: esptool refuses to write below 0x8000 without --force once Secure Boot is active, and on the S3 the upload guard from the previous post refuses earlier.

The 4 MB boards have no OTA at all

Three boards carry only 4 MB of flash: the M5StickC Plus 1.1, the M5StickC Plus SE and the M5Stack CoreInk. They build with NO_OTA=1 and a table with a single factory slot of 2,688 KB and a 1,344 KB vault: there is no second slot to update into. otadata exists there but nothing uses it. The admin portal doesn’t even register /update on those boards; the comment in the code explains why: otherwise the owner would upload a whole image only to get a 500. They are updated by reflashing the full image over USB, and the vault survives that as long as the layout doesn’t change. A browser-based installer is parked until there are public releases; today they are flashed with PlatformIO or esptool.


How does an image get from the browser into the inactive slot?

Thirteen steps, from the owner unlocking the device to the new image deciding whether it is healthy. Steps 5 to 10 are where every check lives, and any failure in them aborts the write session and leaves the boot slot where it was.

Most of the steps are short; a few deserve a closer look.

Steps 1 and 2: the device brings up its own network. The owner unlocks with the PIN and enters admin mode (on the Sticks, from the “WiFi Admin” entry on the vault’s settings page). The device starts its access point and the admin portal, and derives a password for this session only:

otaPassword = hex( HMAC-SHA256(
    key = vaultKey,
    msg = "kleidos-ota-v1" || sessionToken
)[0..12) )

That is 12 bytes, 96 bits, written as 24 hexadecimal characters. It changes every session, because the session token does, and it can’t be computed without the vault key, which the device holds only while it is unlocked. The screen shows it as admin: followed by the password, split across two half-lines.

Step 4: refusals that cost nothing. Before the handler opens anything, it answers 503 if the Bluetooth stack is not fully off (more on that below), 400 if the body is empty and 413 if Content-Length is larger than the slot it would write. A request that fails here never erases a sector.

Step 5: one sector at a time. The update session picks the inactive slot, checks the size again, and opens it in sequential mode:

src/platform/storage/ota.cpp (trimmed) cpp
esp_ota_begin(
    partition,
    OTA_WITH_SEQUENTIAL_WRITES,
    &handle );

With OTA_WITH_SEQUENTIAL_WRITES, ESP-IDF erases each sector as the data reaches it instead of erasing the whole slot up front. That flag is there because of a measured failure. On 2026-10-06, on an M5StickC Plus2 with a debug build, erasing the 2.4 MB in one go blocked long enough that the loop’s watchdog fired about 5 seconds after the upload started, and the board rebooted on every attempt. Espressif’s OTA tuning notes describe the same trade from the other side: bulk erase can be faster, but “If the partition to be erased is too large, task watchdog could be triggered.”

The same step has a refusal inside ESP-IDF that is easy to miss. With rollback enabled, esp_ota_begin() won’t start a new update while the running image is itself still unconfirmed:

app_update/esp_ota_ops.c, esp_ota_begin(), ESP-IDF v6.0.3 (logging removed) c
#ifdef CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE
esp_ota_img_states_t ota_state_running_part;
if (esp_ota_get_state_partition(running_partition,
                                &ota_state_running_part) == ESP_OK) {
    if (ota_state_running_part == ESP_OTA_IMG_PENDING_VERIFY) {
        return ESP_ERR_OTA_ROLLBACK_INVALID_STATE;
    }
}
#endif

In Kleidos you would only meet that error if confirmation had failed, because the firmware confirms a new image within the first moments of its first boot.

Step 6: the body is never stored whole. The /update route is registered without a body buffer, and the handler reads the request in 4 KB chunks into a heap buffer (allocated without exceptions, zeroed at the end) and writes each chunk straight to the slot. Eight consecutive receive timeouts abort the upload. On the very first chunk, ESP-IDF checks one byte:

app_update/esp_ota_ops.c, esp_ota_write(), ESP-IDF v6.0.3 (trimmed) c
if (it->wrote_size == 0 && it->partial_bytes == 0 && size > 0) {
    if (it->partition.final->type == ESP_PARTITION_TYPE_APP ||
        it->partition.final->type == ESP_PARTITION_TYPE_BOOTLOADER) {
        if (data_bytes[0] != ESP_IMAGE_HEADER_MAGIC) {
            ESP_LOGE(TAG, "OTA image has invalid magic byte "
                          "(expected 0xE9, saw 0x%02x)", data_bytes[0]);
            return ESP_ERR_OTA_VALIDATE_FAILED;
        }

Keep that check in mind; it explains a bug further down.

Steps 7 to 10: the checks. esp_ota_end() verifies the image (its structure and its hash, plus the signature on a hardened build). Then the firmware’s own two checks run, board identity and version, and only if both pass does it call esp_ota_set_boot_partition(), which verifies the image again and, on a RELEASE build, compares its security version with the eFuse. Since 2026-11-21 these calls run under the lock the firmware uses for the crypto hardware. Each check gets its own section below.

Steps 11 to 13: the reboot and the decision. The device answers 200, stores two markers in NVS (attempted = true and the version it is running now), shows the result for 2 seconds and reboots: the portal goes down, keys are wiped and esp_restart() runs. The bootloader moves the new slot from NEW to PENDING_VERIFY and boots it once. Early in setup(), markFirmwareValid() decides what that boot means. That decision is the subject of the rollback section.


Who is allowed to push an image?

Three layers, and it helps to be precise about which of them is a secret.

  1. The device’s own network. Outside debug builds, the portal only exists on the access point the device brings up in admin mode, with a password the screen shows. The public threat model describes it as WPA3 with protected management frames and one client.
  2. The upload password. GET /update (the minimal update page) and POST /update both require Basic-Auth with the per-session password from step 2, compared in constant time. The browser sees the challenge as WWW-Authenticate: Basic realm="Kleidos OTA".
  3. The session token. Since 2026-11-20, POST /update also requires the session token in an X-Session-Token header. The update page gets it from GET /api/init.

In front of all three sits a rate limiter per client address, shared by /api/ and /update: 80 requests per 60 seconds, and 30 per 60 seconds for /api/init. Over the limit, the device answers 429 before it looks at any credential. The update page itself carries a Content Security Policy that pins its single script by hash and allows connections only to its own origin. The HTTP server is ESP-IDF’s esp_http_server, with an 8 KB task stack, three sockets and a 3-second receive wait, and no Arduino HTTP or OTA library is involved.

One upload request, and the answers this post names

POST /update

  • Authorization: Basic admin + the per-session password from the screen
  • X-Session-Token: the token from GET /api/init (required since 2026-11-20)
  • Content-Type: application/octet-stream
the raw image; its first byte must be 0xE9
  1. Over the rate limit Status 429 Too Many Requests

    Sent before any credential is looked at.

  2. Bluetooth stack not fully off Status 503 Service Unavailable

    BLE active

    Nothing is opened.

  3. Empty body Status 400 Bad Request

    Nothing is opened.

  4. Content-Length larger than the slot Status 413 Content Too Large

    No sector is erased.

  5. A check in steps 5 to 10 fails Status 500 Internal Server Error

    OTA failed

    The session is aborted and the boot slot doesn't move.

  6. Every check passes Status 200 OK Update accepted

    NVS markers, 2 s on screen, then esp_restart().

The request a browser on the device's own page sends today, and the six answers described in this post. 503, 400 and 413 come before anything is erased; only 500 and 200 mean the image reached the slot.

The token is the layer people misread, so here is what it is not: it is not a second password. GET /api/init hands it to any client on the device’s network, subject only to the rate limiter. The only secret on this route is the upload password on the device’s screen. What the token adds is a proof that the request came from the device’s own page and not from another site open in the same browser. That distinction comes from a hole.

The hole closed on 2026-11-20

Basic-Auth has a property that is convenient for people and convenient for attackers: it is an ambient credential. Once you have typed the password for a site, the browser keeps it and attaches it by itself to every later request to that site, whoever starts the request.

Until 2026-11-20, the upload password was the only thing POST /update required. So the analysis behind the fix goes like this: a page from another site, still open in the same browser while the owner was connected to the device’s access point and had already logged in to the update page, could send a cross-site POST /update of the kind browsers send without asking for permission first. It can’t read the response. It doesn’t need to: the browser would have attached the remembered password, and on an open build the device accepts an unsigned image whose name and version pass the checks below.

The fix makes the request one that a foreign page can’t produce. The token has to travel in a custom header, and a browser won’t send a cross-site request with a custom header without a CORS preflight, which the device never approves. Nor can the foreign page learn the token, because /api/init sends no CORS headers, so the browser refuses to let another origin read its answer.

Two honest caveats. This attack is the fix’s analysis: there is no proof of exploitation in a real browser. I didn’t build one. And no Kleidos device has been sold, so no customer’s device ever carried the hole. On a hardened build it would have run into the signature check anyway; it mattered on the open builds, which is exactly where nothing else stands between an authenticated request and a new image.

The page that never worked

The same commit fixed a second problem on the same route, and this one I find more instructive. The minimal /update page sent the image as multipart/form-data, the format an HTML file upload produces by default. The handler writes the raw request body to the slot. A multipart body starts with its boundary line, two dashes and a random string, and the first byte ESP-IDF expects is the image magic, 0xE9. So esp_ota_write() rejected the first chunk, the session aborted, and the page answered 500. Every time. It didn’t corrupt a slot or write anything useful; it just always failed.

The page until 2026-11-20

Content-Type: multipart/form-data

The body opens with the boundary line, two dashes and a random string, so its first byte is not 0xE9. esp_ota_write() rejects the first chunk and the page answers 500.

The page since 2026-11-20

Content-Type: application/octet-stream

The body is the raw image, as the QA upload scripts always sent it. Its first byte is the image magic, 0xE9, and the chunks stream into the slot.

Nobody saw it because the test tooling never used the page. The QA upload scripts sent the raw binary, as application/octet-stream, and those uploads worked. Since 2026-11-20 the page sends the raw binary as well. It is a small bug with a familiar shape: the path the tests exercised was not the path a person would use.

One route among several

The portal serves more than /update, and one fix on the shared server is worth a line. Until 2026-11-14, every route with a body reserved the whole body, up to a common 64 KB ceiling, before its own handler applied its limit, so an authenticated request that should carry a few bytes could make the device look for 64 KB of contiguous heap. Since then each route is registered with its own ceiling (2 KB for control requests, 64 KB only for full-file imports, and so on), a body declared larger is rejected with 413 before a byte is reserved, and the responses distinguish 413 (too big), 503 (out of memory) and 400 (transfer cut). /update was never part of that problem: it has streamed into a 4 KB buffer since its buffer moved from the stack to the heap on 2026-06-19.


Why does Bluetooth have to be off before an upload?

Kleidos is also a Bluetooth keyboard, and the project rule is that Bluetooth Low Energy (BLE) and the Wi-Fi portal never run together: no BLE advertising during an OTA, ever.

How the firmware enforces it depends on the state of the BLE stack when the owner asks for admin mode. If the stack is still up, the device sets a flag in RTC memory (the small memory that survives a reset), shows a notice and reboots; after the next unlock, with the PIN again, it lands straight in the portal. If the stack is already fully off, the access point starts in the same boot, without a reboot. The flag only routes: it decides which screen the unlock leads to and grants nothing.

Behind that sits a second check, in the upload handler itself, since 2026-07-07:

src/web/admin_ota_upload.cpp cpp
if ( kble::Facade::state()
     != kble::StackState::OFF ) {
    KLEIDOS_LOGE(
        kTag,
        "OTA refused: BLE stack not OFF"
    );
    ctx.req.send( 503, "text/plain",
                  "BLE active" );
    return;
}

The code gives three reasons for the rule, and they don’t all carry the same weight:

  • A crash on the S3. Bringing Wi-Fi up after tearing NimBLE down in the same boot once made the Wi-Fi driver read NVS structures that had already been freed, and the chip panicked. That was in the era of an earlier BLE library. The code today only reboots if the stack is still up, and I found no measurement that says whether the crash still happens with the current BLE host. So I’m not presenting it as a measured fact about today’s firmware: it is the reason the rule exists.
  • Radio coexistence while an update is being written.
  • RAM. On the boards without PSRAM (Plus SE, Plus 1.1 and Cardputer ADV), the access point has to start with the shadow framebuffer, about 64 KB, already freed.

What do the identity and version checks stop, and what don’t they?

These are the two checks the firmware adds on top of ESP-IDF, in steps 8 and 9. Both compare the candidate image’s descriptor with the running image’s descriptor, and both fail closed.

Which board is this image for?

The first question is which product the image belongs to, because comparing the versions of two different products makes no sense. Four Kleidos models (StickS3, CoreS3 SE, T-Deck and Cardputer) use the same ESP32-S3, and the bootloader checks only the chip ID. Without another check, a T-Deck image would pass on a StickS3. So each variant stamps kleidos-<variant> into the descriptor’s project_name, and the candidate must carry the same name as the running image or the session fails with ESP_ERR_OTA_VALIDATE_FAILED.

The candidate’s fields are treated as untrusted data. The firmware’s own comment says it directly: “The candidate descriptor is attacker-supplied”. The fields are copied into a buffer one byte wider than the field, so a terminator always exists, and project_name is measured with a bounded length of 32 bytes and rejected if it isn’t terminated within its field.

Two details are worth knowing before you rely on this check:

  • Identity is per board, not per build type. All the environments of a variant stamp the same name (the StickS3’s seven environments all say kleidos-sticks3). On an open board, a _debug image of the same board and version passes both checks.
  • The first identity-stamped update goes by cable. A board still running an image from before the check existed, whose name is plain kleidos, won’t accept over the air the first image that says kleidos-<variant>. That one update has to be done once over USB.

Is it going backwards?

The second check is a software version floor. The version lives in one file, version.txt, at the root of the repository: one line, strictly major.minor.patch, currently 0.1.0. ESP-IDF reads it natively as PROJECT_VER and stamps it into the descriptor’s version field. The build fails if the file is missing, has more than one line or isn’t N.N.N; otherwise ESP-IDF would fall back to git describe, and a version string like that would make the check reject every update. A variant check forbids the two Kconfig options that would set the version from configuration instead, so there is exactly one source.

The parser is strict on purpose. Three decimal fields and nothing after them:

src/ota/ota_state_logic.cpp (excerpts) cpp
// Reject trailing characters (e.g. ".4" or "-rc1"): strict 3-field only.
return *p == '\0';

// Overflow guard: fail closed rather than wrapping silently.
if ( v > ( ~0u - digit ) / 10u ) {
    return false;
}

So 1.0.0-rc1 and 1.0.0.1 are rejected, a field that overflows is rejected instead of wrapping, and an empty, null or malformed version on either side is rejected. Then the comparison:

src/ota/ota_state_logic.cpp cpp
// candidate >= running?
if ( cMaj != rMaj ) {
    return cMaj > rMaj;
}
if ( cMn != rMn ) {
    return cMn > rMn;
}
return cPat >= rPat;

Equal is accepted, so reinstalling the same version works; higher is accepted; lower is refused with ESP_ERR_INVALID_VERSION. Both operands come from images, the candidate partition and the running one, not from a constant compiled into the firmware:

src/platform/storage/ota.cpp (trimmed) cpp
const char* runningVersion = runningOk ? runningDesc.version : nullptr;
// ...
if ( const char* candidateVersion =
         candidateOk ? candidateVersionText.data() : nullptr;
     !::kleidos::ota::versionIsAcceptable( runningVersion,
                                           candidateVersion ) ) {

That last point has a history. The first version check, on 2026-07-04, compared a compile-time macro with the image’s git describe string, and it rejected every update. The comparison of running image against candidate image replaced it on 2026-07-07. The parser, the comparison and the identity check are covered by 47 native test cases in test/ota/test_ota_state_logic/.

The version policy during 0.x keeps the counter honest: MINOR goes up for an incompatible change (vault format, key derivation, portal API, OTA protocol, partition table), PATCH for a compatible one, and no counter ever goes down.

What these two checks are worth

Here is the sentence this post exists to say plainly. On an open build, both checks protect against mistakes, not against an attacker. The descriptor they read is part of the image, and the image comes from whoever uploads it. Someone who has the upload password can build an image that says kleidos-sticks3 and 9.9.9 and contains anything at all. Nothing signs those fields on an open build, so the checks have nothing to hold them to.

What they do stop is real, and it’s the common case: the image built for the wrong board, the old file picked from the wrong folder, the downgrade nobody meant. An authenticated mistake is far more likely than an authenticated attacker on a device whose password is shown on its own screen, and both checks earn their place for that reason.

And none of this covers the cable. On an open build, a USB reflash writes any image at all: these checks live only on the OTA path. On a _secure RELEASE build, the ROM download mode is closed, so the cable path is gone, as the previous post showed.


What does the signature add on a hardened build?

On the _secure builds, ESP-IDF checks an RSA-3072 Secure Boot v2 signature over the whole image when the upload closes, before the firmware’s own checks run, and the bootloader checks it again on every boot. The mechanism is one configuration option, CONFIG_SECURE_SIGNED_ON_UPDATE=y, which esp_image_format.c turns into signature checking for the application side:

bootloader_support/src/esp_image_format.c, ESP-IDF v6.0.3 c
#ifdef BOOTLOADER_BUILD
#ifdef CONFIG_SECURE_SIGNED_ON_BOOT
#define SECURE_BOOT_CHECK_SIGNATURE 1
#else
#define SECURE_BOOT_CHECK_SIGNATURE 0
#endif
#else /* !BOOTLOADER_BUILD */
#ifdef CONFIG_SECURE_SIGNED_ON_UPDATE
#define SECURE_BOOT_CHECK_SIGNATURE 1
#else
#define SECURE_BOOT_CHECK_SIGNATURE 0
#endif
#endif

esp_ota_end() reaches that code through its verification of the new partition, so an unsigned image, or one signed with another key, fails at step 7 and the boot slot never moves. The public key travels in each image’s signature block; the chip keeps only its SHA-256 digest in an eFuse, burned on the first hardened boot (the previous post has the details).

Open builds are not unverified, which is a common misreading. They check the image on every boot too, for integrity: the bootloader validates the structure, the checksum and the SHA-256 appended to the image. BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON defaults to n, and no Kleidos fragment changes it. An appended hash catches a corrupted image. It says nothing about who built it.

Open builds vs _secure: what verifies an OTA image
CheckOpen builds (base, _release, _debug)_secure
Image signatureNoneRSA-3072, Secure Boot v2
Checked when the upload closesStructure, checksum, appended SHA-256 (integrity)Integrity and signature
Checked at every bootIntegrity (hash)Integrity and signature, by the bootloader
Upload password and session tokenRequiredRequired
Board identity and version floorRun, but read fields the uploader wrote: they stop mistakesRun over a signed descriptor: they stop mistakes and foreign images
eFuse anti-rollbackNoRELEASE only, floor fixed at 1
Cable pathUSB reflash writes any imageRELEASE: download mode closed, OTA is the only way in
OTA observed on hardwareYes (debug build, lab network)Never

Even with the signature, the identity check is still per board rather than per build type, so what the signature narrows is not “which build” but “who could have produced the image”: only someone holding the signing key.

ESP-IDF also offers signed updates without hardware Secure Boot: its OTA page notes that “The verification of signed OTA updates can be performed even without enabling hardware secure boot”, through CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT and CONFIG_SECURE_SIGNED_ON_UPDATE_NO_SECURE_BOOT (secure OTA updates without Secure Boot). Kleidos’s open builds don’t use it. I mention it because it marks where the open builds’ gap actually is; it would not close the cable path, which on an open build writes anything.

What exists for this posture, and what has run

No OTA has been run on a hardened build, on any board. The firmware’s own QA documentation says so, and so do I. A set of tests is prepared for the hardened bench board from the previous post: a signed update that should be accepted, an unsigned image and one signed with another key that should end in a 500, another board’s image that the identity check should refuse, a lower version that should be refused and an equal one that should be accepted, a reboot before confirmation that should roll back, and a crash after confirmation. They are designed, with no recorded result. In the QA document’s words, “None of this has been observed yet.” Everything in this section about _secure is read from code.


Why doesn’t the eFuse version floor block a downgrade yet?

The software floor from the previous section compares the candidate with the running image. The hardware floor compares it with the chip. ESP-IDF calls it anti-rollback: each image carries a security version (CONFIG_BOOTLOADER_APP_SECURE_VERSION, stored in the descriptor), and an eFuse field, SECURE_VERSION, holds a floor that only goes up. It is configured only in the production fragment, the one that makes _secure a RELEASE build:

sdkconfig.secure.prod.opt-in (excerpt) text
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
CONFIG_BOOTLOADER_APP_ANTI_ROLLBACK=y
CONFIG_BOOTLOADER_APP_SECURE_VERSION=1

Read the last line again: 1. Every build in the fleet carries security version 1, so no downgrade between two Kleidos versions is blocked by the eFuse today. The floor starts protecting anything only when a security release raises the number before it is signed. _secure_dev and the bench image don’t carry this fragment at all, so they have no eFuse anti-rollback; the bench board reads SECURE_VERSION = 0.

What ESP-IDF 6.0.3 does with the number, once it is raised, is worth knowing, because none of it is manual. esp_ota_set_boot_partition() refuses a candidate below the floor and erases it:

app_update/esp_ota_ops.c, esp_ota_set_boot_partition(), ESP-IDF v6.0.3 (trimmed) c
#ifdef CONFIG_BOOTLOADER_APP_ANTI_ROLLBACK
esp_app_desc_t partition_app_desc;
esp_err_t err = esp_ota_get_partition_description(partition,
                                                  &partition_app_desc);
if (err != ESP_OK) {
    return err;
}

if (esp_efuse_check_secure_version(
        partition_app_desc.secure_version) == false) {
    // log: "...secure version is lower than stored in efuse.
    //       Partition will be erased."
    esp_err_t err = esp_partition_erase_range(partition, 0,
                                              partition->size);
    if (err != ESP_OK) {
        return err;
    }
    return ESP_ERR_OTA_SMALL_SEC_VER;
}
#endif

The floor is raised by ESP-IDF itself, in two places: the application raises it to the running image’s security version when it marks that image valid, and the bootloader does the same when it boots an image that is already valid. The bootloader also skips any slot whose security version is below the floor when it chooses what to boot. Nobody burns this eFuse by hand.

How many bumps fit

The answer is in how the value is read. esp_efuse_read_secure_version() doesn’t read a binary number; it counts set bits:

efuse/src/esp_efuse_fields.c, ESP-IDF v6.0.3 c
uint32_t esp_efuse_read_secure_version(void)
{
    uint32_t secure_version = 0;
    size_t field_size = esp_efuse_get_field_size(ESP_EFUSE_SECURE_VERSION);
    size_t size = MIN(APP_SEC_VER_SIZE_EFUSE_FIELD, field_size);
    esp_efuse_read_field_blob(ESP_EFUSE_SECURE_VERSION, &secure_version, size);
    return __builtin_popcount(secure_version & ((1ULL << size) - 1));
}

An eFuse bit can only go from 0 to 1, so a counter made of fuses is a unary counter: version n is n bits set. On the ESP32-S3 the field is 16 bits wide, which makes 16 bumps for the life of the chip; on the classic ESP32 it is 32 bits. Espressif’s anti-rollback section says the same: “This means that only 16 times you can do an anti-rollback.” It is easy to read “16-bit field” and think 65,535. It’s 16.

That budget changes how a project should use the number. Sixteen is plenty if it moves only at security releases, the ones that fix something an older image would let an attacker reach again. It runs out fast if it follows the ordinary version.

A small script, scripts/bump_secure_version.py, has handled the number since 2026-07-04: it raises it by one, refuses to lower it and refuses to go past 16, and CI runs its --check mode. Today that check passes without meaning much. It compares against the most recent tag it finds, and the repository has no release tags yet, only an archive tag. There has been nothing to compare against.

None of this has run on silicon: no RELEASE image has ever booted.


What happens if the new image fails to boot?

This is the third check, and the one that gets described loosely most often. Bootloader rollback is on in all Kleidos builds since 2026-07-07 (CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y in the fleet’s base fragment). Between 2026-07-04 and 2026-07-07 it was only in the _secure RELEASE fragment, and in June it was in no build at all.

next boot: bootloader

markFirmwareValid()
confirms

any reboot
first

RejectImage
(host-tested)

crash later

Upload passes steps 5 to 10

NEW

PENDING_VERIFY
boots once

VALID

ABORTED
previous image boots

INVALID
previous image boots

Stays VALID
no rollback

States of a new OTA image with rollback enabled, ESP-IDF 6.0.3

The bootloader waits for nobody

Here is what the ESP-IDF 6.0.3 bootloader does when it reads otadata, from bootloader_utility.c:

bootloader_support/src/bootloader_utility.c, ESP-IDF v6.0.3 (logging removed) c
#ifdef CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE
    bool write_encrypted = esp_efuse_is_flash_encryption_enabled();
    for (int i = 0; i < 2; ++i) {
        if (otadata[i].ota_state == ESP_OTA_IMG_PENDING_VERIFY) {
            otadata[i].ota_state = ESP_OTA_IMG_ABORTED;
            write_otadata(&otadata[i],
                          bs->ota_info.offset + FLASH_SECTOR_SIZE * i,
                          write_encrypted);
        }
    }
#endif

There is no clock in it. If the bootloader finds an image still in PENDING_VERIFY, the previous boot ended before the application confirmed it, and the reason doesn’t matter: panic, watchdog reset, power cut, reset button or a deliberate esp_restart(). The image becomes ABORTED and the previous one boots. Espressif’s rollback section puts it in one line: “a new application has only one attempt to boot successfully.”

So “the device rolls back if the new firmware doesn’t confirm within the watchdog timeout” is not how it works. A watchdog only matters if it is what causes the reboot, and that depends on what the watchdog is watching at that moment.

When Kleidos confirms

The firmware’s setup() runs in this order:

  1. beginBeforeHal()
  2. beginHal(), which runs hal::begin(): display, buttons, power
  3. beginServices()
  4. markFirmwareValid(): the decision
  5. offerSdFirmware() (the card path, below)
  6. everything else, including mounting the vault; the main loop subscribes to the task watchdog (5 s) only after this point, and the watchdog starts without watching the idle tasks

So a new image is confirmed very early: after the hardware and the services come up, before the vault is mounted, and before the loop is watched. That has three consequences, and I’d rather state all three than only the comfortable one:

  • An image that crashes or reboots while bringing up hardware and services is rolled back. That is the case rollback covers.
  • An image that hangs without panicking in that window does not reboot by itself, because nothing is watching it yet. It rolls back on the next manual reset or power cut, since it is still PENDING_VERIFY, but until someone presses a button it just sits there.
  • A failure after confirmation is not rolled back. PIN entry, the home screen and Bluetooth all run after markFirmwareValid(). An image that breaks any of them is already VALID.

Espressif’s own advice points the same way from the other side: “Perform the self-test procedure as quickly as possible, to prevent rollback due to power loss.” Confirming early protects a good image from an unlucky power cut. The price is a short list of what the confirmation proves.

What the decision can be

markFirmwareValid() has four outcomes: confirm the image, reject it, report a rollback, or do nothing (an ordinary boot).

Rejecting was added on 2026-11-07, for one specific case. Before confirming, the firmware asks whether the vault’s read path would refuse the vault: a memory map that doesn’t fit, or flash encryption over a partition that isn’t flagged for it. If it would, the decision turns into a rejection, and the firmware marks the running image invalid under the crypto lock and restarts, so the previous image boots. It mounts nothing to find out. This path is host-tested only: native tests are the only evidence, and it hasn’t run on any board.

Reporting a rollback uses the two NVS markers from step 11. If the markers say an update was attempted and the running version equals the version recorded before the update, the update didn’t stick, and the device shows a blocking notice. The markers are always cleared after the decision. Only the portal update and the portal’s card update write them, which matters in the next section.


Is there another way in? The SD card

On the four boards with a card slot (CoreS3 SE, Cardputer ADV, Core2 v1.3 and T-Deck), an image can also arrive on a microSD card, through two paths. Both use the same update session as the portal, so they run the same identity and version checks and, on _secure, the same signature check.

  • From the portal, already authenticated, with a fresh proof of the unlock secret that counts toward the same failed-attempt limit. This path writes the rollback markers.
  • At boot, before the PIN. If firmware.bin is on the card, the device offers it, and the offer is accepted by holding the GPIO0 button for 3 seconds within a 5-second window. The file has to be between 1 KB and 4 MB before the slot’s own limit applies. This path doesn’t write the rollback markers, so if an image installed this way rolls back, the device doesn’t announce it.

The boot-time offer deserves a plain assessment, because “installs firmware before the PIN” sounds worse than it is. It needs someone holding the device, with a card in it, pressing a button for three seconds. On _secure, the image still has to carry the right signature. On an open build, it accepts any image with the right board name and a version that doesn’t go down, and that adds no power beyond what the USB port already gives the same person: on an open build, anyone holding the device can reflash it over the cable with no check at all. The card path is the more convenient of two doors that were both open; it is not a new one.


What has actually been measured?

Every timing in this section comes from the same model of board, with the same kind of image, over the same network. That is a narrow base, and I’d rather show its edges.

Measured OTA results (ESP-IDF 6.0.3)
Date and setupResult
2026-10-06
M5StickC Plus2, open debug build, lab network
Upload in about 37 s, twice in a row; the image booted and was marked valid
2026-10-06
M5StickC Plus2, open debug build
Before sequential erase: the loop’s watchdog fired about 5 s into every upload, and the board rebooted
2026-10-06 and 2026-10-07
An open debug board, open debug build, lab network
Automated test: uploads its own debug image, requires the reboot, checks the running image’s hash, the changed slot and the VALID state
2026-11-14
M5StickC Plus2, open debug build, lab network
58 to 62 s per update, four updates with a vault of 90 credentials and 40 two-factor entries mounted, two on each of two vault read paths (memory-mapped, and a 16-page cache); all verified and booted, slots alternating, the vault unlocked and all 90 records read without errors

Two things about that base. First, the lab network is not the path a user takes. In those runs a debug build joined the lab’s Wi-Fi so the test tooling could reach it, which is not the device’s own access point. Second, the M5StickC Plus2 is a classic ESP32 board, not an S3. So the honest reading of the table is: the update path works on one open build of one classic board, over a network the product doesn’t use, at roughly a minute per update when the vault is full.

Not observed yet, by anyone
  • An OTA update on a hardened build, on any board.
  • A RELEASE image booting, on any board, so the eFuse floor has never acted.
  • An OTA update over the device’s own access point, the path a user would take.
  • An OTA timing on any board other than the M5StickC Plus2, or on any ESP32-S3.
  • The rejection path for a vault the read path would refuse (host-tested only).
  • The hardened tests for signed, unsigned, foreign, lower-version and interrupted updates (designed, no recorded result).

What existed when?

The first posts in this series were published in June 2026. None of them claimed anything about updates, which is just as well, because almost everything that makes the update path authenticated and downgrade-resistant arrived after them. On 2026-06-22, the function that closed an upload called esp_ota_end() and esp_ota_set_boot_partition() with no other check, and no build enabled bootloader rollback.

  1. Portal and OTA on esp_http_server and esp_ota_ops Milestone
  2. Before June
    App rollback guard (markFirmwareValid)

    Present, but no build enabled bootloader rollback, so marking an image valid had no effect.

  3. 4 KB upload buffer moves from the stack to the heap
  4. First version check

    Compared a compile-time macro with the image's git describe string and rejected every update. Same day: _secure becomes RELEASE with bootloader rollback and anti-rollback at 1, and the bump script arrives.

  5. Per-session upload password and rate limiter on /update
  6. Running image against candidate image Milestone

    The real version floor; bootloader rollback in all builds; 413 by size; 503 while Bluetooth is up; allocation with std::nothrow, where a failed allocation used to abort the device.

  7. version.txt as the single source, and per-board identity
  8. Sequential slot erase

    After the watchdog reboots measured on the M5StickC Plus2.

  9. Rejecting an image whose read path would refuse the vault

    Host-tested only.

  10. Per-route body ceilings on the portal
  11. Session token on POST /update; the page sends the raw binary Milestone
  12. Crypto hardware lock around the OTA calls

    Extended on 2026-11-22.

Read the dates against the thesis. Before 2026-07-04, an upload that reached /update on an open build could install any image that passed ESP-IDF’s integrity check, older or newer, and no build rolled back a bad one. The checks in this post are recent. The signature and the eFuse floor exist only in hardened builds, no hardened build has run an update, and the floor exists only in RELEASE, which has never booted.


The honest costs and limits

What you accept with this design
  • Open builds are authenticated, not signed. Someone with the upload password can install any image whose descriptor says the right board and a version that doesn’t go down, and the descriptor is theirs to write.
  • The eFuse floor blocks nothing yet. Every build carries security version 1, and on the S3 the floor can be raised only 16 times in the chip’s life.
  • The evidence for the hardened path is code, not hardware. No OTA on a hardened build, no RELEASE boot, and the prepared hardened tests have no recorded result.
  • No OTA over the device’s own access point has been measured, and every timing comes from one classic board over the lab network.
  • Rollback covers only the first moments of the first boot. A hang without a panic before confirmation waits for a manual reset, and a failure after confirmation is not rolled back.
  • A crash after confirmation is predicted to become a reboot loop. Reading the code, an image that is already VALID and crashes on every boot keeps booting and crashing, because nothing rolls back a valid image. On the bench that is recoverable over USB; a RELEASE board, with download mode closed, could not be recovered. This is predicted, read from code, not observed.
  • The session token is not a secret against anyone on the device’s network: it is a same-origin proof, and the upload password is the only secret.
  • A rollback after the boot-time card offer is not announced, because that path writes no markers.
  • The cable bypasses everything on an open build: a USB reflash writes any image, and the OTA checks never see it.
  • Some updates can’t go over the air: a partition table change, the first identity-stamped image on an old board, and anything at all on the three 4 MB boards.
  • The update can’t touch the vault, by construction, and every failure before the boot slot moves leaves the running image as it was.

Wrap: three checks, three different failures

Lay the checks side by side and each one answers a different question. The upload password and the session token answer who is asking, and since 2026-11-20 they also answer from which page. The board identity and the software version floor answer is this the image you meant, and on an open build that is all they can answer, because the uploader wrote the descriptor they read. The signature answers who built this image, and only the hardened build asks it. The eFuse floor answers is this older than anything this chip has accepted, and today the answer is always no, because the floor is 1. The bootloader’s rollback answers did the new image survive its first moments, and nothing after that.

That is the thesis in its working form. An OTA path is only as strong as the weakest check that can still say no, and which check that is depends on the situation. Against a slip of the hand, the open build is in good shape. Against someone who has the password, it has one layer, the password, and the hardened build has a second, the signature, that has never yet been exercised by an update. The two gaps I can name are the floor that blocks nothing and the window after confirmation that rollback doesn’t cover. Neither is hidden, and neither is closed yet.

Kleidos OTA updates, as tested

An app-only update path that can't reach the vault, a per-session upload password shown only on the device, a same-origin token against cross-site uploads, fail-closed board and strict-semver checks against the running image, sequential erase and bootloader rollback in every build. The rating is held back by what can still say no to an attacker: on open builds nothing signs the image, the eFuse floor is fixed at 1, rollback ends at an early confirmation, and the signed path has never run an update on hardware.

The next article goes back inside the chip, to what one PBKDF2 iteration costs on the S3’s SHA engine and how the build proves the count it applies. The question this series keeps for last is still at the boundary: what someone with physical access and a laboratory can recover from the device, signed updates and all.

Frequently asked questions

Does an authenticated OTA update stop an attacker on an ESP32 without Secure Boot?

Only up to the password. Once someone has the upload password, the board-identity and version checks read fields of the image descriptor that the uploader wrote, and no signature covers them on an open build. They stop mistakes, such as an image built for another board or an older file, not a malicious authenticated uploader. On Kleidos only the hardened _secure build verifies an RSA-3072 signature over the image, descriptor included, which turns those two checks into a real barrier.

Does the ESP-IDF 6.0.3 bootloader roll back an OTA image after a watchdog timeout?

There is no timeout. With CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE, the bootloader marks a new image PENDING_VERIFY on its first boot, and on the next boot of any cause (panic, watchdog reset, power cut, reset button or esp_restart) it marks a still-unconfirmed image ABORTED and boots the previous one. A watchdog only matters if it is what causes that reboot. Once the application confirms the image, the bootloader no longer rolls it back.

How many times can the SECURE_VERSION anti-rollback floor be raised on an ESP32-S3?

Sixteen. ESP-IDF reads the security version as the number of bits set in the SECURE_VERSION eFuse field, and on the ESP32-S3 that field is 16 bits wide, so it fits 16 increments. On the classic ESP32 the field is 32 bits, so 32. The counter is raised by ESP-IDF itself when a newer image is marked valid, never burned by hand.

Does a Kleidos OTA update touch the password vault?

No. An OTA update writes only the inactive app slot and the otadata partition. It never writes the bootloader, the partition table, NVS or the vault partition, which is why the vault survives an update by construction, and why a release that changes the partition table cannot be delivered over the air.

Why does the Kleidos upload need a session token if the token is not secret?

Because Basic-Auth is an ambient credential: a browser sends it again on its own, so a page from another site open in the same browser could have sent a POST that carried it. The session token must travel in a custom header, which another site cannot set without a CORS preflight the device never approves, and cannot read because the endpoint that hands it out sends no CORS headers. It proves the request came from the device's own page. It is not a second password: any client on the device's network can ask for it.

Why did the minimal Kleidos /update page always fail?

It sent the image as multipart/form-data, and the handler writes the raw request body to the slot. ESP-IDF's esp_ota_write rejects a first chunk whose first byte is not the image magic 0xE9, and a multipart body starts with the boundary dashes, so every upload from that page ended in a 500 on the first chunk. The test upload scripts sent the raw binary, so nobody saw it until it was fixed on 2026-11-20.