0

I'm playing with Over The Air (OTA) updates in my LoLin. I can make connections to my router and OTA updates seem to work well.

I'm uncomfortable storing my WiFi router SSID and password unencrypted in every sketch. Can I store an encrypted password instead for use in WiFi.begin()?

For example, Linux has wpa_pasphrase, which generates a 32-byte number which is an encrypted version of the password which can safely be stored in plaintext configuration files.

1
  • 1
    you can let the esp8266 store the password. see WiFiManager library – Juraj Jan 11 '20 at 6:18
2

Can I store an MD5 password hash instead

No. MD5 is a "trapdoor" algorithm. It's one-way. You can make a hash from a password but you cannot make a password from a hash.

You could AES encrypt it, but you would need to have the AES key in your sketch to decrypt the password, which just moves the problem elsewhere.

Typically in a real-world situation you wouldn't have either the SSID or the password in the sketch. Instead you'd create a configuration system which would allow you to set (and of course change) both the SSID and password at runtime, and have the data stored somewhere (either EEPROM or in a file in SPIFFS, for example).

You might want to take a look at WiFiManager which automates that process for you.

2
  • I shall reword the question to remove "MD5". What I actually hope for is an equivalent to the Linux wpa_passphrase command, which generates a 32 byte encrypted number which I can store in plaintext configuration files instead of storing my password. – KDM Jan 11 '20 at 0:18
  • @KDM The same thing applies - all you're doing is moving the problem. Even worse in this case, since the result is the actual key that is used to connect, not just the source data that generates it internally. – Majenko Jan 11 '20 at 0:36
2

I use Tzapu's WiFiManager https://github.com/tzapu/WiFiManager.

That starts your ESP as a WiFi access point (AP mode) which presents a web page at http://192.168.4.1 where you enter your WiFi SSID and password. It then stores the password and restarts WiFi as a station (STA mode).

On restart if the password is already stored then it just connects as a station.

If the SSID can't be found it runs the access point again.

1

I laud your intention and wish there were a good solution on the ESP8266 for what you're trying to do.

MD5 is a one-way hash function, so you won't be able to simply recover the original string to use in WiFi.begin().

MD5 is also considered to be "cryptographically broken and unsuitable for further use" as of 2008. So if you're concerned about more than just a casual eavesdropping attack sniffing out your password, MD5 isn't considered good for any kind of security application these days.

You'd need to use some form of reversible encryption, but you'd still need to store the key somewhere. If you were using an ESP32, it has the capability of encrypting its flash storage, but the ESP8266 can't do that, so you'll always be vulnerable to someone recovering keys or passwords if they get sufficient access to the CPU.

1
  • I don't really mind how the password is encrypted, but on my Raspberry Pi, I can load the config file with a hashed password for my WiFi router, so that my password isn't stored in plaintext. As such, there is a way to achieve what I want, even if it's not yet implemented on the Arduino library. – KDM Jan 11 '20 at 0:15
0

While it IS possible to reverse a password hash, especially MD5 (https://md5decrypt.net/en/), it doesn't buy you anything in the way of security since everyone else can also reverse them.

If you happen to have a second LoLin, you could set it up as an Access Point and have the first device connect to it instead of having it connect to your router. Then you could relay the communication to a PC over USB.

Sure, it's a bit of a pain, but it at least means that you don't have to expose your router's password on a device that someone can pick up and walk off with.

2
  • Hmmm... Having had a good thumb through this website, I now understand why MD5 is IRREVERSIBLE and why it can only be put back into plaintext if someone has already stored the original plaintext along with its checksum. – KDM Jan 12 '20 at 10:46
  • MD5 (and most other hashes) on their own are irreversible. It's when you constrain the input to passwords that it becomes reversible. Normally with a hash, there are many inputs that can generate the same output. With a password hash, only one of the inputs will normally be 8-20 printable charaters. Knowing that, you just need to reference a table of known password->hashes and boom - hashed password reversed. Salting the hash makes reversing the value more difficult and using a better hash than MD5 makes it harder yet. However, given enough time, all known password hashes can be reversed. – Merkle Groot Jan 12 '20 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.