Repository navigation
Conversation
wifiPwdDecrypt() returns the input unchanged when it cannot decrypt it (not base64, not whole AES blocks, or bad PKCS7 padding). applySettingsFromRoot() and getWifiFromNVS() treated that return value as a plaintext password, so saveConfigs()/saveWifiIntoNVS() encrypted the ciphertext again: every boot nested another layer and the real password was lost. That happens when config.conf or NVS was written by a build with a different WIFI_ENC_KEY, which is normal when an SD card moves between devices or the key changes between releases. wifiPwdDecryptStored() now reports whether the value was readable. When it was not, the caller keeps a good password already loaded from config.conf, or stores the SSID without one, instead of re-encrypting garbage. Values this build can read are handled exactly as before; the cipher, key, IV and stored format are unchanged. Also stop seeding config.conf with the myNetSSID/myNetPwd placeholder, which showed up as a saved network and came back after every reset, and collapse duplicate SSIDs when NVS is merged with config.conf.
This branch has not been deployed
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.
Follow-up to #477, split out as requested: this PR only touches the WiFi credential handling in shared code (
src/settings.cpp,src/settings.h,src/wifi_crypto.cpp,src/wifi_crypto.h). No board files, and the cipher itself is not changed.The bug
wifiPwdDecrypt()returns its input unchanged when it cannot decrypt it:applySettingsFromRoot()(config.conf) andgetWifiFromNVS()(NVS) took that return value as the plaintext password. The nextsaveConfigs()/saveWifiIntoNVS()then encrypted it again, so every boot wrapped another layer around a ciphertext nobody could read, and the real password was gone.That happens whenever the stored value was written with a different
WIFI_ENC_KEY: an SD card moved from another device, a config.conf copied between boards, or the key changing between releases. It is silent — the network stays in the list, looks saved, and only fails when connecting.The fix
wifiPwdDecryptStored()reports whether the value was actually readable, and unwraps values that earlier builds encrypted more than once.saveConfigs()no longer seeds themyNetSSID/myNetPwdplaceholder into an empty list. That placeholder showed up as a saved network and came back after every reset.Compatibility
The cipher is untouched: same AES-128-CBC, same
WIFI_ENC_KEY, same IV, same base64 + PKCS7 format. Values written by this build, and readable by the old code, decrypt exactly as before.wifiPwdDecrypt()keeps its signature and its old behaviour for existing callers.How it was observed
On an ESP32-P4 board with a config.conf/NVS carried over from a build using a different key,
wifi listshowed the same SSID twice plusmyNetSSID, all with unreadable passwords, andwifi connectfailed on the stored value. After the fix there is one entry per SSID with the real password, it survives reboots, andwifi connectsucceeds.