So you have a prototype. It works, it does what it was built to do, and you are ready to move to mass production. All this time you have been focused on the core functionality and solved a thousand engineering problems along the way. It is quite possible there was simply no time left for security. But it matters more than it may seem.
If your device has a microphone or a camera, or can receive or store any personal data at all, you as the manufacturer are obliged to protect that data. Not only for the user's sake and your own reputation, but because the law requires it.
And security is not something you can flash onto the device at the factory along with firmware that seems to work fine. It is made of decisions taken before you even pick a chip, and of processes that have to keep running for as long as anyone uses the device. First we will look at what you have to defend against, and then walk the whole path of a device, from concept to decommissioning.
Even a light bulb has something to lose
Let's look at a few examples.
An LED strip you can control from your phone and that pulses in time with music. A lovely device: it sets the mood for an evening or an occasion and makes a home feel cozier. But to hear the music, the strip has a microphone, and app control means it is connected to the network. So potentially it is a listening device that can hear you 24/7 and pass everything it hears to whoever has taken control of it.
A baby monitor with a camera. Parents want to see their child from their phone wherever they are, so the video from the nursery is reachable over the internet. If the device is poorly protected, it may not only be mom or dad watching.
A robot vacuum with a camera or lidar. To clean, it builds a map of your home, and the cleaning schedule makes it easy to work out when nobody is in. And when the vacuum is sold or given away, the map and the link to the previous owner's account often stay on the device.
An ordinary smart light bulb. No microphone, no camera, so it would seem there is nothing to protect. But to join the network, it stores your Wi-Fi password. The bulb burns out, you throw it in the trash, and the password is still in its memory. Taking the bulb apart and reading the memory out with a programmer is an hour's work for a hobbyist with a soldering iron. And whoever picked it out of your trash is already within range of your Wi-Fi.
Notice that in the last two examples the problem does not appear while the device is in use, but when it passes to someone else or goes for disposal. That is why security has to be thought about across the whole lifecycle.
The buyer trusts, but can't check
A manufacturer can build any malicious function into a device, and the buyer has practically no way to check for it themselves. So they build their trust in the manufacturer another way: on their own experience, reviews, brand reputation, independent tests and research. But none of those sources has checked the firmware of the specific device they are holding. That makes the manufacturer responsible for its users' security: not only for leaving out malicious functions, but for making sure nobody outside or even inside the company can use the device unlawfully.
There are countless ways to break into a device, but in most cases the malicious function first has to get inside along with the firmware. Take a hardware crypto wallet. It isn't connected to the internet, so a backdoor in it would be subtler than a "secret password": for example, the firmware generates the seed phrase not at random but with an algorithm the backdoor's author knows. From the outside everything works as usual, while the author can recover the keys of any wallet created by that firmware and take the money remotely.
How does firmware like that get inside? The simplest way: an employee builds it themselves, publishes it as an official update, uses the backdoor, and removes it in the next update. That is hard to trace, and the damage stays: the seed phrases created in the meantime remain predictable forever.
From repository to device: the chain of trust
Defending against that scenario takes several steps.
Step 1. Only the build server builds releases. Developers are not allowed to build releases themselves: a build server does it, taking the code straight from the repository. Then whatever is in the firmware is also in the code, and hiding a backdoor becomes much harder. That holds as long as every change goes through code review, release branch history can't be rewritten, the people with access to the build server are not the people writing the code, and third-party libraries are pinned by version and hash. Otherwise the backdoor gets in by bypassing the repository.
Step 2. Every firmware image is signed. But how do you know that the image the server built is the one that reaches the update server, and then the devices? You sign every build, and the device verifies the signature with a public key written at the factory into one-time programmable memory (OTP). One signature solves two problems: nobody can swap the image on the update server, and nobody can sign their own firmware without the private key.
Step 3. The key is stored where it can't be copied. But what guarantees the private key won't be copied off the build server? This is where you start thinking about storing it: a dedicated HSM, a cloud key management service (KMS) and so on. Each option has its pros and cons, but all of them protect the key from being copied, not from being used. Someone who breaks into a build server with access to the HSM won't steal the key, but will be able to sign their own firmware with it. That's why signing a release requires approval from several people (M-of-N), so no single person can ship a release alone.
Step 4. Every use of the key is visible. What remains is making sure the key isn't used outside the official pipeline. Every signature is recorded in a log kept out of reach of whoever signs, and the log is checked regularly: a signature with no matching build in the pipeline is an alarm. Approval stops abuse from happening, and the audit catches it if it does.
On the device side the chain is closed by secure boot: the device runs only firmware with a valid signature. And thanks to the process above, a valid signature means the firmware was built from the official repository, reviewed, and signed with a well-protected key. How this works for over-the-air updates is covered in our article on secure OTA updates.
When the attack targets the device, not the update
But OTA updates aren't the only way malicious firmware can reach a device.
You buy a wireless Bluetooth keyboard from a well-known brand in an online shop you've never heard of. Good price, and there's a free gift with the offer: a weather station. A nice device in its own right: it measures temperature and humidity in the room, gets readings from an outdoor sensor over Bluetooth, and downloads the forecast from the internet. Everything works perfectly, and you're happy.
But here is what actually happened. The keyboard is genuine, but its firmware has been replaced: the chip was fully erased and reflashed. Secure boot didn't help, because the key the device used to check its firmware lived in the same flash and disappeared with it. The new firmware keeps all of the keyboard's functionality and adds one more function: it connects over Bluetooth to a device chosen in advance and sends it everything you type. Remember the gift? The weather station is that device, and it's the one with internet access - think of the forecast. A while later, your messages, logins and passwords are in the attacker's hands.
A hardware root of trust
How do you protect against that? Remember step 2: the key has to live in memory that can't be rewritten. Now you can see why. The root of trust has to be anchored in the chip itself, not in flash that can be erased. Then the signature is checked by code fixed in silicon, and no amount of reflashing can switch that check off.
The obvious objection: what stops someone from erasing the chip and writing firmware that simply doesn't use secure boot? The fact that such firmware never gets control at all. At power-on, the first thing to run is a ROM bootloader built into the silicon by the chip vendor. It reads one-time programmable memory (OTP), where the secure boot flag and the hash of the public key are "burned" at the factory, and checks the signature of the bootloader in flash, which in turn checks the firmware. Erasing flash doesn't touch that memory, and a bit set to 1 can never go back. This is how the ESP32 works, for example, where that memory is called eFuse. For full protection, the factory also disables JTAG, restricts UART download mode, and turns on flash encryption, so the firmware can't be read out and copied.
On STM32 the mechanism is different: the chip shuts off external access (permanently, on the classic series), so it can no longer be erased or reflashed, and the signature is checked by its own secure bootloader.
Where even that isn't enough
But a hardware root of trust doesn't close every gap either. First, not every chip has one. On the nRF52, which you'll often find in wireless keyboards, a full erase (ERASEALL) wipes everything including the key, so our scenario really does work there. Second, even the best chip can simply be replaced: an attacker holding the board can desolder the microcontroller and fit a new, "clean" one. Third, the check itself can be bypassed. Fault injection attacks, which glitch the power supply for an instant, make the processor skip it, and that is exactly how secure boot was bypassed on early ESP32 revisions.
Against a swapped chip, or a chip without a root of trust, secure boot is no protection at all. Something else is needed.
Device identity: a passport that can't be forged
Device identity is what makes each device individually recognizable, in a way that is very hard to fake. We covered it in detail in a separate article; here is the essence.
At the factory, each device gets its own key pair. Ideally the private key is generated inside the chip or a secure element and never leaves it. The manufacturer signs the device's public key with its own key and writes the resulting certificate to the device - in effect, a passport with the manufacturer's stamp. To check the device, an app, a cloud service or a host sends it a random number (a challenge), and the device signs it and returns it with the certificate. The verifier can then see that the certificate was issued by the manufacturer and that the device really holds the key from that certificate. Forged firmware or a replacement chip doesn't have that key, and without the manufacturer's key you can't produce a certificate of your own.
So there is now one more private key - the certificate issuing key - and it needs the same care as the firmware signing key. If it leaks, fakes will get "genuine" passports and no check will tell them apart. And it is used during the manufacture of every single device, while the device is still on the line, which makes protecting the issuing process even harder. More on that in the "Factory" stage below.
And identity only works when someone actually checks it. The one who checks is whoever talks to the device and cares who is on the other end. That might be the manufacturer's cloud when the device connects to it, or a mobile app when the user adds a new device. Or another device in the same ecosystem: a Matter smart home hub, before adding a new bulb or sensor, checks that the new device's passport is genuine. If something doesn't add up, the device isn't allowed into the cloud, doesn't get updates, and the user sees a warning that the device isn't genuine.
That won't work with the keyboard from our example. A computer accepts any Bluetooth keyboard without asking for certificates, and the keyboard has no cloud. The only thing that could check it is the vendor's configuration software, and only if the user has installed it. So identity only protects where the check is genuinely built into the product, and that too has to be thought about at the design stage. It would be good, incidentally, if operating systems themselves learned to check the authenticity of connected devices. With AI, taking someone else's firmware apart and writing your own that reproduces every function of the original is becoming orders of magnitude cheaper, so attacks like our keyboard will soon stop being purely hypothetical.
The path of one device: from concept to decommissioning
Now let's put it all together and follow a single device along its path.
Stage 1. Threat analysis
Before you choose a chip, be honest with yourself about what exactly you are protecting, from whom, and what it will cost you if the protection fails. Everything else depends on the answer: the design, the cost of components, the processes at the factory. We walked through this step by step in our threat modeling guide.
It isn't only user data that needs protecting. There is also the device's function (a lock should open only for its owner), your keys and firmware, and, in the end, your whole fleet of devices, which could be turned into a botnet. Attackers vary too, and you've already met a few. The baby monitor gets hacked by someone on the other side of the world who automatically scans the internet for devices with weak passwords. The password from the discarded bulb is extracted by a curious neighbor with a soldering iron. The keyboard is faked by someone with a lab, for whom cracking one unit is enough to start churning out fakes. The backdoor in the wallet is added by the manufacturer's own employee. Sometimes it's the buyer who breaks their own device: to unlock paid features without a subscription, to tamper with a meter, or to find a vulnerability that will then work on thousands of other people's devices. And, of course, anyone with access to the production line.
The cost of failure decides how much effort all of this is worth. For a bulb, the worst case is a stranger on your home network; for a wallet, lost money; for a lock, an open door. Nobody expects a light bulb to resist glitching, while a hardware wallet is expected to hold up even against attacks with lab equipment.
A threat analysis isn't written once and put in a drawer. It is revisited when the product changes or new attacks appear, and every later decision relies on it. That is exactly what the CRA requires: a risk assessment that underpins how you meet the requirements of Annex I.
Stage 2. Design
Security can't be added at the factory if it wasn't designed into the hardware, and most decisions made at this stage can't be changed later.
Start with the chip. You need a hardware root of trust or a separate secure element, and if you have neither, you should at least be honest with yourself about what the device is not protected against. Decide on the keys straight away: one for signing firmware, a separate one for issuing certificates, and separate ones for development. A production key on a developer's board is, in effect, already a leak. And settle who will check the device's authenticity, and when: the cloud, an app or another device. Otherwise identity stays a passport nobody ever asks to see.
Think about the day a key does leak, too. How many keys can be written to the chip, and can one of them be revoked? If there is only one slot, a leaked key means sharing control of every device you have sold with whoever has the key. Some chips (the ESP32-S3, for example) let you write several keys and revoke a compromised one.
The remaining decisions are about how the device will live from then on. Two firmware partitions (A/B) or a recovery mode, so a failed update doesn't brick it, and a version counter against rollback. A place for user data that can be encrypted and reliably erased. And the support period: however many years you will be shipping updates, that is how long the keys and all the infrastructure around them have to last.
Stage 3. Factory
"Flashing the firmware" is the smallest part of what happens on the production line. A typical sequence:
- Test firmware and hardware checks.
- Writing the production firmware, already signed with your key.
- Burning the OTP memory: the public key hash plus the flags that enable secure boot and flash encryption.
- Locking debug access for good. Steps 3 and 4 are done by the firmware itself on first boot, not by the station.
- Generating identity: the locked device creates its own key pair, your server issues a certificate for the public key, and the certificate is written to the device.
- Final check: is the device really locked, does it run only signed firmware, and does it pass the identity check.
It's obvious that a device left unlocked goes on sale wide open. What's less obvious: if identity is generated before the device is locked, the private key sits for a while in a chip that a debugger can still connect to. Anyone with access to the line only has to read it out to put a copy of a genuine device's passport into a fake that is indistinguishable from the original. So the key must only ever appear in a device that is already locked. A secure element, from which the key can't be read under any circumstances, closes that window in hardware.
What's more, stealing the key isn't even necessary. Someone could generate their own key pair on an ordinary computer and submit the public key for certification as if it came from a device. The server has no idea where the key came from and will issue a genuine certificate. Two things protect against this: a certificate quota reconciled against the number of devices ordered, and attestation from the chip. A chip that supports this (not all do) signs the new key with its own key, written by the chip vendor, proving that the key was born inside a genuine protected chip. The server only certifies keys with that attestation.
The same goes for test firmware. Until the device is locked, it will run anything, and swapped-in firmware can quietly write someone else's key into a spare OTP slot, which the device will then trust forever. The station software can be swapped too. So only one thing really protects you: not relying on the station at all. The device locks itself on the first boot of your firmware, revokes foreign and unused key slots, and only then creates its identity, while the certificate for it is issued by your server. Best of all is when the secure element arrives on the line already holding a key from the chip vendor: then there is simply nothing on the line to steal. In this setup, the station is just a cable between the device and your server. And it's still worth spot-checking finished devices in-house: whether they're locked, which key is in OTP, and which firmware they run.
The firmware signing key never goes to the factory at all: the line receives an image that is already signed. The firmware's factory mode, through which the certificate is written, only accepts commands signed by your server and is permanently disabled after provisioning. And boards that fail testing are destroyed or accounted for, so they don't end up on the market unlocked.
Stage 4. First power-on
The box is open and the device is being linked to an account. This is the first chance to check that the user has received a genuine device: the app or the cloud asks for its identity, and this is where a fake should be filtered out.
An "admin" password that is the same on every device is a banned practice. Either the device has unique credentials, or it makes the user set their own during first setup. And it should check for updates straight away: it may have sat in a warehouse for a year, and a year is long enough for more than one vulnerability to be found in its firmware.
Stage 5. Operation and updates
Every update goes through the same chain of trust from repository to device, and the device won't roll back to an older version. But a signature only guarantees that the firmware is yours, not that it is free of bugs. A vulnerability may turn up in your own code, but more often it is found in third-party libraries (the network stack, Bluetooth, TLS), and they usually make up more of the firmware than your own code does. So you need to know what each version is made of (SBOM), track new CVEs, and ship fixes in time.
Meanwhile, the keys live for years. If the HSM fails and there is no backup, you will never ship an update again. So the key is copied in advance to a second, backup HSM through a separate secure procedure: it can't be extracted from that one either, but now it is much harder to lose. And for a leak you need a plan ready: revoke the key, switch to the spare, and ship an update signed with the new one.
Stage 6. Repair and resale
A device comes back for repair with the user's data on it, and the service engineer would like to unlock debug access to diagnose it. But any unlock mechanism will sooner or later be found by people it wasn't meant for. So unlocking has to require permission signed by the manufacturer for that specific device, and has to wipe the user's data. So that the customer doesn't have to start from scratch after the repair, the data can be saved beforehand into an encrypted backup that only the same device can restore. And the repaired device goes through the same steps as a new one at the factory.
Resale is simple on paper. A factory reset has to genuinely erase all data and unlink the device from the cloud account. Incidentally, from December 2027 the CRA will require giving users a way to remove their data securely and permanently, although it doesn't say how. In practice the most reliable approach is to encrypt the data with a key and destroy only that key on reset. It takes an instant, so a power cut can't leave the wipe half done, and any old copies that might remain in flash can no longer be read without the key.
Stage 7. Decommissioning
That same reset is the last thing that should happen to a device before disposal. And when the owner removes the device from their account as decommissioned, the manufacturer revokes its certificate, so nobody can reuse that device's identity.
It's harder with devices nobody throws away. They will keep working after you stop shipping updates. Be honest with users that no more updates are coming, and think ahead about what happens when you switch off the cloud: does the device become a brick, or is there at least a local mode left?
What lies beyond the device
Even a perfectly protected device is only part of the product. Data can leak through the backend or the mobile app: for example, baby monitor videos stored in the cloud with a simple misconfiguration in the access settings. And if someone finds that misconfiguration and writes to you, there has to be a person in the company who takes the report, deals with it and, if needed, notifies the regulator, as the CRA requires. And everything described above also has to be documented: the risk assessment, the decisions taken, and why. Under the CRA, that is part of the technical documentation.
How to build all of this
So far we have talked about what has to happen to the device. Now for what you need to have in place to make it happen. None of the above comes in a single box: some of it you buy, some you configure, some you write yourself, and then you maintain it for years. Below is a rough stack for a small manufacturer. Product names are examples, not recommendations.
What to buy
First of all, an HSM for the signing key. It can be in the cloud (AWS KMS or CloudHSM, Azure Key Vault or Managed HSM, Google Cloud KMS) or physical (Thales Luna, Entrust nShield, Utimaco, while a small team can manage with a YubiHSM 2 or Nitrokey HSM). One isn't enough; you need a backup too. And the root key is best kept offline, in a separate HSM or on a smart card in a safe.
Choose carefully: this is a choice for years. A key born in an HSM usually never leaves it, so you can only change vendor with a new key, and your devices will only accept it if a slot was left for it in the chip.
Next, components for the device itself: a chip with a hardware root of trust or a separate secure element, which adds to the cost of every unit. For each production line, a provisioning station: a computer, programmers, a fixture to connect the board, and a secure channel to your certificate server. And services: CI, a cloud for updates and the device registry, and a vulnerability tracking tool.
What to configure
Each of these pieces still has to be configured:
- in the repository: protected branches, mandatory code review, and no rewriting of history;
- in CI: isolated servers for release builds, pinned compiler and dependency versions (in Docker images, for example), and a separate signing stage with manual approval;
- a bootloader that checks signatures: the chip vendor's or MCUboot, but with your keys, rollback protection and A/B partitions;
- PKI for identity: an offline root certificate authority and an issuing CA that signs certificates during manufacturing, either in the cloud (AWS Private CA, Google Certificate Authority Service) or self-hosted (EJBCA, step-ca, HashiCorp Vault, or your own service with its key in Azure Key Vault);
- updates and fleet management: Mender, Eclipse hawkBit, Memfault, AWS IoT Jobs, Azure Device Update and the like;
- SBOM generation at build time (Syft, the CycloneDX tools, built-in SPDX support in Zephyr and Yocto) and a tracker such as Dependency-Track;
- HSM or KMS audit logs in storage that the people who sign can't reach, with alerts on suspicious signatures.
Once you choose a cloud provider, you are tied to it for as long as your devices live: you can't take a key out of a KMS or a cloud CA, and devices that already fetch updates from one service won't move to another on their own. On top of that, the provider can simply shut a service down, and that has already happened to cloud IoT platforms.
What you'll have to write yourself
This is where most of the work hides, because the ready-made pieces aren't connected to each other. For example, the espsecure and imgtool utilities can sign through an HSM, but wiring that into CI, adding multi-person approval, and reconciling the signing log against builds is up to you.
You'll also have to write the factory part of the firmware yourself: the test mode, key generation on an already locked device, writing the certificate, disabling factory mode. And the provisioning station software that walks the line through each step, keeps a log, and produces reports to reconcile against the order. Plus a backend with a registry of devices and certificates that issues certificates only within the order quota, checks identity when a device is linked, revokes certificates, unlinks the device on reset, and transfers it to a new owner. And a secure service mode for repairs.
And what you'll have to maintain
New CVEs appear every day, and they have to be checked against every firmware version still running on devices. With every release: signing approval, log reconciliation, staged rollout. Every few months: a review of who has access to the keys, a check of backups, a key leak fire drill, and a fresh look at the threat analysis.
And some things only show up years later. Certificates have to outlive the devices they're on. The compiler and dependencies have to be archived, so that five years from now you can still rebuild an old version with a security fix instead of discovering the toolchain no longer exists. HSMs and cloud services change their APIs and prices. And the people who set all this up leave the company and take their knowledge with them.
Sounds like a separate product you'll have to build and maintain alongside your main one? That's exactly what it is. To see how ready you already are, go through a short list.
Is your device ready for production?
- The threat analysis is documented and regularly reviewed, and every security decision rests on a specific threat
- Releases are built only by the build server from the repository, with mandatory code review
- Every firmware image is signed, and the device checks the signature with a key in immutable memory and doesn't allow rollback to older versions
- Firmware can be updated over the air: the device checks for updates right after first power-on, a failed update doesn't brick it, and new versions roll out in stages
- The signing key is kept in an HSM or KMS, separately from the certificate issuing key and development keys; releases are signed with multi-person approval, and the signing log is reconciled against the pipeline
- There is a backup of the key, a spare slot in the chip, and a plan for a leak
- Every firmware version has an SBOM, new CVEs are checked daily, and there is someone to receive vulnerability reports
- At the factory, debug access is locked before identity is generated, and the firmware signing key never goes there
- The factory station is not trusted: the device locks itself, certificates are issued by your server only within the order quota and only for keys with chip attestation, and finished devices are spot-checked in your own lab
- Every device has a unique identity, and it is decided who checks it: the cloud, an app or a hub
- No device leaves the factory with a shared password or key: each has its own credentials (a certificate, a code on a sticker, a unique password) or receives them during first setup
- The service mode for repairs requires permission signed by the manufacturer and wipes the user's data
- A reset genuinely erases user data and unlinks the device from the account, and on decommissioning the device's certificate is revoked
- The support period is defined, along with what happens to the device after it ends
This is exactly the path we are trying to make simpler. At Platanor we are building a platform that takes over manufacturing, updates, key management and SBOM-based vulnerability analysis. Then a manufacturer doesn't have to assemble this stack alone and maintain it for years: you focus on your product, and the chain of trust from repository to decommissioned device works as one system.
If you are getting a device ready for production right now and want to get through this path without surprises, get in touch. If you want to see where your product stands today, the CRA Readiness Check is free and takes 20-40 minutes.
FAQ
Is secure boot enough to protect firmware? No. Secure boot only guarantees that the device runs firmware with a valid signature. What that signature is worth depends on your release process and on how the key is protected. It protects against a full reflash only when it rests on a hardware root of trust, and it doesn't protect against a swapped chip at all.
Does the CRA require secure boot? Not directly. The words "secure boot" don't appear in the regulation. But from December 2027 the CRA will require protecting the integrity of firmware and configuration against unauthorized changes, and for embedded devices secure boot is the most common way to do that. How exactly you meet the requirement is your call, based on your risk assessment.
How is device identity different from secure boot? Secure boot answers the question "is this our code?"; device identity answers "is this our device?". The first protects against foreign firmware, the second against a counterfeit device, even if the firmware on it looks genuine.
Why a secure element if the chip already has a hardware root of trust? The root of trust in the chip protects against foreign firmware. A secure element protects the identity key even against physical attacks, and it can also arrive with a key written by the chip vendor, so the key never appears at your factory at all.
Cloud KMS or your own HSM? A cloud KMS is quicker to set up and needs no hardware of your own. But it ties you to the provider for as long as your devices live. Your own HSM costs more and needs procedures around it: a backup HSM, access control, physical security. In return, the key stays entirely in your hands. For a small team, the cloud or a compact USB HSM is often enough.
What should I do if the signing key leaks? Revoke the compromised key, switch to the spare, and ship an update signed with the new one. That works cleanly only if a spare key slot was designed into the chip. With a single slot you don't lose control, but you now share it with whoever has the key, because the chip will keep trusting it. You can soften the blow with an update, still signed with the old key, that makes the firmware accept further updates only if they are also signed with a new key. That closes the official update channel to the attacker, but not physical access: a device in someone's hands will still boot anything signed with the leaked key.
How many years do I have to ship updates? The CRA will require at least five years, or the expected period of use if the device is designed to be used for less. But in practice devices stay in service longer, so the keys, the update servers, and the people who know how all of it works need to last at least as long.
Sources: CRA Regulation (EU) 2024/2847 - Article 13 (risk assessment, support period), Article 14 (reporting), Annex I Part I; ETSI EN 303 645 - requirements on default passwords; Delegated Regulation (EU) 2022/30 under the RED; GDPR (EU) 2016/679.
Denys Zaliznyak is the CTO of Platanor. Platanor builds secure firmware and device security architecture for IoT and hardware manufacturers.
