Repository navigation
Accept 32-character hex meter keys in MQTT setconfig - #1310
Merged
Merged
Conversation
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]>
🔧 PR Build ArtifactsVersion: All environments built successfully. Download the zip files:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The meter's GCM encryption key and authentication key are 16 bytes each, so their hex form is 32 characters.
JsonMqttHandler::handleConfigMessageonly accepted aconfig.m.e.k/config.m.e.astring of 16 characters and then calledfromHex(..., 16), which reads 16 bytes, i.e. 32 characters:setconfigwas silently ignored, and the old key was kept.fromHexthen 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 passsizeof(key)tofromHexrather 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 esp32builds. MQTT config handling is ESP32-only.setconfigwith a 32-character key to real hardware.🤖 Generated with Claude Code