Introduction:
The modern world is hyper-connected, a fact that makes it a prime target for cybercriminals, as it represents a global environment of devices they will want to access. The security of an embedded device is paramount to prevent hackers from controlling it, but these hackers could even prepare a more damaging attack on the device's connected systems. Remote attacks, however, are not their only weapon; local attacks on the physical hardware device are another way to obtain sensitive information. This type of attack includes accessing system authentication passwords and even the intellectual property of the application's code itself.

In this article, we'll review the basic concepts for achieving reliable and robust embedded security in an embedded microcontroller. We'll analyze security principles and take a close look at the attack surfaces and vectors used by malicious actors.

Image 1: In an IoT installation, when a single device is compromised, the entire system is open to the enemy (source: STMicroelectronics)

The importance of security should not be underestimated, regardless of the level of complexity added to the embedded system. Furthermore, the issue extends beyond protecting cryptographic keys or embedded firmware; it also includes protecting personal data. If a hacker gains access to a device's firmware, they could reverse engineer the code and, by understanding how it works, potentially uncover more vulnerabilities and introduce malicious code. Access to even a single unprotected device in an IoT system can compromise the entire installation (see Figure 1).


What We Need to Protect
Before analyzing security techniques, let's review and classify what we need to protect. Hackers target three different aspects of an IoT device. A target is an IoT device that we need to protect. An asset is the specific part of the target that requires protection. In Figure 2, we can see the assets we need to protect and the related risks within each target if it has been compromised. Regarding the implementation of embedded security techniques, this classification helps us select the appropriate method.

Image 2: The classification of objectives, assets, and related risks helps us determine the security methods we should implement (source: STMicroelectronics)


Types of Attacks:
Attacks against IoT devices can originate from various sources and, broadly speaking, can be divided into software and hardware attacks. Software attacks can occur locally or over a connected network, while hardware attacks can be further divided into invasive and non-invasive. A non-invasive attack takes place locally and, in some cases, only requires a power connection to the IoT device's printed circuit board.

On the other hand, an invasive hardware attack involves gaining electrical and physical access to the device's microcontroller. Generally, an invasive attack is the most expensive method, and the hacker needs specialized knowledge to carry it out. In Figure 3, we can see the three types of attacks mentioned, along with a summary of the techniques used and the reasons why a hacker might use them.

Image 3: Types of attacks and associated cost (source: STMicroelectronics)

Software attacks are usually the most common and consist of exploiting firmware flaws or known protocol weaknesses through the device's communication channels. These attacks are relatively inexpensive and easy to implement, as they are executed remotely. Furthermore, after discovering device vulnerabilities, hackers may share this knowledge within their community.

Security in Real-World Scenarios:
For a device manufacturer, it's important to understand the factors that contribute to security in order to assess which protective features will be necessary. The following three examples will illustrate some of these features. In the next section, we'll discuss many security features and how to implement them.

Example 1:
Imagine a company that sells firmware and whose primary source of revenue is licensing rights. This firmware is a valuable intellectual property (IP) asset and must be protected. Customers use the firmware in conjunction with application code. For the company, it is necessary to isolate the firmware from the customer's code. The company updates the firmware regularly, so it is also necessary to install and update the firmware securely. In this case, some of the necessary security features would be isolation, protection of the software's IP, and secure routines for firmware installation and updates.

Example 2:
IndustrialAdvantage sells production control equipment at a high price and wants to offer firmware updates to its customers. One of the conditions is that only IndustrialAdvantage firmware can be run on the supplied equipment. The update process must be careful and include authenticity checks. To ensure that the equipment only runs IndustrialAdvantage firmware, we can use the secure boot function. The secure installation and update function will allow us to perform integrity and authenticity checks. 

Example 3:
Consumer Tech manufactures devices to collect user data within a larger system. The company is meticulous and consistently compliant with consumer data regulations, such as the GDPR. Consumer Tech also wants to ensure that the device operates robustly and runs only the company's firmware. During device communication with the host system, there is a potential for user data to be exposed; the use of encryption techniques and device identification and authentication systems can prevent this vulnerability. Platform integrity is protected by a secure boot feature.


The security framework
: For embedded system developers, a comprehensive and robust set of security features for a device's microcontroller platform is essential. An example of this is the STM32Trust ecosystem for the STM32 series of microcontrollers from STMicroelectronics (see Figure 4).

Image 4: STM32Trust security feature ecosystem (source: STMicroelectronics)

The STM32Trust security features are used in the STM32L4 and STML5 series of microcontrollers, which are Arm PSA (Level 2) and SESIP (Level 3) certified. These security features can be embedded in the microcontroller's silicon or implemented as firmware and are associated with the corresponding device.

In the rest of the article, we will analyze two essential security features that are included in the STM32Trust ecosystem and which we have discussed in the previous examples: Secure Boot (SB) and Secure Install/Upgrade (SBSFU).


Secure Boot:
The basic principle of Secure Boot is that, when a device restarts, a Secure Boot code runs to verify the firmware's authenticity before allowing it to boot. This function relies on two parameters. First, the Secure Boot code is the only code that runs during the restart. Second, this code is immutable; that is, it cannot be modified in any way. The boot code's address is also unique, preventing access to a different firmware address during the restart. The combination of these two principles creates a root of trust for the device (see Figure 5).

Figure 5: Basic principle of the safe boot function (source: STMicroelectronics)

Integrity and authenticity checks are performed on the application firmware and compared against a signature. The integrity check compares a hash function (also called a digest) generated from the application code with a supplied reference. The authenticity check compares this with a signature computed from the generated hash value and a private key. The signature is then verified against an associated public key. The signature value and the reference hash value must be supplied with the firmware.

Typically, it is stored in a container called metadata or a header (see Figure 6). Due to its generation method, metadata does not require encryption. If malicious firmware were present, it would not be possible to match the firmware hash with the reference. In Figure 6, we can see the construction of the metadata signature using the private key and the firmware digest with the hash function.

Image6: Generation of the metadata signature (source: STMicroelectronics)

In Figure 7, the secure boot code uses the metadata signature to confirm the authenticity and integrity of the application firmware. If the signature verification results in valid firmware, the boot process begins loading the application code. If there are discrepancies between the application firmware and the signature, the boot process fails.

Image7: Validation of the application firmware by signing the metadata before loading the application (source: STMicroelectronics)


Secure Firmware Update
The most important steps in a firmware update are:
• creating the application firmware update,
• generating the associated metadata, and
• transmitting it to the target device.
• The Secure Boot function uses the metadata to verify the integrity and authenticity of the application firmware.
• If the verification is successful, the Secure Boot process installs the new firmware.

The new metadata signature is created using the same technique as for Secure Boot. On many remotely connected IoT/IIoT devices, the simplest transfer method is an over-the-air (OTA) update. Devices without an internet connection require a local connection, such as UART, SPI, USB, or a microSD card. The new application firmware is installed on flash memory in the target device using a loader, which is typically included in the Secure Boot code or the application firmware. The new firmware must be installed locally while the current firmware is running.

Figure 8 shows the remote firmware update process. Two memory slots are required, one for the current firmware and one for the new version. 

Image 8: Example of remote firmware update (source: STMicroelectronics)

The final stage of the update process involves checking the application's new firmware (see image 9). If the metadata check is successful, the current firmware is replaced with the new one. The update is now complete.


Conclusion:
Embedded security in devices is not optional. All devices must be protected against malicious attacks and potential vulnerabilities. Device security begins at startup, so it is vital to incorporate security features such as secure boot and secure firmware installation/updates. STM32Trust offers all the security features an embedded systems developer might need to protect their devices and comply with current regulations.

Article provided by Mouser Electronics