0

In my setup, I've got a number of ESP8266 devices around my home controlling various devices like my boiler and some lights.

They're all controlled by a central smart hub on a Raspberry Pi with a static's IP address.

This works great, but I'm increasingly concerned of the security implications of this. Communication between the Pi and the various ESP8266s is currently done over HTTP, with all the commands simply in the URL the Pi requests from the web servers.

As such, anyone on my network could theoretically control these smart devices using a simple curl request.

Whilst I have a strong Wi-Fi password, and am using WPA2 encryption, I would feel much more comfortable if communication with the ESP8266s was controlled in some way. E.g. in the same sort of way you can only connect to an SSH server using public key encryption if you have the right private key.

Is something like this possible to implement on an ESP8266? I've done some searching and only found articles about HTTPS which doesn't seem like it would solve my problem.

Thanks in advance, Rocco

  • 1
    You could have a shared password. Then have the sender hash that password concatenated with the time and data, and perhaps some random nonce. Send the time, nonce, data and hash to the ESP. The ESP can then do the same at it's end and validate that the hashes are the same. The ESP can validate the sender has the same password, and that the message hasn't been altered. Data however is still send in the clear, but in this case, I don't think it matters. The time is there to prevent replay attacks. Either have the ESP know the time through NTP, or have it store the timestamp of the last message. – Gerben May 1 at 16:33
  • @Gerben Thanks, that's a great idea! I feel your solution may be more relevant as it takes far less compute time on the ESP. I'm not quite sure how properly solve the problem of the ESP getting the time. Getting from the NTP would be off by a few milliseconds or seconds, and I'm not quite sure what you mean about the time stamping. – Rocco May 3 at 23:23
  • you don't need accurate time. The time is just there to prevent replay attacks. You store the last time stamp of the last message, and then only accept messages with newer timestamps. To prevent replay attacks after the ESP is reset, you could use NTP and make sure the message isn't older than a few seconds or so. PS just to reiterate; the sender sends the timestamp, along with the data, to the ESP. – Gerben May 4 at 13:03
2

The simplest method is to encrypt your communication channel using some secret key. You could use the built-in AES encryption functionality, which would mean that only people that know the key could encrypt a request in such a way that the device at the other end could decrypt it.

You would think that SSL (HTTPS) would do the job, but that only provides interception security, not authentication. Of course for even more security you can combine both HTTPS and AES encryption. One for overall encryption, and the other for encryption-based authentication.

| improve this answer | |
  • 1
    Thanks for your answer. So you suggest encrypting the instruction on the hub, sending it to the ESP8266, then decrypting it with some key and executing it on the ESP8266? Wouldn't it also be wise to implement HTTPS in this case to prevent replay attacks? – Rocco May 1 at 14:48
  • 1
    Sure, you can also use HTTPS. More is always better :) – Majenko May 1 at 14:54

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.