arm-trusted-firmware/tools
Sandrine Bailleux bb3b0c0b09 fix(cert-create): fix key loading logic
When key_load() attempts to load the key from a file and it fails to
open this file, the 'err_code' output argument is set to
'KEY_ERR_OPEN' error code. However, it is incorrectly overwritten
later on with 'KEY_ERR_NONE' or 'KEY_ERR_LOAD'.

The latter case messes up with the key creation scenario. The
'KEY_ERR_LOAD' error leads the tool to exit, when it should attempt to
create the said key file if invoked with the --new-keys/-n option.

Note that, to complicate matters further, which of 'KEY_ERR_OPEN' or
'KEY_ERR_NONE' values is returned by key_load() depends on the version
of OpenSSL in use:

 - If using v3+, KEY_ERROR_LOAD is returned.

 - If using <v3, KEY_ERROR_NONE is returned as a result of the key
   pair container being initialized by key_new().

This patch fixes this bug and also takes the opportunity to refactor
key_load() implementation to (hopefully) make it more straight-forward
and easier to reason about.

Fixes: 616b3ce27d "feat(cert-create): add pkcs11 engine support"
Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
Reported-by: Wenchen Tan <xtaens@qq.com>
Change-Id: Ia78ff442e04c5ff98e6ced8d26becbd817a8ccb7
2023-10-19 11:34:55 +02:00
..
amlogic meson: Rename platform directory to amlogic 2019-09-05 10:39:25 +01:00
cert_create fix(cert-create): fix key loading logic 2023-10-19 11:34:55 +02:00
conventional-changelog-tf-a Merge "build(changelog): pretend scope-less build changes have the build scope" into integration 2023-06-20 15:16:26 +02:00
encrypt_fw build(tools): avoid unnecessary link 2023-07-05 13:00:18 +02:00
fiptool feat(fiptool): add ability to build statically 2023-09-25 18:13:10 +02:00
marvell/doimage refactor(mbedtls): avoid including MBEDTLS_CONFIG_FILE 2023-02-21 11:09:47 +00:00
memory chore(bl): add UNALIGNED symbols for TEXT/RODATA 2023-06-12 12:50:08 +02:00
nxp fix(tree): correct some typos 2023-05-09 15:57:12 +01:00
renesas feat(plat/rcar3): change the memory map for OP-TEE 2021-09-12 01:13:48 +02:00
sptool feat(sptool): generate ARM_BL2_SP_LIST_DTS file from sp_layout.json 2023-08-11 11:49:47 +01:00
stm32image feat(st): update stm32image tool for header v2 2022-03-21 10:53:55 +01:00