ESP32rev v3.0+eFusebootloaderappkite42broker :88831WiFiClientSecure net;2net.setCACert(ROOT_CA);3PubSubClient mqtt(net);4mqtt.setServer(HOST, 8883);5mqtt.connect(ID, USER, PASS);6mqtt.publish(TOPIC, "21.5");attacker21.521.5CA4101818?#%&kite429f3ac1..
Back: the ESP32 board (chip, eFuse keys, flash) and the MQTT brokerFront: the firmware card and the attackerTokens: readings, certificates, key numbers, a flash dump and an attacker's appAn ESP32 sensor node, its MQTT broker and an attacker, with the firmware lines that open a TLS connection on port 8883. TLS lets the device check the broker's certificate against the CA it carries, agree a key without sending it (4 and 10 cross, 18 appears at both ends) and seal every message. On the chip, flash encryption (AES-256, key in eFuse) hides the password "kite42" from a flash dump, and secure boot (3072-bit RSA signatures) refuses unsigned code.

The threats

  1. A device on a network can be attacked three ways. Someone reads or fakes its traffic. Someone holding the board copies its memory, passwords and all. Someone loads their own program onto it. Each needs its own defence.

TLS on the wire

Protecting the chip

What happens

;; step 1/11 · threats
threat                       defence
read or fake the traffic  -> TLS
copy the flash memory     -> flash encryption
run their own firmware    -> secure boot

The card shows the six lines that open the connection. The whole sketch also joins Wi-Fi and defines HOST, ID, USER, PASS, TOPIC and ROOT_CA (paste your CA's PEM text there). In the current arduino-esp32 core WiFiClientSecure is another name for NetworkClientSecure. The key exchange uses textbook Diffie-Hellman with tiny numbers (p = 23, g = 5) so you can check it by hand. Real TLS uses an elliptic-curve version with numbers far too large to guess.