mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-02 01:50:58 +02:00
Merge branch 'bugfix/encrypt_len_for_sb_update_case' into 'master'
fix(bootloader): correct encryption length for secure update without secure boot See merge request espressif/esp-idf!41665
This commit is contained in:
@@ -1058,7 +1058,7 @@ menu "Security features"
|
|||||||
endmenu # Potentially Insecure
|
endmenu # Potentially Insecure
|
||||||
|
|
||||||
config SECURE_FLASH_ENCRYPT_ONLY_IMAGE_LEN_IN_APP_PART
|
config SECURE_FLASH_ENCRYPT_ONLY_IMAGE_LEN_IN_APP_PART
|
||||||
bool "Encrypt only the app image that is present in the partition of type app"
|
bool "Encrypt contents upto app image length in app partition"
|
||||||
depends on SECURE_FLASH_ENC_ENABLED && !SECURE_FLASH_REQUIRE_ALREADY_ENABLED
|
depends on SECURE_FLASH_ENC_ENABLED && !SECURE_FLASH_REQUIRE_ALREADY_ENABLED
|
||||||
default y
|
default y
|
||||||
help
|
help
|
||||||
|
@@ -225,6 +225,23 @@ typedef struct {
|
|||||||
uint8_t signature[64];
|
uint8_t signature[64];
|
||||||
} esp_secure_boot_sig_block_t;
|
} esp_secure_boot_sig_block_t;
|
||||||
|
|
||||||
|
/** @brief Get the size of the secure boot signature block
|
||||||
|
*
|
||||||
|
* This is the size of the signature block appended to a signed image.
|
||||||
|
*
|
||||||
|
* @return Size of the secure boot signature block in bytes
|
||||||
|
*/
|
||||||
|
static inline uint32_t esp_secure_boot_sig_block_size()
|
||||||
|
{
|
||||||
|
#if CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME || CONFIG_SECURE_SIGNED_APPS_ECDSA_V2_SCHEME
|
||||||
|
return sizeof(ets_secure_boot_signature_t);
|
||||||
|
#elif defined(CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME)
|
||||||
|
return sizeof(esp_secure_boot_sig_block_t);
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/** @brief Verify the ECDSA secure boot signature block for Secure Boot V1.
|
/** @brief Verify the ECDSA secure boot signature block for Secure Boot V1.
|
||||||
*
|
*
|
||||||
* Calculates Deterministic ECDSA w/ SHA256 based on the SHA256 hash of the image. ECDSA signature
|
* Calculates Deterministic ECDSA w/ SHA256 based on the SHA256 hash of the image. ECDSA signature
|
||||||
|
@@ -428,6 +428,10 @@ static esp_err_t encrypt_partition(int index, const esp_partition_info_t *partit
|
|||||||
if (partition->type == PART_TYPE_APP && should_encrypt) {
|
if (partition->type == PART_TYPE_APP && should_encrypt) {
|
||||||
// Encrypt only the app image instead of encrypting the whole partition
|
// Encrypt only the app image instead of encrypting the whole partition
|
||||||
size = image_data.image_len;
|
size = image_data.image_len;
|
||||||
|
#if CONFIG_SECURE_SIGNED_ON_UPDATE_NO_SECURE_BOOT
|
||||||
|
// If secure update without secure boot, also encrypt the signature block
|
||||||
|
size += esp_secure_boot_sig_block_size();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (partition->type == PART_TYPE_PARTITION_TABLE) {
|
} else if (partition->type == PART_TYPE_PARTITION_TABLE) {
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
# SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
# SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
||||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from pytest_embedded import Dut
|
from pytest_embedded import Dut
|
||||||
from pytest_embedded_idf.utils import idf_parametrize
|
from pytest_embedded_idf.utils import idf_parametrize
|
||||||
@@ -9,6 +10,14 @@ from pytest_embedded_idf.utils import idf_parametrize
|
|||||||
@idf_parametrize('target', ['esp32c2', 'esp32c3'], indirect=['target'])
|
@idf_parametrize('target', ['esp32c2', 'esp32c3'], indirect=['target'])
|
||||||
def test_examples_security_on_update_no_secure_boot(dut: Dut) -> None:
|
def test_examples_security_on_update_no_secure_boot(dut: Dut) -> None:
|
||||||
dut.expect(
|
dut.expect(
|
||||||
"This app is not signed, but check signature on update is enabled in config. It won't be possible to verify any update.",
|
"This app is not signed, but check signature on update is enabled in config. It won't be possible to verify any update.", # noqa : E501
|
||||||
timeout=10,
|
timeout=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.host_test
|
||||||
|
@pytest.mark.qemu
|
||||||
|
@pytest.mark.parametrize('config', ['secure_update_with_fe'], indirect=True)
|
||||||
|
@idf_parametrize('target', ['esp32c3'], indirect=['target'])
|
||||||
|
def test_examples_secure_update_with_fe_qemu(dut: Dut) -> None:
|
||||||
|
dut.expect('Example for secured signed with no secure boot', timeout=60)
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
CONFIG_SECURE_FLASH_ENC_ENABLED=y
|
||||||
|
CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES=y
|
||||||
|
CONFIG_PARTITION_TABLE_OFFSET=0xc000
|
||||||
|
CONFIG_NVS_ENCRYPTION=n
|
@@ -0,0 +1,39 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIG5AIBAAKCAYEA5sRBdVlob0RWwRsBYrGrMmdhIbam45boFbD/1skxb7lRhJjE
|
||||||
|
pStZ5DVhtQWVAsqTKkY/QH0zzRBBSfdnsneBAc3yFBTBrMPBQitOvg2UK5rx3jJ2
|
||||||
|
dD3hpFG5QZPzmB48ZBmsnmMILLgSMwraAPwkbA4qU2TAeCkAE5WVH3w2m1n95sze
|
||||||
|
gbxZamLbaPj5DedT5yqIjWK4NecTlr7VXFTXWzzAfb+hQtzBN1RmemvbhCgSksAS
|
||||||
|
4huoLAZ6iwpEyuACj4pNmFMyQJQ4PPr54mUkL+btMSTbkOZdMbIrXR/FePvFU/Ug
|
||||||
|
zu9u3QvGm/u2tmpp2Lo/hDgJOhcS4bQjLk7R6Ynq+pi6zQuqpRSCoMEuSz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MLSYufS77FClcuWOfyx08iaqONLNQLLps1HJ0ydCPWKObhL+iKlzapEMh
|
||||||
|
6aAMN/0YR2Fw3+5Cz4Zsn+pe/N6/rqoCVMxS5vsgbmIAZ6537ENMwA==
|
||||||
|
-----END RSA PRIVATE KEY-----
|
Reference in New Issue
Block a user