#Why this matters
In earlier lessons, unpacking firmware and emulating binaries showed how easily hardcoded passwords and static API keys leak from flash memory. When a fleet of sensors communicates with a central MQTT broker or REST gateway, a single shared credential turns one compromised unit into full access across every device in the deployment.
Over-the-air (OTA) update channels carry equal risk. If a device accepts firmware over plain HTTP, or trusts TLS transport without verifying an end-to-end signature on the image itself, an attacker who compromises a CDN mirror or intercepts local traffic can flash malicious code onto thousands of endpoints at once.
#Moving beyond shared secrets and weak tokens
Many legacy devices authenticate to an ingestion API using a static token embedded in firmware or derived predictably from a MAC address. Others validate a bearer token but still trust an unverified identifier in the payload, such as an X-Device-Id header or an MQTT topic path, creating an authentication and authorization bypass.
| Mechanism | Secret storage | Blast radius on extraction | Suitable for fleet scale |
|---|---|---|---|
| Shared static API key | Plaintext flash | Entire fleet compromised | No |
| Predictable ID / MAC hash | Derived in code | Any device can be impersonated | No |
| Per-device HMAC token | Provisioned per unit | Single unit if bound to ID | Limited without rotation |
| X.509 mTLS (ECDSA P-256) | Secure element / TPM | Single unit; revocable by serial | Yes |
Weak JWT implementations are another common failure. If a backend accepts alg: none, signs tokens with a short shared secret recovered during firmware analysis, or skips checking the sub claim against the requested resource path, any attacker with one dumped device can forge requests for neighboring sensors.
#Mutual TLS (mTLS) for device identity
Standard HTTPS authenticates only the server. Mutual TLS (mTLS) in TLS 1.3 extends the handshake so the server requests a client certificate (CertificateRequest) and the device signs the handshake transcript with its private key (CertificateVerify). Because the private key never leaves the device, passive eavesdropping cannot replay the credential.
Authentication alone is not enough; authorization must bind to the verified certificate. If the MQTT broker trusts any certificate signed by the fleet CA without mapping the certificate Common Name (CN) or Subject Alternative Name (SAN) to an access control list (ACL), compromised sensor-042 can publish spoofed readings under sensor-001.
$ openssl x509 -in sensor-042.crt -noout -subject -issuer -dates
subject=CN = sensor-042.lab.local
issuer=CN = CyberSamSU Lab IoT Intermediate CA
notBefore=Nov 1 00:00:00 2026 GMT
notAfter=Nov 1 00:00:00 2027 GMT
$ openssl verify -CAfile fleet-ca-chain.pem sensor-042.crt
sensor-042.crt: OK
$ mosquitto_pub -h broker.lab.local -p 8883 \
--cafile fleet-ca-chain.pem \
--cert sensor-042.crt --key sensor-042.key \
-t "telemetry/sensor-042/temp" -m '{"celsius":22.4}'If sensor-042 attempts to publish to telemetry/sensor-001/temp, a properly configured broker rejects the PUBLISH packet even though the TLS handshake succeeded.
#Signed OTA updates and rollback protection
Relying solely on HTTPS for OTA updates leaves a critical gap: TLS protects the link between the device and the distribution server, not the firmware image at rest. If an attacker compromises the storage bucket, injects a proxy on an internal network, or rewrites flash staging memory, the device will boot unverified code.
Following the IETF SUIT architecture (RFC 9019), modern OTA systems separate transport from end-to-end manifest signing:
- Build ServerHash firmware (SHA-256) and build manifest
- Offline HSMSign manifest with Ed25519 or ECDSA P-256
- CDN / MirrorHost untrusted binary and signed manifest
- Device BootloaderVerify signature, check version > counter, verify hash
A secure OTA manifest binds four mandatory fields under one signature:
- Firmware digest: SHA-256 hash of the exact binary payload.
- Hardware/board ID: Prevents cross-flashing firmware meant for a different product revision.
- Monotonic version / security counter: Rejects any image whose security version is less than or equal to the value stored in protected non-volatile memory (anti-rollback protection). Without this check, an attacker can serve an old, validly signed firmware image that contains a known vulnerability.
- Target slot metadata: Supports A/B partitioning, where the new image writes to inactive slot B while slot A remains intact. On reboot, the bootloader boots slot B with a watchdog timer; if the new firmware fails health checks before confirming the update, the bootloader automatically reverts to slot A.
$ sha256sum firmware-v2.4.0.bin
9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 firmware-v2.4.0.bin
$ openssl dgst -sha256 -verify ota-signing-pub.pem -signature manifest.sig manifest.json
Verified OKNever verify a signature over a download URL or filename; verify the signature over the manifest containing the cryptographic hash of the downloaded bytes before flashing.
#Defending and common mistakes
- Plaintext private keys on the filesystem: Storing an mTLS private key in
/etc/ssl/device.keyon unencrypted flash allows physical cloning; wrap keys with a hardware root of trust or store them inside a TPM or secure element. - No certificate revocation or expiration plan: Issuing 30-year certificates with no revocation check leaves compromised devices permanently trusted; use short-lived certificates with automated renewal or OCSP/CRL checks.
- Unbound MQTT permissions: Allowing any valid fleet certificate to subscribe to
#or publish to any topic lets one breached node spoof or eavesdrop on the entire fleet. - Missing anti-rollback checks: Validating the signature without checking a monotonic security counter allows downgrade attacks to older vulnerable releases.
- Deprecated cryptography: Never deploy TLS 1.0/1.1, RSA-1024, or SHA-1 signatures in new firmware; standardize on TLS 1.3 with ECDSA P-256 or Ed25519 and SHA-256.
#Summary
Strong IoT security replaces shared secrets and trust-on-header designs with per-device X.509 credentials verified via mTLS and bound directly to server-side ACLs. Protecting firmware updates requires end-to-end signed manifests verified against an offline public key, SHA-256 integrity checks over the payload, monotonic anti-rollback counters, and A/B partition failover. Together, these controls ensure a single compromised node cannot impersonate its peers or hijack the update pipeline.