From f4f89151979768b008dcc8ed6164daeb0b35467d Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 18 Jul 2018 14:06:40 +0200 Subject: [PATCH] Pokus o sifrovani retezcu v EEPROM --- src/WiFiConfig.cpp | 51 +++++++++++++++++++++++++++++----------------- src/embHTML.h | 3 ++- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/WiFiConfig.cpp b/src/WiFiConfig.cpp index 78a9e7f..050f456 100644 --- a/src/WiFiConfig.cpp +++ b/src/WiFiConfig.cpp @@ -1,4 +1,6 @@ /* + * V5.9 - 18.7.2018 - Retezce, ukladane do EEPROM jsou primitivnim zpusobem sifrovany pro ztizeni odhaleni SSID a hesla pri dumpu pameti + * * V5.8 - 5.7.2018 - Opraveno spatne zobrazovani sily signalu v prehledu WiFi siti (spatne barvy) * * V5.7 - 4.7.2018 - BugFix - staticka konfigurace ip adresy se neuplatnila - vypada to, jako kdyby SDK ukladalo SSID a Password, ale uz neuklada @@ -139,11 +141,11 @@ uint8_t * getOurMAC(uint8_t *mac) return WiFi.softAPmacAddress(mac); } -uint32_t getEEPROMuint32(int start) +uint32_t getEEPROMuint32(unsigned int start) { uint32_t result = 0; - for (int i=0; i<4; ++i) + for (uint32_t i=0; i<4; ++i) { result <<= 8; result += EEPROM.read(start); @@ -152,24 +154,31 @@ uint32_t getEEPROMuint32(int start) return result; } -void setEEPROMuint32(int start, uint32_t val) +void setEEPROMuint32(unsigned int start, uint32_t val) { - for (int i=0; i<4; ++i) + for (unsigned int i=0; i<4; ++i) { EEPROM.write(start + 3 - i, (uint8_t)val); val >>= 8; } } -String getEEPROMString(int start, int len) +String getEEPROMString(unsigned int start, size_t maxlen) { + uint8_t mac[WL_MAC_ADDR_LENGTH]; + unsignd int enciphidx = 0; String string = ""; - for (int i = start; i < + start + len; ++i) + WiFi.softAPmacAddress(mac); + for (unsigned int i = start; i < + start + len; ++i) { uint8_t b = EEPROM.read(i); + b ^= mac[enciphidx]; + ++enciphidx; + enciphidx %= WL_MAC_ADDR_LENGTH; + if ((0xff == b) || (0 == b)) break; string.concat(char(b)); @@ -177,11 +186,14 @@ String getEEPROMString(int start, int len) return string; } -void setEEPROMString(int start, int len, String string) +void setEEPROMString(unsigned int start, size_t len, String &string) { + uint8_t mac[WL_MAC_ADDR_LENGTH]; + unsignd int enciphidx = 0; unsigned int si = 0; - for (int i = start; i < start + len; ++i) + WiFi.softAPmacAddress(mac); + for (unsigned int i = start; i < start + len; ++i) { char c; @@ -193,6 +205,9 @@ void setEEPROMString(int start, int len, String string) { c = 0; } + c ^= mac[enciphidx]; + ++enciphidx; + enciphidx %= WL_MAC_ADDR_LENGTH; EEPROM.write(i, c); ++si; } @@ -206,7 +221,7 @@ WiFiConfigUsrParameter::WiFiConfigUsrParameter(const char *id, const char *label _label = label; _length = length; _value = new char[length + 1]; - for (int i = 0; i < length; i++) + for (unsigned int i = 0; i < length; i++) { _value[i] = 0; } @@ -281,18 +296,16 @@ void WiFiConfig::addParameter(WiFiConfigUsrParameter *p) void WiFiConfig::_handleNotFound(void) { -// _time = millis() + (_timeout * 1000); // spocitame si novy cas, kdy budeme modul restartovat DEBUG_MSG("Requested URI: %s\r\n", server->uri().c_str()); if (server->uri().endsWith(String(F("favicon.ico")))) { - server->send(404, F("text/plain"), F("Err")); + server->send_P(404, FPSTR(TEXTPLAIN), PSTR("Err")); } else { server->sendHeader(F("Location"), String(F("http://")) + server->client().localIP().toString() + String(F("/index.htm")), true); -// server->sendHeader(F("Location"), String(F("http://")) + WiFi.softAPIP().toString() + String(F("/index.htm")), true); - server->send (302, F("text/plain"), F("Redirect")); + server->send_P(302, FPSTR(TEXTPLAIN), PSTR("Redirect")); } } @@ -306,7 +319,7 @@ void WiFiConfig::_handleReset(void) ESP.restart(); }); - server->send_P(200, TEXTHTML, PAGE_RESTART); + server->send_P(200, FPSTR(TEXTHTML), FPSTR(PAGE_RESTART)); } void WiFiConfig::_handleInfo(void) @@ -353,7 +366,7 @@ void WiFiConfig::_handleInfo(void) reply.concat(buff); reply.concat(F("")); - server->send(200, TEXTHTML, reply); + server->send(200, FPSTR(TEXTHTML), reply); } void WiFiConfig::_handleRoot(void) @@ -399,12 +412,12 @@ void WiFiConfig::_handleRoot(void) break; default: - content.concat(F("Neznámého")); + content.concat(F("Neznámý")); break; } content.concat(F("")); content.concat(FPSTR(PAGE_CAPTIVEPORTALCATCH2)); // 2. cast stranky (ukonceni) - server->send(200, TEXTHTML, content); + server->send(200, FPSTR(TEXTHTML), content); _time = millis() + (_timeout * 1000); // spocitame si novy cas, kdy budeme modul restartovat } @@ -498,7 +511,7 @@ void WiFiConfig::_handleDisplayAP(void) } content.concat(FPSTR(PAGE_END)); - server->send(200, TEXTHTML, content); + server->send(200, FPSTR(TEXTHTML), content); } void WiFiConfig::_handleSetAP(void) @@ -566,7 +579,7 @@ void WiFiConfig::_handleSetAP(void) } EEPROM.commit(); // skutecne ulozime data } - server->send(200, F("text/html"), FPSTR(PAGE_SAVED)); + server->send_P(200, FPSTR(TEXTHTML), FPSTR(PAGE_SAVED)); delay(2000); // cekame na odeslani dat // nakonfigurujeme ESP dle nove nastavenych parametru WiFi.disconnect(); // vsechno odpojime diff --git a/src/embHTML.h b/src/embHTML.h index 3c48688..6d6bf77 100644 --- a/src/embHTML.h +++ b/src/embHTML.h @@ -1,5 +1,6 @@ -// file:///I:/MyProjects/PB_ESP8266_WiFiConfig_Vyvoj/doc/_testy/s?_s=SSID1&_p=heslo&_n=jmeno_zarizeni&_a=on&_st=on&_i=192.168.1.1&_m=255.255.255.0&_g=192.168.1.3&_d=192.168.1.3&{n}={v} +// HTML data static const char TEXTHTML[] PROGMEM = "text/html"; +static const char TEXTPLAIN[] PROGMEM = "text/plain"; static const char PAGE_INDEX1[] PROGMEM = R"=====(