Skip to main content
IoT Authentication, mTLS Device Identity & Signed OTA Updates
Lesson 7 of 9

IoT Authentication, mTLS Device Identity & Signed OTA Updates

Learn how to replace extractable shared secrets with mTLS device certificates, enforce broker topic authorization, and design cryptographically signed OTA updates with anti-rollback protection.

Advanced 26 min IoT & embedded
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Identify weaknesses in shared API keys, static device tokens, and unbound device identifiers
  • Configure and verify mutual TLS (mTLS) device authentication and MQTT topic authorization
  • Validate signed over-the-air (OTA) firmware manifests using SHA-256 digests and asymmetric signatures
  • Design anti-rollback and A/B partition recovery controls for safe fleet updates

Recommended first: IoT Networking Protocols: MQTT, CoAP & BLE SecurityEmulating IoT Binaries with QEMU & Auditing Hardcoded Secrets

#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.

MQTT over mTLS handshake and topic authorizationMQTT over mTLS handshake and topic authorizationDeviceBrokerClientHello (TLS 1.3)ServerHello + Certificate + CertificateRequestDevice Certificate + CertificateVerify + FinishedVerify CA chain and map SAN/CN to ACLDevice CN=sensor-042 allowed only on telemetry/sensor-042/#

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.

Inspecting a device certificate and testing mTLS in a lab
$ 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:

  1. Build ServerHash firmware (SHA-256) and build manifest
  2. Offline HSMSign manifest with Ed25519 or ECDSA P-256
  3. CDN / MirrorHost untrusted binary and signed manifest
  4. Device BootloaderVerify signature, check version > counter, verify hash

A secure OTA manifest binds four mandatory fields under one signature:

  1. Firmware digest: SHA-256 hash of the exact binary payload.
  2. Hardware/board ID: Prevents cross-flashing firmware meant for a different product revision.
  3. 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.
  4. 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.
Verifying an OTA payload digest and detached signature
$ 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 OK

Never 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.key on 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.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge