services/tfm/overview.html · services/tfm/overview.rst 공식 원문 ↗

Zephyr 3.7.0 · TF-M · Security Architecture

Trusted Firmware-M Overview

Secure boot에서 secure service와 Zephyr application까지 신뢰 경계를 단계적으로 세웁니다.

Official pathservices/tfm/overview.html
Source fileservices/tfm/overview.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

TF-M 2.1.0 통합의 RoT hierarchy, 세 isolation level, MCUboot, PSA IPC, storage와 key lifecycle을 설명합니다.

Trust

PRoT · ARoT

Boundary

SPE · NSPE

Secrets

ITS · HUK · derived keys

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 BD89A229AFCEE7128599A4EA2195A5CA85D9A7A994268D44E840D30CE8FEDF21
Trusted Firmware-M Overview
###########################

`Trusted Firmware-M (TF-M) <https://tf-m-user-guide.trustedfirmware.org/>`__
is a reference implementation of the Platform Security Architecture (PSA)
`IoT Security Framework <https://www.psacertified.org/what-is-psa-certified/>`__.
It defines and implements an architecture and a set of software components
that aim to address some of the main security concerns in IoT products.

Zephyr RTOS has been PSA Certified since Zephyr 2.0.0 with TF-M 1.0, and
is currently integrated with TF-M 2.1.0.

What Does TF-M Offer?
*********************

Through a set of secure services and by design, TF-M provides:

* Isolation of secure and non-secure resources
* Embedded-appropriate crypto
* Management of device secrets (keys, etc.)
* Firmware verification (and encryption)
* Protected off-chip data storage and retrieval
* Proof of device identity (device attestation)
* Audit logging

Build System Integration
************************

When using TF-M with a supported platform, TF-M will be automatically built and
link in the background as part of the standard Zephyr build process. This
build process makes a number of assumptions about how TF-M is being used, and
has certain implications about what the Zephyr application image can and can
not do:

* The secure processing environment (secure boot and TF-M) starts first
* Resource allocation for Zephyr relies on choices made in the secure image.

Architecture Overview
*********************

A TF-M application will, generally, have the following three parts, from most
to least trusted, left-to-right, with code execution happening in the same
order (secure boot > secure image > ns image).

While the secure bootloader is optional, it is enabled by default, and secure
boot is an important part of providing a secure solution:

::

    +-------------------------------------+           +--------------+
    | Secure Processing Environment (SPE) |           |     NSPE     |
    | +----------++---------------------+ |           | +----------+ |
    | |          ||                     | |           | |          | |
    | | bl2.bin  ||  tfm_s_signed.bin   | |           | |zephyr.bin| |
    | |          ||                     | | <- PSA -> | |          | |
    | |  Secure  || Trusted Firmware-M  | |    APIs   | |  Zephyr  | |
    | |   Boot   ||   (Secure Image)    | |           | |(NS Image)| |
    | |          ||                     | |           | |          | |
    | +----------++---------------------+ |           | +----------+ |
    +-------------------------------------+           +--------------+

Communication between the (Zephyr) Non-Secure Processing Environment (NSPE) and
the (TF-M) Secure Processing Environment image happens based on a set of PSA
APIs, and normally makes use of an IPC mechanism that is included as part of
the TF-M build, and implemented in Zephyr
(see :zephyr_file:`modules/trusted-firmware-m/interface`).

Root of Trust (RoT) Architecture
================================

TF-M is based upon a **Root of Trust (RoT)** architecture. This allows for
hierarchies of trust from most, to less, to least trusted, providing a sound
foundation upon which to build or access trusted services and resources.

The benefit of this approach is that less trusted components are prevented from
accessing or compromising more critical parts of the system, and error
conditions in less trusted environments won't corrupt more trusted, isolated
resources.

The following RoT hierarchy is defined for TF-M, from most to least trusted:

* PSA Root of Trust (**PRoT**), which consists of:

  * PSA Immutable Root of Trust: secure boot
  * PSA Updateable Root of Trust: most trusted secure services
* Application Root of Trust (**ARoT**): isolated secure services

The **PSA Immutable Root of Trust** is the most trusted piece of code in the
system, to which subsequent Roots of Trust are anchored. In TF-M, this is the
secure boot image, which verifies that the secure and non-secure images are
valid, have not been tampered with, and come from a reliable source. The
secure bootloader also verifies new images during the firmware update process,
thanks to the public signing key(s) built into it. As the name implies,
this image is **immutable**.

The **PSA Updateable Root of Trust** implements the most trusted secure
services and components in TF-M, such as the Secure Partition Manager (SPM),
and shared secure services like PSA Crypto, Internal Trusted Storage (ITS),
etc. Services in the PSA Updateable Root of Trust have access to other
resources in the same Root of Trust.

The **Application Root of Trust** is a reduced-privilege area in the secure
processing environment which, depending on the isolation level chosen when
building TF-M, has limited access to the PRoT, or even other ARoT services at
the highest isolation levels. Some standard services exist in the ARoT, such as
Protected Storage (PS), and generally custom secure services that you implement
should be placed in the ARoT, unless a compelling reason is present to place
them in the PRoT.

These divisions are distinct from the **untrusted code**, which runs in the
non-secure environment, and has the least privilege in the system. This is the
Zephyr application image in this case.

Isolation Levels
----------------

At present, there are three distinct **isolation levels** defined in TF-M,
with increasingly rigid boundaries between regions. The isolation level used
will depend on your security requirements, and the system resources available
to you.

* **Isolation Level 1** is the lowest isolation level, and the only major
  boundary is between the secure and non-secure processing environment,
  usually by means of Arm TrustZone on Armv8-M processors. There is no
  distinction here between the PSA Updateable Root of Trust (PRoT) and the
  Application Root of Trust (ARoT). They execute at the same privilege level.
  This isolation level will lead to the smallest combined application images.
* **Isolation Level 2** builds upon level one by introducing a distinction
  between the PSA Updateable Root of Trust and the Application Root of Trust,
  where ARoT services have limited access to PRoT services, and can only
  communicate with them through public APIs exposed by the PRoT services.
  ARoT services, however, are not strictly isolated from one another.
* **Isolation Level 3** is the highest isolation level, and builds upon level
  2 by isolating ARoT services from each other, so that each ARoT is
  essentially silo'ed from other services. This provides the highest level of
  isolation, but also comes at the cost of additional overhead and code
  duplication between services.

The current isolation level can be checked via
:kconfig:option:`CONFIG_TFM_ISOLATION_LEVEL`.

Secure Boot
===========

The default secure bootloader in TF-M is based on
`MCUBoot <https://www.mcuboot.com/>`__, and is referred to as ``BL2`` in TF-M
(for the second-stage bootloader, potentially after a HW-based bootloader on
the secure MCU, etc.).

All images in TF-M are hashed and signed, with the hash and signature verified
by MCUBoot during the firmware update process.

Some key features of MCUBoot as used in TF-M are:

* Public signing key(s) are baked into the bootloader
* S and NS images can be signed using different keys
* Firmware images can optionally be encrypted
* Client software is responsible for writing a new image to the secondary slot
* By default, uses static flash layout of two identically-sized memory regions
* Optional security counter for rollback protection

When dealing with (optionally) encrypted images:

* Only the payload is encrypted (header, TLVs are plain text)
* Hashing and signing are applied over the un-encrypted data
* Uses ``AES-CTR-128`` or ``AES-CTR-256`` for encryption
* Encryption key randomized every encryption cycle (via ``imgtool``)
* The ``AES-CTR`` key is included in the image and can be encrypted using:

  * ``RSA-OAEP``
  * ``AES-KW`` (128 or 256 bits depending on the ``AES-CTR`` key length)
  * ``ECIES-P256``
  * ``ECIES-X25519``

Key config properties to control secure boot in Zephyr are:

* :kconfig:option:`CONFIG_TFM_BL2` toggles the bootloader (default = ``y``).
* :kconfig:option:`CONFIG_TFM_KEY_FILE_S` overrides the secure signing key.
* :kconfig:option:`CONFIG_TFM_KEY_FILE_NS` overrides the non-secure signing key.

Secure Processing Environment
=============================

Once the secure bootloader has finished executing, a TF-M based secure image
will begin execution in the **secure processing environment**. This is where
our device will be initially configured, and any secure services will be
initialised.

Note that the starting state of our device is controlled by the secure firmware,
meaning that when the non-secure Zephyr application starts, peripherals may
not be in the HW-default reset state. In case of doubts, be sure to consult
the board support packages in TF-M, available in the ``platform/ext/target/``
folder of the TF-M module (which is in ``modules/tee/tf-m/trusted-firmware-m/``
within a default Zephyr west workspace.)

Secure Services
---------------

As of TF-M 1.8.0, the following secure services are generally available (although vendor support may vary):

* Crypto
* Firmware Update (FWU)
* Initial Attestation
* Platform
* Secure Storage, which has two parts:

  * Internal Trusted Storage (ITS)
  * Protected Storage (PS)

A template also exists for creating your own custom services.

For full details on these services, and their exposed APIs, please consult the
`TF-M Documentation <https://tf-m-user-guide.trustedfirmware.org/>`__.

Key Management and Derivation
-----------------------------

Key and secret management is a critical part of any secure device. You need to
ensure that key material is available to regions that require it, but not to
anything else, and that it is stored securely in a way that makes it difficult
to tamper with or maliciously access.

The **Internal Trusted Storage** service in TF-M is used by the **PSA Crypto**
service (which itself makes use of mbedtls) to store keys, and ensure that
private keys are only ever accessible to the secure processing environment.
Crypto operations that make use of key material, such as when signing payloads
or when decrypting sensitive data, all take place via key handles. At no point
should the key material ever be exposed to the NS environment.

One exception is that private keys can be provisioned into the secure
processing environment as a one-way operation, such as during a factory
provisioning process, but even this should be avoided where possible, and a
request should be made to the SPE (via the PSA Crypto service) to generate a
new private key itself, and the public key for that can be requested during
provisioning and logged in the factory. This ensures the private key
material is never exposed, or even known during the provisioning phase.

TF-M also makes extensive use of the **Hardware Unique Key (HUK)**, which
every TF-M device must provide. This device-unique key is used by the
**Protected Storage** service, for example, to encrypt information stored in
external memory. For example, this ensures that the contents of flash memory
can't be decrypted if they are removed and placed on a new device, since each
device has its own unique HUK used while encrypting the memory contents
the first time.

HUKs provide an additional advantage for developers, in that they can be used
to derive new keys, and the **derived keys** don't need to be stored since
they can be regenerated from the HUK at startup, using an additional salt/seed
value (depending on the key derivation algorithm used). This removes the
storage issue and a frequent attack vector. The HUK itself it usually highly
protected in secure devices, and inaccessible directly by users.

``TFM_CRYPTO_ALG_HUK_DERIVATION`` identifies the default key derivation
algorithm used if a software implementation is used. The current default
algorithm is ``HKDF`` (RFC 5869) with a SHA-256 hash. Other hardware
implementations may be available on some platforms.

Non-Secure Processing Environment
=================================

Zephyr is used for the NSPE, using a board that is supported by TF-M where the
:kconfig:option:`CONFIG_BUILD_WITH_TFM` flag has been enabled.

Generally, you simply need to select the ``*_ns`` variant of a valid target
(for example ``mps2_an521_ns``), which will configure your Zephyr application
to run in the NSPE, correctly build and link it with the TF-M secure images,
sign the secure and non-secure images, and merge the three binaries into a
single ``tfm_merged.hex`` file. The :ref:`west flash <west-flashing>` command
will flash ``tfm_merged.hex`` by default in this configuration.

At present, Zephyr can not be configured to be used as the secure processing
environment.

Part 3

한국어 전문 번역

Trusted Firmware-M(TF-M)은 PSA(Platform Security Architecture) IoT Security Framework의 reference implementation입니다. IoT product에서 반복되는 secure boot, secret 보관, firmware 신뢰성, device identity 같은 문제를 architecture와 reusable software component로 해결합니다.

Zephyr RTOS는 Zephyr 2.0.0과 TF-M 1.0 조합부터 PSA Certified를 받았고, 이 Zephyr 3.7.0 문서는 TF-M 2.1.0 통합을 기준으로 합니다.

What Does TF-M Offer?

TF-M은 설계된 isolation boundary와 secure service를 통해 다음 기능을 제공합니다.

  • Secure resource와 non-secure resource의 격리
  • Embedded system에 적합한 cryptography
  • Key 같은 device secret의 관리
  • Firmware 검증과 선택 encryption
  • Off-chip data의 보호된 저장·복원
  • Initial attestation을 통한 device identity 증명
  • Audit logging

Build System Integration

지원 platform의 _ns target을 선택하면 standard Zephyr build가 TF-M을 external project로 자동 build하고 link합니다. 그 대신 secure processing environment가 먼저 시작하고, Zephyr가 쓸 flash·RAM·peripheral은 secure image가 정한 allocation에 의존합니다.

따라서 non-secure application은 hardware reset 직후의 모든 resource를 마음대로 소유한다고 가정할 수 없습니다. TF-M board support가 먼저 security attribution과 secure service를 초기화한 뒤 Zephyr로 제어를 넘깁니다.

Architecture Overview

일반적인 system은 신뢰도가 높은 순서이자 실행 순서대로 secure boot, TF-M secure image, Zephyr non-secure image의 세 부분으로 구성됩니다. Secure bootloader는 선택 기능이지만 기본으로 활성화되며 secure solution의 신뢰 사슬을 시작합니다.

신뢰도와 실행 순서
BL2 · Secure Boot가장 먼저 실행 · image hash와 signature 검증
verified handoff
TF-M Secure ImageSPE · SPM · secure services · secrets
PSA APIs · IPC
Zephyr NS ImageNSPE · application · least privilege

Zephyr가 실행되는 NSPE와 TF-M이 실행되는 SPE 사이 통신은 PSA API를 사용합니다. 보통 TF-M build에 포함된 IPC mechanism과 Zephyr의 modules/trusted-firmware-m/interface 구현이 호출을 경계 너머 secure partition으로 전달합니다.

Root of Trust (RoT) Architecture

Root of Trust는 가장 신뢰할 수 있는 작은 기반에서 덜 신뢰하는 component로 신뢰를 단계적으로 확장하는 구조입니다. 덜 신뢰받는 component가 더 중요한 resource를 직접 읽거나 손상하지 못하게 하며, 낮은 계층의 오류가 높은 계층으로 번지는 것을 막습니다.

TF-M의 계층은 PSA Root of Trust(PRoT)와 Application Root of Trust(ARoT)로 나뉩니다. PRoT에는 immutable secure boot와 update 가능한 핵심 secure service가 있고, ARoT에는 더 낮은 privilege로 격리된 application secure service가 있습니다.

PSA Immutable Root of Trust는 system에서 가장 신뢰받는 code입니다. TF-M에서는 secure boot image가 secure·non-secure image의 출처, hash, signature와 변조 여부를 검증하고 firmware update 때도 내장 public key로 새 image를 확인합니다. 이름처럼 현장 update 대상이 아닌 immutable anchor입니다.

PSA Updateable Root of Trust는 Secure Partition Manager(SPM), PSA Crypto, Internal Trusted Storage(ITS) 같은 핵심 service를 구현합니다. 같은 PRoT 안의 service는 서로의 resource에 접근할 수 있습니다.

Application Root of Trust는 SPE 안에서도 privilege를 줄인 영역입니다. 선택한 isolation level에 따라 PRoT 또는 다른 ARoT service 접근이 제한됩니다. Protected Storage(PS)와 application-specific custom secure service는 보통 ARoT에 두며, 특별한 이유가 있을 때만 PRoT에 둡니다.

이 secure 계층과 별도로 Zephyr application은 non-secure environment의 untrusted code로 취급되며 system에서 가장 낮은 privilege를 가집니다.

Isolation Levels

TF-M는 resource 비용과 security boundary 강도가 다른 세 isolation level을 제공합니다. 현재 level은 CONFIG_TFM_ISOLATION_LEVEL로 확인합니다.

  1. Level 1: Armv8-M TrustZone으로 SPE와 NSPE만 크게 나눕니다. PRoT와 ARoT는 같은 privilege에서 실행하므로 image가 가장 작습니다.
  2. Level 2: PRoT와 ARoT를 분리합니다. ARoT는 PRoT가 공개한 API로만 핵심 service에 접근하지만 ARoT service끼리는 완전히 격리되지 않습니다.
  3. Level 3: 각 ARoT service까지 서로 silo로 격리합니다. 가장 강한 isolation을 제공하지만 context, memory와 중복 code overhead가 늘어납니다.

Secure Boot

TF-M의 기본 secure bootloader는 MCUboot 기반이며 TF-M에서는 second-stage bootloader라는 뜻으로 BL2라 부릅니다. 모든 image는 hash와 signature를 가지며 MCUboot가 boot/update 과정에서 검증합니다.

  • Public signing key는 bootloader image에 내장됩니다.
  • Secure(S)와 non-secure(NS) image에 서로 다른 key를 쓸 수 있습니다.
  • Firmware payload를 선택적으로 encryption할 수 있습니다.
  • Client software가 새 image를 secondary slot에 씁니다.
  • 기본 layout은 크기가 같은 primary·secondary 영역을 사용합니다.
  • Security counter로 rollback protection을 적용할 수 있습니다.

Encrypted image에서도 header와 TLV는 plaintext이고 payload만 암호화됩니다. Hash와 signature는 encryption 전 data에 적용됩니다. Payload encryption은 AES-CTR-128 또는 AES-CTR-256을 사용하며 imgtool이 매 encryption cycle마다 key를 새로 만듭니다.

Image에 포함되는 AES-CTR key 자체는 RSA-OAEP, AES-KW-128/256, ECIES-P256 또는 ECIES-X25519로 감쌀 수 있습니다. CONFIG_TFM_BL2가 bootloader를 켜고, CONFIG_TFM_KEY_FILE_S와 CONFIG_TFM_KEY_FILE_NS가 secure·non-secure signing key를 교체합니다.

Secure Processing Environment

BL2가 검증과 handoff를 끝내면 TF-M secure image가 SPE에서 실행되어 device security attribution과 secure service를 초기화합니다. 이 때문에 Zephyr NS image가 시작할 때 peripheral이 hardware-default reset 상태가 아닐 수 있습니다.

의심되는 resource 초기 상태는 Zephyr workspace의 modules/tee/tf-m/trusted-firmware-m/platform/ext/target/ 아래 TF-M board support package에서 확인합니다.

Secure Services

TF-M 1.8.0 기준 일반적으로 Crypto, Firmware Update(FWU), Initial Attestation, Platform, Internal Trusted Storage(ITS), Protected Storage(PS)가 제공됩니다. Vendor platform에 따라 지원 범위가 달라질 수 있고 custom service template도 있습니다.

Key Management and Derivation

Secure device는 key material을 필요한 secure component에만 제공하고 NSPE에는 노출하지 않아야 합니다. TF-M의 ITS는 mbed TLS를 사용하는 PSA Crypto의 key를 보관합니다. Sign·decrypt 같은 operation은 key handle로 요청하며 private key byte는 non-secure environment로 나오지 않습니다.

Factory provisioning 중 private key를 SPE에 한 방향으로 넣을 수는 있지만 가능하면 피합니다. 더 안전한 방식은 PSA Crypto에 device 내부 key 생성을 요청하고 public key만 꺼내 factory record에 남기는 것입니다. 그러면 provisioning 담당 system조차 private key를 알지 못합니다.

모든 TF-M device는 Hardware Unique Key(HUK)를 제공해야 합니다. Protected Storage는 HUK를 이용해 external memory data를 암호화할 수 있으므로 flash chip을 다른 device로 옮겨도 device마다 다른 HUK 때문에 내용을 복호화할 수 없습니다.

HUK에서 salt 또는 seed와 key derivation algorithm으로 derived key를 다시 만들 수 있어 파생 key를 flash에 저장할 필요도 없습니다. HUK 자체는 높은 보호 수준에 두고 user가 직접 읽지 못하게 합니다. Software 기본 TFM_CRYPTO_ALG_HUK_DERIVATION은 RFC 5869 HKDF와 SHA-256이며 platform별 hardware 구현을 쓸 수도 있습니다.

Non-Secure Processing Environment

Zephyr는 TF-M 지원 board의 NSPE에서 실행됩니다. 일반적으로 mps2_an521_ns 같은 *_ns variant를 선택하면 CONFIG_BUILD_WITH_TFM, memory layout, image signing과 linking이 함께 설정됩니다.

Build는 BL2, TF-M secure image와 Zephyr NS image를 tfm_merged.hex로 합칩니다. 이 구성에서 west flash는 기본적으로 merged image를 board에 기록합니다. 현재 Zephyr 자체를 TF-M의 secure processing environment로 구성하는 방식은 지원되지 않습니다.

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.