Principle:78 Xiaozhi esp32 Device Activation
| Knowledge Sources | |
|---|---|
| Domains | Security, Device_Identity, Authentication |
| Last Updated | 2026-10-17 00:00 GMT |
Overview
A challenge-response authentication mechanism that proves a device's identity to a server using an HMAC-SHA256 signature computed with a hardware-burned key from eFuse, enabling secure device registration and provisioning without exposing the secret key.
Description
Device activation is the process by which a voice assistant registers itself with the cloud server and receives its operational configuration (WebSocket/MQTT endpoints, server time, firmware update info). The XiaoZhi firmware uses a two-phase activation:
Phase 1 — Version Check (Ota::CheckVersion):
The device sends an HTTP POST to the OTA server with system information (MAC, UUID, serial number, user-agent). The server responds with:
- Firmware version and download URL (if update available)
- MQTT/WebSocket connection configuration
- Server time
- Activation challenge: a random nonce the device must sign to prove identity
Phase 2 — Activation (Ota::Activate):
If the server includes an activation challenge, the device computes HMAC-SHA256(HMAC_KEY0, challenge) using the ESP32's hardware HMAC peripheral, which uses a key burned into eFuse. The device sends the HMAC back to the server's /activate endpoint along with its serial number. The server verifies the HMAC using the same key (or a derived key) and returns:
200 OK: activation successful202 Accepted: pending, retry with backoff (up to 10 attempts)
The activation may also produce an activation code — a short numeric code displayed/spoken to the user for manual pairing.
Key security properties:
- The HMAC key never leaves the chip (eFuse + hardware HMAC peripheral)
- The serial number is read from eFuse USER_DATA block
- The challenge is a random nonce, preventing replay attacks
Usage
Use this principle when:
- Devices must be individually registered with a cloud service
- Hardware-backed cryptographic identity is available (ESP32 eFuse HMAC)
- First-boot provisioning requires server-side verification
- An activation code is needed for user-assisted pairing
Theoretical Basis
The activation uses a challenge-response authentication protocol:
Server Device
| |
| CheckVersion Response |
| {challenge: nonce} --------> |
| |
| HMAC = HMAC-SHA256(HMAC_KEY0, nonce)
| payload = {serial_number, challenge, hmac(hex)}
| |
| <-------- POST /activate --- |
| {payload} |
| |
| Verify HMAC |
| 200 OK (activated) -------> |
| 202 (retry) --------> |
The HMAC key is burned into eFuse block HMAC_KEY0 during manufacturing. The ESP32's hardware HMAC peripheral computes the signature without exposing the key to software:
esp_hmac_calculate(HMAC_KEY0, challenge_data, challenge_len, hmac_output);
// hmac_output is 32 bytes of SHA-256 digest
The serial number is read from the eFuse USER_DATA block (32 bytes), validated as printable ASCII text.
Practical Guide
When implementing device activation:
- Burn the HMAC key during manufacturing: use
esp_efuse_write_blockto program HMAC_KEY0. - Read serial from eFuse: check USER_DATA for printable ASCII; fall back to activation v1 if absent.
- Retry with backoff: on 202 response, wait 3–10 seconds and retry, up to 10 times.
- Display activation code: if
HasActivationCode(), play digit sounds for each character. - Persist server config: store MQTT/WebSocket config to NVS after successful activation.
- Set server time: call
settimeofday()if server_time is provided.