Skip to content

Commit

Permalink
Hide passwords in console output by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
prampec committed Feb 3, 2019
1 parent 02cb39c commit 1ef271a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -48,6 +48,9 @@ tzapu's WiFiManager is a great library. The features of IotWebConf may appear ve
- When connecting in AP mode, the WiFi provides an encryption layer, so all you communication here is known to be safe.
- When connecting through a WiFi router (WiFi mode), the Thing will ask for authentication when someone requests the config portal. This is required as the Thing will be visible for all devices sharing the same network. But be warned by the following note...
- NOTE: **When connecting through a WiFi router (WiFi mode), your communication is not hidden from devices connecting to the same network.** So either: Do not allow ambiguous devices connecting to your WiFi router, or configure your Thing only in AP mode!
- However IotWebConf has a detailed debug output, passwords are not shown in this log by default. You have
to enable password visibility manually in the IotWebConf.h with the IOTWEBCONF_DEBUG_PWD_TO_SERIAL
if it is needed.

## Compatibility
IotWebConf is primary built for ESP8266. But meanwhile it was discovered, that the code can be adopted
Expand Down
4 changes: 4 additions & 0 deletions examples/IotWebConf01Minimal/IotWebConf01Minimal.ino
Expand Up @@ -23,6 +23,10 @@
*
* You have to leave the access point before to let the Thing continue operation
* with connecting to configured WiFi.
*
* Note that you can find detailed debug information in the serial console depending
* on the settings IOTWEBCONF_DEBUG_TO_SERIAL, IOTWEBCONF_DEBUG_PWD_TO_SERIAL set
* in the IotWebConf.h .
*/

#include <DNSServer.h>
Expand Down
67 changes: 65 additions & 2 deletions src/IotWebConf.cpp
Expand Up @@ -217,9 +217,23 @@ boolean IotWebConf::configLoad()
#ifdef IOTWEBCONF_DEBUG_TO_SERIAL
Serial.print("Loaded config '");
Serial.print(current->getId());
Serial.print("'= '");
Serial.print("'= ");
# ifdef IOTWEBCONF_DEBUG_PWD_TO_SERIAL
Serial.print("'");
Serial.print(current->valueBuffer);
Serial.println("'");
# else
if (strcmp("password", current->type) == 0)
{
Serial.println(F("<hidden>"));
}
else
{
Serial.print("'");
Serial.print(current->valueBuffer);
Serial.println("'");
}
# endif
#endif

start += current->getLength();
Expand Down Expand Up @@ -247,9 +261,23 @@ void IotWebConf::configSave()
#ifdef IOTWEBCONF_DEBUG_TO_SERIAL
Serial.print("Saving config '");
Serial.print(current->getId());
Serial.print("'= '");
Serial.print("'= ");
# ifdef IOTWEBCONF_DEBUG_PWD_TO_SERIAL
Serial.print("'");
Serial.print(current->valueBuffer);
Serial.println("'");
# else
if (strcmp("password", current->type) == 0)
{
Serial.print(F("<hidden>"));
}
else
{
Serial.print("'");
Serial.print(current->valueBuffer);
Serial.println("'");
}
# endif
#endif

this->writeEepromValue(start, current->valueBuffer, current->getLength());
Expand Down Expand Up @@ -366,7 +394,18 @@ void IotWebConf::handleConfig()
Serial.print("Rendering '");
Serial.print(current->getId());
Serial.print("' with value: ");
# ifdef IOTWEBCONF_DEBUG_PWD_TO_SERIAL
Serial.println(current->valueBuffer);
# else
if (strcmp("password", current->type) == 0)
{
Serial.println(F("<hidden>"));
}
else
{
Serial.println(current->valueBuffer);
}
# endif
#endif

String pitem = FPSTR(IOTWEBCONF_HTTP_FORM_PARAM);
Expand Down Expand Up @@ -465,6 +504,18 @@ void IotWebConf::handleConfig()
#ifdef IOTWEBCONF_DEBUG_TO_SERIAL
Serial.print(current->getId());
Serial.print("='");
# ifdef IOTWEBCONF_DEBUG_PWD_TO_SERIAL
Serial.print(current->valueBuffer);
# else
if (strcmp("password", current->type) == 0)
{
Serial.print(F("<hidden>"));
}
else
{
Serial.print(current->valueBuffer);
}
# endif
Serial.print(current->valueBuffer);
Serial.println("'");
#endif
Expand Down Expand Up @@ -768,9 +819,13 @@ void IotWebConf::stateChanged(byte oldState, byte newState)
#ifdef IOTWEBCONF_DEBUG_TO_SERIAL
Serial.print("Connecting to [");
Serial.print(this->_wifiAuthInfo.ssid);
# ifdef IOTWEBCONF_DEBUG_PWD_TO_SERIAL
Serial.print("] with password [");
Serial.print(this->_wifiAuthInfo.password);
Serial.println("]");
# else
Serial.println(F("] (password is hidden)"));
# endif
#endif
this->_wifiConnectionStart = millis();
this->_wifiConnectionHandler(this->_wifiAuthInfo.ssid, this->_wifiAuthInfo.password);
Expand Down Expand Up @@ -882,15 +937,23 @@ void IotWebConf::setupAp()
{
#ifdef IOTWEBCONF_DEBUG_TO_SERIAL
Serial.print("With default password: ");
# ifdef IOTWEBCONF_DEBUG_PWD_TO_SERIAL
Serial.println(this->_initialApPassword);
# else
Serial.println(F("<hidden>"));
# endif
#endif
this->_apConnectionHandler(this->_thingName, this->_initialApPassword);
}
else
{
#ifdef IOTWEBCONF_DEBUG_TO_SERIAL
Serial.print("Use password: ");
# ifdef IOTWEBCONF_DEBUG_PWD_TO_SERIAL
Serial.println(this->_apPassword);
# else
Serial.println(F("<hidden>"));
# endif
#endif
this->_apConnectionHandler(this->_thingName, this->_apPassword);
}
Expand Down
3 changes: 3 additions & 0 deletions src/IotWebConf.h
Expand Up @@ -42,6 +42,9 @@
// -- Logs progress information to Serial if enabled.
#define IOTWEBCONF_DEBUG_TO_SERIAL

// -- Logs passwords to Serial if enabled.
//#define IOTWEBCONF_DEBUG_PWD_TO_SERIAL

// -- Helper define for serial debug
#ifdef IOTWEBCONF_DEBUG_TO_SERIAL
# define IOTWEBCONF_DEBUG_LINE(MSG) Serial.println(MSG)
Expand Down

0 comments on commit 1ef271a

Please sign in to comment.