From 62aa76b06aa4f9a060a3c4a1e133595aacec67a4 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 20 Mar 2024 02:22:34 +0700 Subject: [PATCH] obfuscate passwords --- .../lib/ESPMegaPRO/InternalDisplay.cpp | 14 +++++++++++--- .../lib/ESPMegaPRO/InternalDisplay.hpp | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.cpp index 2fc8efa..b74f022 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.cpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.cpp @@ -212,9 +212,17 @@ void InternalDisplay::saveMQTTConfig() if (!this->getStringToBuffer("user_set.txt", this->mqttConfig->mqtt_user, 16)) return; - // Save the mqtt password - if (!this->getStringToBuffer("password_set.txt", this->mqttConfig->mqtt_password, 16)) + // Check if the password should be + char password_temp[32]; + // Get the passwords + if (!this->getStringToBuffer("password_set.txt", password_temp, 16)) return; + + // Check if the password should be updated + if (strcmp(password_temp, PASSWORD_OBFUSCATION_STRING)) + { + strcpy(this->mqttConfig->mqtt_password, password_temp); + } // Save the mqtt base topic if (!this->getStringToBuffer("topic_set.txt", this->mqttConfig->base_topic, 16)) @@ -852,7 +860,7 @@ void InternalDisplay::refreshMQTTConfig() this->sendStopBytes(); // Refresh the mqtt password this->displayAdapter->print("password_set.txt=\""); - this->displayAdapter->print(this->mqttConfig->mqtt_password); + this->displayAdapter->print(PASSWORD_OBFUSCATION_STRING); this->displayAdapter->print("\""); this->sendStopBytes(); // Refresh the mqtt base topic diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.hpp index 6532706..c6388a3 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.hpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.hpp @@ -6,6 +6,9 @@ #include #include +// Password Obfuscation +#define PASSWORD_OBFUSCATION_STRING "********" + // Page IDs #define INTERNAL_DISPLAY_BOOT_PAGE 0 #define INTERNAL_DISPLAY_DASHBOARD_PAGE 1