Skip to content

Accept 32-character hex meter keys in MQTT setconfig - #1310

Merged
gskjold merged 1 commit into
mainfrom
fix-mqtt-meter-key-length
Nov 5, 2026
Merged

gskjold merged 1 commit into
mainfrom
fix-mqtt-meter-key-length

Conversation

@gskjold

@gskjold gskjold commented Nov 5, 2026

Copy link
Copy Markdown
Member

Why

The meter's GCM encryption key and authentication key are 16 bytes each, so their hex form is 32 characters. JsonMqttHandler::handleConfigMessage only accepted a config.m.e.k / config.m.e.a string of 16 characters and then called fromHex(..., 16), which reads 16 bytes, i.e. 32 characters:

  • A real 32-character key sent via setconfig was silently ignored, and the old key was kept.
  • A 16-character string passed the check, and fromHex then read 16 characters past the end of the string's buffer (the terminator and beyond) into the key.

Change

Require the length to be sizeof(key) * 2 (32), and pass sizeof(key) to fromHex rather than a literal. This matches what the web configuration form sends (AmsWebServer.cpp, mek/mea). Behaviour for disabled encryption (keys zeroed) is unchanged. Keys of any other length are still ignored.

Verification

  • pio run -e esp32 builds. MQTT config handling is ESP32-only.
  • Not tested on a device: I haven't sent a setconfig with a 32-character key to real hardware.

🤖 Generated with Claude Code

The encryption and authentication keys are 16 bytes, so their hex form
is 32 characters. setconfig only accepted a 16-character string and then
had fromHex read 32 characters from it, so a correct key was silently
ignored and a 16-character one was parsed past the end of the string.
Require twice the key size, as the web configuration already sends.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

🔧 PR Build Artifacts

Version: 58d3a92

All environments built successfully. Download the zip files:

Artifacts expire after 7 days. View workflow run

@gskjold
gskjold merged commit 389e921 into main Nov 5, 2026
8 checks passed
@gskjold
gskjold deleted the fix-mqtt-meter-key-length branch November 5, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant