Esp32 Wifi Provisioning
Provisioning is the one-time setup flow that gets a chip's Wi-Fi credentials from a user's phone into the device, and it has to solve a problem that sounds almost contradictory: the device isn't on the home Wi-Fi network yet, so it can't just receive the password over Wi-Fi the normal way — the chip has to open some other, non-Wi-Fi communication channel specifically to bootstrap the Wi-Fi connection it doesn't have yet. A brand-new smart plug out of the box knows nothing about the network it's about to join; BLE or a temporary SoftAP (the device briefly acting as its own Wi-Fi access point) exist specifically to give a phone app a way to talk to the device before that device has any real network connection of its own.
Encrypting the credential transfer over BLE or SoftAP matters precisely because this is the one moment the device is deliberately broadcasting an open invitation for a nearby phone to talk to it — which also makes it the one moment an attacker's phone could try the exact same thing. An unencrypted provisioning channel would let anyone within BLE or Wi-Fi range who understands the protocol simply listen in and capture a home network's password the instant a legitimate owner sets up their new device; real provisioning schemes establish a session key (often via a key-exchange step or a shared secret printed on the device, like a QR code) before the actual SSID and password are transmitted, so even an attacker sniffing the raw radio traffic sees only ciphertext rather than a plaintext Wi-Fi password.
Closing the provisioning channel immediately after successful setup is as much a security decision as it is a cleanup step, because a BLE or SoftAP interface left open indefinitely is a permanent, unnecessary attack surface a deployed product should never carry. Once a device has joined the real network and no longer needs to receive credentials, there's no legitimate reason for it to keep advertising a BLE provisioning service or hosting a SoftAP — leaving either one running after setup is exactly the kind of lingering, unused capability a security review flags, since every open interface the chip exposes is one more thing an attacker could attempt to exploit, whether or not the device's owner ever needed it again.
The fallback path — what happens when provisioning fails partway through, or the stored credentials turn out to be wrong (the password changed, the router was replaced) — is where many provisioning implementations quietly fall short, because it's much easier to design the happy path than to design graceful recovery from a half-completed or now-invalid setup. A device that can't connect using its stored credentials needs a deliberate, discoverable way back into provisioning mode — typically a long-press button combination or a specific number of power cycles — rather than becoming a bricked, un-reconfigurable device the moment its one stored Wi-Fi network becomes unavailable; designing that re-entry path explicitly, and testing it as carefully as the initial setup flow, is what separates a provisioning scheme that works on a demo day from one that survives years of real households changing routers and passwords.
Provisioning is the first security-sensitive interaction a product has with its owner, and getting it right means solving three things together: a genuinely encrypted bootstrap channel that never transmits a home network's password in the clear, a channel that closes itself the instant it's done its one job rather than lingering as an open attack surface, and a reliable way back into setup mode when the stored credentials eventually stop working — the last of which is the part most likely to get skipped under a ship deadline and the part users notice most when it's missing.