Back to Blog
Security

Zero-Trust Security for Embedded IoT: Why Your Devices Are Probably Vulnerable

Most IoT security breaches happen because of decisions made in the first week of a project. Learn the zero-trust security model for embedded systems — from device attestation to TLS certificate rotation.

March 1, 2024
14 min read
IoT SecurityTLSmTLSZero-Trust

Zero-Trust Security for Embedded IoT: Why Your Devices Are Probably Vulnerable

We've audited a lot of IoT systems. The pattern is almost always the same: security was treated as a final step, bolted on after the core functionality was working. By then, the architecture made proper security nearly impossible without a rewrite.

This guide is about doing it right from day one.

The Zero-Trust Model for IoT

Zero-trust means: never trust, always verify. For IoT:

  • Every device has a unique identity (not shared credentials)
  • Every message is authenticated and encrypted
  • Every device has minimum necessary permissions
  • Compromise of one device doesn't compromise others
  • Step 1: Device Identity — The Foundation

    The most common mistake: using the same password/API key on every device.

    X.509 Certificate-Based Identity

    Each device gets a unique certificate signed by your Certificate Authority:

    Generate device-specific certificate

    openssl genrsa -out device-001.key 2048 openssl req -new -key device-001.key -out device-001.csr \ -subj "/CN=device-001/O=CodeCaracal/OU=IoT Fleet"

    Sign with your CA (or AWS IoT CA)

    openssl x509 -req -in device-001.csr \ -CA ca.crt -CAkey ca.key \ -CAcreateserial -out device-001.crt \ -days 365

    Embed at flash time, not at runtime. The certificate is part of the build artifact for that specific device.

    Step 2: mTLS — Mutual Authentication

    Standard TLS authenticates the server. mTLS authenticates both sides.

    // ESP32: configure mTLS
    WiFiClientSecure client;
    client.setCACert(rootCA);        // Trust this CA
    client.setCertificate(devCert);  // Our identity
    client.setPrivateKey(devKey);    // Prove it

    // The broker now verifies BOTH sides // A fake device without a valid cert gets rejected at the TLS layer

    On the broker side (AWS IoT Core, Mosquitto with TLS):

    mosquitto.conf

    listener 8883 cafile /etc/mqtt/ca.crt certfile /etc/mqtt/server.crt keyfile /etc/mqtt/server.key require_certificate true # Enforce mTLS use_identity_as_username true

    Step 3: Least-Privilege MQTT Policies

    Devices should only publish to their own topic, and only subscribe to their own command topic.

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": "iot:Publish",
          "Resource": "arn:aws:iot:us-east-1:*:topic/devices/${iot:ClientId}/telemetry"
        },
        {
          "Effect": "Allow",
          "Action": "iot:Subscribe",
          "Resource": "arn:aws:iot:us-east-1:*:topicfilter/devices/${iot:ClientId}/commands"
        }
      ]
    }
    

    The ${iot:ClientId} variable ensures device-001 can't publish to device-002's topic.

    Step 4: Secure OTA — Don't Ship Untrusted Code

    OTA without signature verification is a remote code execution vulnerability.

    bool verifyFirmwareSignature(const uint8_t* firmware, size_t len, const uint8_t* sig) {
      // Verify ECDSA signature using your public key
      mbedtls_ecdsa_context ctx;
      mbedtls_ecdsa_init(&ctx);

    // Load your OTA signing public key (embedded at compile time) mbedtls_ecp_point_read_binary(&ctx.grp, &ctx.Q, OTA_PUBLIC_KEY, sizeof(OTA_PUBLIC_KEY));

    uint8_t hash[32]; mbedtls_sha256(firmware, len, hash, 0);

    int result = mbedtls_ecdsa_read_signature(&ctx, hash, 32, sig, sigLen); mbedtls_ecdsa_free(&ctx);

    return result == 0; }

    Never flash firmware that fails signature verification.

    Step 5: Certificate Rotation

    Certificates expire. Build rotation into your architecture from the start.

    Automated rotation with AWS IoT

    // Lambda function triggered 30 days before cert expiry
    async function rotateCertificate(deviceId) {
      // Issue new cert
      const newCert = await iot.createKeysAndCertificate({ setAsActive: true }).promise()

    // Attach policy await iot.attachPolicy({ policyName: 'IoTDevicePolicy', target: newCert.certificateArn }).promise()

    // Deliver new cert via shadow (device will pick up on next connection) await iotData.updateThingShadow({ thingName: deviceId, payload: JSON.stringify({ state: { desired: { newCertificate: newCert.certificatePem, newPrivateKey: newCert.keyPair.PrivateKey, rotateBy: new Date(Date.now() + 7 * 86400000).toISOString() } } }) }).promise() }

    Security Audit Checklist

    Before shipping any IoT system:

  • Every device has unique X.509 certificate (no shared credentials)
  • mTLS enforced on all broker connections
  • MQTT policies use least-privilege (device-specific topics only)
  • Firmware OTA signed with ECDSA
  • Firmware signature verified before flashing
  • Certificate expiry monitored and rotation automated
  • Device can be remotely revoked (certificate policy detached)
  • Secrets never stored in plaintext (use ESP32 NVS with encryption)
  • Physical JTAG/UART debug disabled on production builds
  • Security audit performed before fleet deployment
  • The Cost of Getting This Wrong

    Mirai botnet. Verkada breach. Ubiquiti. These aren't abstract risks — they're documented incidents where basic IoT security failures led to device compromise at scale.

    The cost of doing this right at design time? A few days of architecture work.

    The cost of retrofitting security into 10,000 deployed devices? Potentially a full product recall.

    Need help auditing or architecting your IoT security? [Talk to our team](/contact) — we've built zero-trust IoT systems for clients across 15+ countries.

    Written by CodeCaracal Engineering

    We write from production experience — every technique in our articles has been deployed to real clients. No academic theory.

    More Articles

    Business · 12 min read

    IoT Device Compliance: FCC, CE, and Product Certification Guide for Hardware Startups

    Business · 11 min read

    What to Look for When Hiring an IoT Development Partner: 8 Critical Criteria

    Business · 11 min read

    IoT MVP to Production: Realistic Timeline and Budget for Hardware Startups

    Business · 11 min read

    IoT Development Agency vs Building In-House: A Decision Framework for Founders

    IoT Dashboard · 13 min read

    Next.js IoT Analytics Dashboard: From Sensor Data to Production App

    Business · 11 min read

    How Much Does It Cost to Build an IoT Product in 2024? A Realistic Breakdown

    IoT Dashboard · 11 min read

    IoT Dashboard UX: Design Principles for Industrial Monitoring Interfaces

    IoT Dashboard · 12 min read

    Node.js WebSocket Server: The Real-Time Backend for IoT Dashboards

    Cloud & DevOps · 12 min read

    Containerizing IoT Backend Services with Docker: From Dev to Production

    IoT Dashboard · 14 min read

    Grafana + InfluxDB IoT Monitoring: Complete Production Setup Guide

    IoT Dashboard · 12 min read

    Building Real-Time IoT Dashboards with React and Recharts

    Cloud & DevOps · 13 min read

    CI/CD for Embedded Firmware: Automated Build, Test, and OTA Release Pipeline

    Mobile Development · 12 min read

    Flutter Offline-First IoT Apps: Hive + Sync Architecture That Works in the Field

    Cloud & DevOps · 14 min read

    Terraform for IoT Infrastructure: Provisioning AWS IoT Core, Lambda, and InfluxDB as Code

    Mobile Development · 10 min read

    Flutter IoT Alerts: Firebase Push Notifications for Device Events

    Cloud & DevOps · 12 min read

    Deploying IoT Backends on AWS: ECS Fargate vs Lambda vs EC2 Decision Guide

    Mobile Development · 11 min read

    Flutter + MQTT: Building Production IoT Mobile Apps That Scale

    Mobile Development · 13 min read

    Flutter BLE: Building a Bluetooth IoT Controller App from Scratch

    Cloud & DevOps · 13 min read

    AWS IoT Core vs Azure IoT Hub vs Google Cloud IoT: 2024 Honest Comparison

    IoT Engineering · 13 min read

    Kafka vs RabbitMQ for IoT: Choosing the Right Message Queue for High-Volume Telemetry

    IoT Engineering · 14 min read

    IoT System Testing: Unit, Integration, Hardware-in-the-Loop, and End-to-End

    IoT Engineering · 14 min read

    Predictive Maintenance with IoT Sensor Data: From Threshold to Machine Learning

    Embedded Systems · 14 min read

    IoT Bootloader Design: Secure Boot, A/B Partitions, and Reliable OTA Recovery

    IoT Engineering · 14 min read

    Multi-Tenant IoT Platform Architecture: Isolation, Scaling, and Data Partitioning

    Embedded Systems · 14 min read

    Memory Management in Embedded Firmware: Avoiding Heap Fragmentation and Stack Overflows

    IoT Engineering · 13 min read

    IoT Cost Optimization: How We Cut AWS IoT Bills by 60% Without Sacrificing Reliability

    IoT Engineering · 12 min read

    Edge Computing in IoT: When to Process On-Device vs In the Cloud

    IoT Engineering · 13 min read

    Digital Twins for IoT: Building a Virtual Mirror of Your Physical Devices

    Embedded Systems · 14 min read

    ESP32 Deep Sleep Mastery: Cutting Power Consumption from 240mA to 10µA

    IoT Engineering · 10 min read

    MQTT QoS 0, 1, and 2 Explained: Choosing the Right Level for IoT

    IoT Engineering · 14 min read

    IoT Monitoring and Observability: Metrics, Logs, and Distributed Tracing

    Embedded Systems · 14 min read

    Debugging Embedded Firmware: JTAG, GDB, Logic Analyzers, and Serial Tracing

    IoT Engineering · 12 min read

    WebSocket vs MQTT vs Server-Sent Events: Real-Time IoT Protocol Deep Dive

    Embedded Systems · 13 min read

    STM32 HAL vs Low-Level Drivers: When the Abstraction Costs You Too Much

    IoT Engineering · 13 min read

    IoT Data Pipeline: From Raw Sensor Reading to Live Dashboard in Under 100ms

    IoT Engineering · 13 min read

    Zero-Touch IoT Device Provisioning: Scaling from 10 to 100,000 Devices

    Embedded Systems · 13 min read

    UART vs SPI vs I2C: Choosing the Right Protocol for Sensor Integration

    IoT Engineering · 12 min read

    Real-Time IoT Alerting: From Simple Thresholds to ML Anomaly Detection

    Embedded Systems · 12 min read

    ESP32 Partition Table: Designing Flash Layout for Production Firmware

    IoT Engineering · 12 min read

    IoT Architecture Patterns: Hub-and-Spoke, Mesh, and Edge-Cloud Hybrid

    Embedded Systems · 13 min read

    IoT Battery Life Optimization: Engineering Devices That Last Years on a Single Charge

    IoT Engineering · 13 min read

    Time-Series Databases for IoT: InfluxDB vs TimescaleDB vs AWS Timestream

    Embedded Systems · 14 min read

    FreeRTOS on ESP32: Task Scheduling, Queues, and Resource Management for IoT

    IoT Engineering · 12 min read

    Building a Production IoT Gateway with Raspberry Pi and Node.js

    Embedded Systems · 13 min read

    ESP32 vs STM32: Choosing the Right Microcontroller for Your IoT Project

    Mobile Development · 10 min read

    Flutter + WebSocket: Building Real-Time IoT Dashboards That Don't Stutter

    IoT Engineering · 13 min read

    IoT Fleet Management at Scale: AWS IoT Core Device Registry and Provisioning

    IoT Engineering · 11 min read

    MQTT vs HTTP for IoT: Which Protocol Wins in Production?

    IoT Engineering · 12 min read

    ESP32 → MQTT → AWS IoT Core: The Production-Grade Architecture Guide

    Let's Build Together

    Got an IoT challenge?
    We've shipped it.

    Whether you need a fleet to track, a factory to monitor, or a farm to automate — our team has done it before and we'd love to build it with you. Typical response time: under 24 hours.

    No upfront commitment99.9% uptime SLANDA on requestFixed-price options