Repository navigation
Ignore meter keys that are not 32 hex characters in web save and config import - #1311
Merged
Merged
Conversation
…ig import The web configuration form only checked that the encryption and authentication keys were hex, not how long they were, and handleSave and the config file import both had fromHex read 32 characters regardless. A short key was parsed past the end of the string, and in the config file import past the end of the line into leftovers from earlier lines. Only accept a key of exactly twice the key size and keep the stored key otherwise; an empty key in the web form still clears it. The form now requires 32 hex characters, so a wrong length is reported before saving. 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
Follow-up to #1310, same bug in the other two places that take meter keys. The GCM encryption and authentication keys are 16 bytes, i.e. 32 hex characters, but:
AmsWebServer::handleSave,mek/mea): the form'spatternonly required hex characters ([0-9A-Fa-f]+), not a length. A short or mistyped key such asABCDwas accepted, andfromHex(..., 16)read 32 characters from it, past the end of the string. A key with an extra character was cut off without a warning.configFileParse,meterEncryptionKey/meterAuthenticationKey): the same unconditionalfromHex(..., 16).readBytesUntildoesn't null-terminate andbufisn't cleared between lines, so a short key line was filled up with leftover bytes from earlier, longer lines.Changes
handleSave: after removing0x, parse the key only if it is exactlysizeof(key) * 2characters. Otherwise keep the stored key. An empty field still clears the key, as before.configFileParse: parse the key only if the line length (size, not the string length, which could include those leftover bytes) is the prefix plus 32 characters.meterKeyPatternreplaceshexPattern, which only these two inputs used), so the browser reports a wrong length before submitting. The config JSON always sends 32 characters (zeros when no key is set), so existing configs still validate.ui/distis rebuilt.Verification
pio run -e esp32 -e esp8266builds;npm run buildinui/builds.🤖 Generated with Claude Code