Skip to content

Commit 33979a9

Browse files
supreetd21espressif-bot
authored andcommitted
Docs: Secure boot v2 support for ESP32-S2
1 parent e640e14 commit 33979a9

File tree

6 files changed

+96
-26
lines changed

6 files changed

+96
-26
lines changed

docs/conf_common.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@
155155
'api-guides/RF_calibration.rst',
156156
'api-reference/system/ipc.rst',
157157
'security/secure-boot-v1.rst',
158-
'security/secure-boot-v2.rst',
159158
'api-reference/peripherals/secure_element.rst',
160159
'hw-reference/esp32/**'] + LEGACY_DOCS
161160

docs/en/api-guides/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ API Guides
3131
:esp32: RF Calibration <RF_calibration>
3232
ROM debug console <romconsole>
3333
:esp32: Secure Boot <../security/secure-boot-v1>
34-
:esp32: Secure Boot V2 <../security/secure-boot-v2>
34+
Secure Boot V2 <../security/secure-boot-v2>
3535
Thread Local Storage <thread-local-storage>
3636
Tools <tools/index>
3737
ULP Coprocessor <ulp>

docs/en/api-guides/unit-tests.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ Some old ways of disabling unit tests for targets, that have obvious disadvantag
170170
- Test item: some items that will be performed on some targets, but skipped on other
171171
targets. E.g.
172172

173-
There are three test items SD 1-bit, SD 4-bit and SDSPI. For ESP32S2, which doesn't have
174-
SD host, among the tests only SDSPI is enabled on ESP32S2.
173+
There are three test items SD 1-bit, SD 4-bit and SDSPI. For ESP32-S2, which doesn't have
174+
SD host, among the tests only SDSPI is enabled on ESP32-S2.
175175

176176
- Test implementation: some code will always happen, but in different ways. E.g.
177177

docs/en/security/secure-boot-v1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Secure Boot
44
.. important::
55

66
All references in this document are related to Secure Boot V1 (The AES based Secure Boot Scheme). ESP32 Revision 3 onwards, the preferred secure boot scheme is :doc:`Secure Boot V2 <secure-boot-v2>`.
7-
Please refer to Secure Boot V2 document for ESP32 Revision 3 or ESP32S2.
7+
Please refer to Secure Boot V2 document for ESP32 Revision 3 or ESP32-S2.
88

99
Secure Boot is a feature for ensuring only your code can run on the chip. Data loaded from flash is verified on each reset.
1010

docs/en/security/secure-boot-v2.rst

Lines changed: 91 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ Secure Boot V2
33

44
.. important::
55

6-
The references in this document are related to Secure Boot v2, the preferred scheme from ESP32-ECO3 onwards and in ESP32S2. (Refer to :doc:`Secure Boot <secure-boot-v1>` for ESP32)
7-
6+
The references in this document are related to Secure Boot V2, the preferred scheme from ESP32-ECO3 onwards and in ESP32-S2.
7+
8+
.. only:: esp32
9+
10+
Refer also to :doc:`Secure Boot <secure-boot-v1>` for ESP32.
11+
812
Secure Boot V2 uses RSA based app and bootloader verification. This document can also be referred for signing apps with the RSA scheme without signing the bootloader.
913

1014
Background
1115
----------
1216

13-
Secure Boot protects a device from running unsigned code (verification at time of load). A new RSA based secure boot
14-
verification scheme (Secure Boot V2) has been introduced for ESP32S2 and ESP32 ECO3 onwards.
17+
Secure Boot protects a device from running unsigned code (verification at time of load). A new RSA based secure boot
18+
verification scheme (Secure Boot V2) has been introduced for ESP32-S2 and ESP32 ECO3 onwards.
1519

1620
- The software bootloader’s RSA-PSS signature is verified by the Mask ROM and it is executed post successful verification.
1721
- The verified software bootloader verifies the RSA-PSS signature of the application image before it is executed.
@@ -21,9 +25,13 @@ Advantages
2125

2226
- The RSA public key is stored on the device. The corresponding RSA private key is kept secret on a server and is never accessed by the device.
2327

24-
- Upto three public keys can store can be generated and stored in ESP32S2 during manufacturing. (ESP32 ECO3: only one key)
28+
- Up to three public keys can be generated and stored in ESP32-S2 during manufacturing. (ESP32 ECO3: only one key)
29+
30+
.. only:: esp32
2531

26-
- ESP32S2 also provides the facility to revoke individual public keys.
32+
- ESP32-S2 provides the facility to permanently revoke individual public keys. This can be configured conservatively or aggressively.
33+
34+
- Conservatively - The old key is revoked after the bootloader and application have successfully migrated to a new key. Aggressively - The key is revoked as soon as verification with this key fails.
2735

2836
- Same image format & signature verification is applied for applications & software bootloader.
2937

@@ -37,7 +45,7 @@ This is an overview of the Secure Boot V2 Process, Step by step instructions are
3745

3846
1. Secure Boot V2 verifies the signature blocks appended to the bootloader and application binaries. The signature block contains the image binary signed by a RSA-3072 private key and its corresponding public key. More details on the :ref:`signature-block-format`.
3947

40-
2. On startup, ROM code checks the secure boot v2 bit in eFuse.
48+
2. On startup, ROM code checks the Secure Boot V2 bit in eFuse.
4149

4250
3. If secure boot is enabled, ROM checks the SHA-256 of the public key in the signature block in the eFuse.
4351

@@ -88,9 +96,9 @@ The remainder of the signature sector is erased flash (0xFF) which allows writin
8896
Verifying the signature Block
8997
-----------------------------
9098

91-
A signature block is “valid” if the first byte is 0xe7 and a valid CRC32 is stored at offset 1196. Upto 3 signature blocks can be appended to the bootloader or application image in ESP32S2. (ESP32 ECO3: only one key)
99+
A signature block is “valid” if the first byte is 0xe7 and a valid CRC32 is stored at offset 1196. Upto 3 signature blocks can be appended to the bootloader or application image in ESP32-S2. (ESP32 ECO3: only one key)
92100

93-
An image is “verified” if the public key stored in any signature block is valid for this device, and if the stored signature is valid for the image data read from flash.
101+
An image is “verified” if the public key stored in any signature block is valid for this device, and if the stored signature is valid for the image data read from flash.
94102

95103
1. The magic byte, signature block CRC is validated.
96104

@@ -100,10 +108,10 @@ An image is “verified” if the public key stored in any signature block is va
100108

101109
4. The public key is used to verify the signature of the bootloader image, using RSA-PSS (section 8.1.2 of RFC8017) with the image digest calculated in step (3) for comparison.
102110

103-
- The application signing scheme is set to RSA for secure boot V2 and to ECDSA for secure boot V1.
111+
- The application signing scheme is set to RSA for Secure Boot V2 and to ECDSA for Secure Boot V1.
104112

105113
.. important::
106-
It is recommended to use secure boot V2 on the chip versions supporting them.
114+
It is recommended to use Secure Boot V2 on the chip versions supporting them.
107115

108116
.. _secure-boot-v2-bootloader-size:
109117

@@ -133,25 +141,46 @@ Options to work around this are:
133141
eFuse usage
134142
-----------
135143

136-
ESP32-ECO3:
144+
.. only:: esp32
145+
146+
ESP32-ECO3:
147+
148+
- ABS_DONE_1 - Enables secure boot protection on boot.
149+
150+
- BLK2 - Stores the SHA-256 digest of the public key. SHA-256 hash of public key modulus, exponent, precalculated R & M’ values (represented as 776 bytes – offsets 36 to 812 - as per the :ref:`signature-block-format`) is written to an eFuse key block.
137151

138-
- ABS_DONE_1 - Enables secure boot protection on boot.
152+
.. only:: esp32s2
139153

140-
- BLK2 - Stores the SHA-256 digest of the public key. SHA-256 hash of public key modulus, exponent, precalculated R & M’ values (represented as 776 bytes – offsets 36 to 812 - as per the :ref:`signature-block-format`) is written to an eFuse key block.
154+
- SECURE_BOOT_EN - Enables secure boot protection on boot.
141155

156+
- KEY_PURPOSE_X - Set the purpose of the key block on ESP32-S2 by programming SECURE_BOOT_DIGESTX (X = 0, 1, 2) into KEY_PURPOSE_X (X = 0, 1, 2, 3, 4). Example: If KEY_PURPOSE_2 is set to SECURE_BOOT_DIGEST1, then BLOCK_KEY2 will have the Secure Boot V2 public key digest.
157+
158+
- BLOCK_KEYX - The block contains the data corresponding to its purpose programmed in KEY_PURPOSE_X. Stores the SHA-256 digest of the public key. SHA-256 hash of public key modulus, exponent, precalculated R & M’ values (represented as 776 bytes – offsets 36 to 812 - as per the :ref:`signature-block-format`) is written to an eFuse key block.
159+
160+
- KEY_REVOKEX - The revocation bits corresponding to each of the 3 key block. Ex. Setting KEY_REVOKE2 revokes the key block whose key purpose is SECURE_BOOT_DIGEST2.
161+
162+
- SECURE_BOOT_AGGRESSIVE_REVOKE - Enables aggressive revocation of keys. The key is revoked as soon as verification with this key fails.
142163

143164
.. _secure-boot-v2-howto:
144165

145166
How To Enable Secure Boot V2
146167
----------------------------
147168

148-
1. Open the :ref:`project-configuration-menu`, in "Security Features" set "Enable hardware Secure Boot in bootloader" to enable Secure Boot. The chip revision should be changed to revision 3(ESP32- ECO3) to view the Secure Boot V2 option.
169+
1. Open the :ref:`project-configuration-menu`, in "Security Features" set "Enable hardware Secure Boot in bootloader" to enable Secure Boot.
170+
171+
.. only:: esp32
149172

150-
2. To change the chip revision, set "Minimum Supported ESP32 Revision" to Rev 3 in "Component Config" -> "ESP32- Specific", the Secure Boot V2 option can be enabled under "Enable hardware Secure Boot in bootloader" -> "Secure Boot Version". Secure Boot V2 is available for ESP32 ECO3 onwards and in ESP32S2.
173+
2. For ESP32, Secure Boot V2 is available only ESP32 ECO3 onwards. To view the "Secure Boot V2" option the chip revision should be changed to revision 3 (ESP32- ECO3). To change the chip revision, set "Minimum Supported ESP32 Revision" to Rev 3 in "Component Config" -> "ESP32- Specific".
151174

152-
3. Specify the secure boot signing key path. The file can be anywhere on your system. A relative path will be evaluated from the project directory. The file does not need to exist yet.
175+
3. Specify the secure boot signing key path. The file can be anywhere on your system. A relative path will be evaluated from the project directory. The file does not need to exist yet.
153176

154-
4. Set other menuconfig options (as desired). Pay particular attention to the "Bootloader Config" options, as you can only flash the bootloader once. Then exit menuconfig and save your configuration
177+
.. only:: esp32s2
178+
179+
2. The "Secure Boot V2" option will be selected and the "App Signing Scheme" would be set to RSA by default.
180+
181+
3. Select the number of keys to be used to sign the bootloader binary and chose one of them to sign the application. Specify the secure boot signing key paths for each one of these. The file can be anywhere on your system. A relative path will be evaluated from the project directory. The file does not need to exist yet.
182+
183+
4. Set other menuconfig options (as desired). Pay particular attention to the "Bootloader Config" options, as you can only flash the bootloader once. Then exit menuconfig and save your configuration.
155184

156185
5. The first time you run ``make`` or ``idf.py build``, if the signing key is not found then an error message will be printed with a command to generate a signing key via ``espsecure.py generate_signing_key``.
157186

@@ -169,11 +198,11 @@ How To Enable Secure Boot V2
169198

170199
.. note:: ``idf.py flash`` doesn't flash the bootloader if secure boot is enabled.
171200

172-
9. Reset the ESP32 and it will boot the software bootloader you flashed. The software bootloader will enable secure boot on the chip, and then it verifies the app image signature and boots the app. You should watch the serial console output from the ESP32 to verify that secure boot is enabled and no errors have occurred due to the build configuration.
201+
9. Reset the {IDF_TARGET_NAME} and it will boot the software bootloader you flashed. The software bootloader will enable secure boot on the chip, and then it verifies the app image signature and boots the app. You should watch the serial console output from the {IDF_TARGET_NAME} to verify that secure boot is enabled and no errors have occurred due to the build configuration.
173202

174203
.. note:: Secure boot won't be enabled until after a valid partition table and app image have been flashed. This is to prevent accidents before the system is fully configured.
175204

176-
.. note:: If the ESP32 is reset or powered down during the first boot, it will start the process again on the next boot.
205+
.. note:: If the {IDF_TARGET_NAME} is reset or powered down during the first boot, it will start the process again on the next boot.
177206

178207
10. On subsequent boots, the secure boot hardware will verify the software bootloader has not changed and the software bootloader will verify the signed app image (using the validated public key portion of its appended signature block).
179208

@@ -227,6 +256,48 @@ Secure Boot Best Practices
227256
* Enable all secure boot options in the Secure Boot Configuration. These include flash encryption, disabling of JTAG, disabling BASIC ROM interpeter, and disabling the UART bootloader encrypted flash access.
228257
* Use secure boot in combination with :doc:`flash encryption<flash-encryption>` to prevent local readout of the flash contents.
229258

259+
.. only:: esp32s2
260+
261+
Key Management
262+
--------------
263+
264+
* Between 1 and 3 RSA-3072 public keypairs (Keys #0, #1, #2) should be computed independently and stored separately.
265+
* The KEY_DIGEST efuses should be write protected after being programmed.
266+
* The unused KEY_DIGEST slots must have their corresponding KEY_REVOKE efuse burned to permanently disable them. This must happen before the device leaves the factory.
267+
* The eFuses can either be written by the software bootloader during during first boot after enabling "Secure Boot V2" from menuconfig or can be done using `espefuse.py` which communicates with the serial bootloader program in ROM.
268+
* The KEY_DIGESTs should be numbered sequentially beginning at key digest #0. (ie if key digest #1 is used, key digest #0 should be used. If key digest #2 is used, key digest #0 & #1 must be used.)
269+
* The software bootloader (non OTA upgradeable) is signed using at least one, possibly all three, private keys and flashed in the factory.
270+
* Apps should only be signed with a single private key (the others being stored securely elsewhere), however they may be signed with multiple private keys if some are being revoked (see Key Revocation, below).
271+
272+
Multiple Keys
273+
-------------
274+
275+
* The bootloader should be signed with all the private key(s) that are needed for the life of the device, before it is flashed.
276+
* The build system can sign with at most one private key, user has to run manual commands to append more signatures if necessary.
277+
* You can use the append functionality of ``espsecure.py``, this command would also printed at the end of the Secure Boot V2 enabled bootloader compilation.
278+
espsecure.py sign_data -k secure_boot_signing_key2.pem -v 2 --append_signatures -o signed_bootloader.bin build/bootloader/bootloader.bin
279+
* While signing with multiple private keys, it is recommended that the private keys be signed independently, if possible on different servers and stored separately.
280+
* You can check the signatures attached to a binary using -
281+
espsecure.py signature_info_v2 datafile.bin
282+
283+
Key Revocation
284+
--------------
285+
286+
* Keys are processed in a linear order. (key #0, key #1, key #2).
287+
* Applications should be signed with only one key at a time, to minimise the exposure of unused private keys.
288+
* The bootloader can be signed with multiple keys from the factory.
289+
290+
Assuming a trusted private key (N-1) has been compromised, to update to new keypair (N).
291+
1. Server sends an OTA update with an application signed with the new private key (#N).
292+
2. The new OTA update is written to an unused OTA app partition.
293+
3. The new application's signature block is validated. The public keys are checked against the digests programmed in the eFuse & the application is verified using the verified public key.
294+
4. The active partition is set to the new OTA application's partition.
295+
5. Device resets, loads the bootloader (verified with key #N-1) which then boots new app (verified with key #N).
296+
6. The new app verifies bootloader with key #N (as a final check) and then runs code to revoke key #N-1 (sets KEY_REVOKE efuse bit).
297+
7. The API `esp_ota_revoke_secure_boot_public_key()` can be used to revoke the key #N-1.
298+
299+
* A similiar approach can also be used to physically reflash with a new key. For physical reflashing, the bootloader content can also be changed at the same time.
300+
230301
.. _secure-boot-v2-technical-details:
231302

232303
Technical Details

docs/zh_CN/api-guides/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ API 指南
2323
引导加载程序 <bootloader>
2424
分区表 <partition-tables>
2525
:esp32: Secure Boot <../security/secure-boot-v1>
26-
:esp32: Secure Boot V2 <../security/secure-boot-v2>
26+
Secure Boot V2 <../security/secure-boot-v2>
2727
ULP 协处理器 <ulp>
2828
:esp32: ULP (传统 GNU Make) <ulp-legacy>
2929
:esp32s2: ULP-RISC-V Coprocessor <ulp-risc-v>

0 commit comments

Comments
 (0)