Pokus o sifrovani retezcu v EEPROM

This commit is contained in:
Pavel Brychta 2018-07-18 14:06:40 +02:00
parent 68083ee040
commit f4f8915197
2 changed files with 34 additions and 20 deletions

View File

@ -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.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 * 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); return WiFi.softAPmacAddress(mac);
} }
uint32_t getEEPROMuint32(int start) uint32_t getEEPROMuint32(unsigned int start)
{ {
uint32_t result = 0; uint32_t result = 0;
for (int i=0; i<4; ++i) for (uint32_t i=0; i<4; ++i)
{ {
result <<= 8; result <<= 8;
result += EEPROM.read(start); result += EEPROM.read(start);
@ -152,24 +154,31 @@ uint32_t getEEPROMuint32(int start)
return result; 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); EEPROM.write(start + 3 - i, (uint8_t)val);
val >>= 8; 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 = ""; 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); uint8_t b = EEPROM.read(i);
b ^= mac[enciphidx];
++enciphidx;
enciphidx %= WL_MAC_ADDR_LENGTH;
if ((0xff == b) || (0 == b)) if ((0xff == b) || (0 == b))
break; break;
string.concat(char(b)); string.concat(char(b));
@ -177,11 +186,14 @@ String getEEPROMString(int start, int len)
return string; 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; 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; char c;
@ -193,6 +205,9 @@ void setEEPROMString(int start, int len, String string)
{ {
c = 0; c = 0;
} }
c ^= mac[enciphidx];
++enciphidx;
enciphidx %= WL_MAC_ADDR_LENGTH;
EEPROM.write(i, c); EEPROM.write(i, c);
++si; ++si;
} }
@ -206,7 +221,7 @@ WiFiConfigUsrParameter::WiFiConfigUsrParameter(const char *id, const char *label
_label = label; _label = label;
_length = length; _length = length;
_value = new char[length + 1]; _value = new char[length + 1];
for (int i = 0; i < length; i++) for (unsigned int i = 0; i < length; i++)
{ {
_value[i] = 0; _value[i] = 0;
} }
@ -281,18 +296,16 @@ void WiFiConfig::addParameter(WiFiConfigUsrParameter *p)
void WiFiConfig::_handleNotFound(void) 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()); DEBUG_MSG("Requested URI: %s\r\n", server->uri().c_str());
if (server->uri().endsWith(String(F("favicon.ico")))) 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 else
{ {
server->sendHeader(F("Location"), String(F("http://")) + server->client().localIP().toString() + String(F("/index.htm")), true); 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_P(302, FPSTR(TEXTPLAIN), PSTR("Redirect"));
server->send (302, F("text/plain"), F("Redirect"));
} }
} }
@ -306,7 +319,7 @@ void WiFiConfig::_handleReset(void)
ESP.restart(); ESP.restart();
}); });
server->send_P(200, TEXTHTML, PAGE_RESTART); server->send_P(200, FPSTR(TEXTHTML), FPSTR(PAGE_RESTART));
} }
void WiFiConfig::_handleInfo(void) void WiFiConfig::_handleInfo(void)
@ -353,7 +366,7 @@ void WiFiConfig::_handleInfo(void)
reply.concat(buff); reply.concat(buff);
reply.concat(F("</table></form>")); reply.concat(F("</table></form>"));
server->send(200, TEXTHTML, reply); server->send(200, FPSTR(TEXTHTML), reply);
} }
void WiFiConfig::_handleRoot(void) void WiFiConfig::_handleRoot(void)
@ -399,12 +412,12 @@ void WiFiConfig::_handleRoot(void)
break; break;
default: default:
content.concat(F("Neznámého")); content.concat(F("Neznámý"));
break; break;
} }
content.concat(F("</div>")); content.concat(F("</div>"));
content.concat(FPSTR(PAGE_CAPTIVEPORTALCATCH2)); // 2. cast stranky (ukonceni) 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 _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)); content.concat(FPSTR(PAGE_END));
server->send(200, TEXTHTML, content); server->send(200, FPSTR(TEXTHTML), content);
} }
void WiFiConfig::_handleSetAP(void) void WiFiConfig::_handleSetAP(void)
@ -566,7 +579,7 @@ void WiFiConfig::_handleSetAP(void)
} }
EEPROM.commit(); // skutecne ulozime data 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 delay(2000); // cekame na odeslani dat
// nakonfigurujeme ESP dle nove nastavenych parametru // nakonfigurujeme ESP dle nove nastavenych parametru
WiFi.disconnect(); // vsechno odpojime WiFi.disconnect(); // vsechno odpojime

View File

@ -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 TEXTHTML[] PROGMEM = "text/html";
static const char TEXTPLAIN[] PROGMEM = "text/plain";
static const char PAGE_INDEX1[] PROGMEM = R"=====( static const char PAGE_INDEX1[] PROGMEM = R"=====(
<!DOCTYPE html><html lang="en"><head><meta charset= "utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> <!DOCTYPE html><html lang="en"><head><meta charset= "utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">