Add proper replacement for MBEDTLS_PK_ECKEY #825

Open
opened 2026-06-30 09:28:52 -05:00 by MathisMARION · 2 comments
MathisMARION commented 2026-06-30 09:28:52 -05:00 (Migrated from github.com)

When declaring a certificate profile for Wi-SUN with MbedTLS 3.x, I used .allowed_pks = MBEDTLS_X509_ID_FLAG(MBEDTLS_PK_ECKEY). The migration guide indicates that this maps to a new value MBEDTLS_PK_SIGALG_ECDSA. However, this does not seem to be true in practice as there is still an internal header which defines both MBEDTLS_PK_ECDSA and MBEDTLS_PK_ECKEY while only the former properly maps to MBEDTLS_PK_SIGALG_ECDSA. In practice, Wi-SUN test certificates get refused because internally the public key type is parsed as MBEDTLS_PK_ECKEY which is then refused by x509_profile_check_pk_alg() as being distinct from MBEDTLS_PK_SIGALG_ECDSA.

When declaring a [certificate profile](https://mbed-tls.readthedocs.io/projects/api/en/development/api/file/x509__crt_8h/#_CPPv424mbedtls_x509_crt_profile) for [Wi-SUN](https://wi-sun.org/) with MbedTLS 3.x, I used `.allowed_pks = MBEDTLS_X509_ID_FLAG(MBEDTLS_PK_ECKEY)`. The [migration guide](https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/v1.1.0/docs/1.0-migration-guide.md#changes-to-pk-metadata) indicates that this maps to a new value `MBEDTLS_PK_SIGALG_ECDSA`. However, this does not seem to be true in practice as there is still an [internal header](https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/v1.1.0/include/mbedtls/private/pk_private.h#L21-L29) which defines both `MBEDTLS_PK_ECDSA` and `MBEDTLS_PK_ECKEY` while only the former properly maps to `MBEDTLS_PK_SIGALG_ECDSA`. In practice, Wi-SUN [test certificates](https://github.com/SiliconLabs/wisun-br-linux/tree/main/examples) get refused because internally the public key type is parsed as `MBEDTLS_PK_ECKEY` which is then refused by [`x509_profile_check_pk_alg()`](https://github.com/Mbed-TLS/mbedtls/blob/v4.1.0/library/x509_crt.c#L197) as being distinct from `MBEDTLS_PK_SIGALG_ECDSA`.
gilles-peskine-arm commented 2026-06-30 13:34:21 -05:00 (Migrated from github.com)

The bug is probably actually in X.509 code in mbedtls — I suspect that it's using MBEDTLS_PK_ECKEY in a place where it should have changed to MBEDTLS_PK_SIGALG_ECDSA. Thanks for providing an example certificate.

The bug is probably actually in X.509 code in mbedtls — I suspect that it's using `MBEDTLS_PK_ECKEY` in a place where it should have changed to `MBEDTLS_PK_SIGALG_ECDSA`. Thanks for providing an example certificate.
MathisMARION commented 2026-07-01 03:34:44 -05:00 (Migrated from github.com)

From my understanding, the public key type is parsed by mbedtls_oid_get_pk_alg(), which is currently located in the TF-PSA-Crypto codebase. MbedTLS fetches the key type using mbedtls_pk_get_type(), and casts the result to mbedtls_pk_sigalg_t. To me, the issue lies at the boundary between TF-PSA-Crypto and MbedTLS as internal APIs are still being used.

From my understanding, the public key type is parsed by [`mbedtls_oid_get_pk_alg()`](https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/v1.1.0/utilities/oid.c#L116-L147), which is currently located in the TF-PSA-Crypto codebase. MbedTLS [fetches the key type using `mbedtls_pk_get_type()`, and casts the result to `mbedtls_pk_sigalg_t`](https://github.com/Mbed-TLS/mbedtls/blob/v4.1.0/library/x509_crt.c#L3062-L3065). To me, the issue lies at the boundary between TF-PSA-Crypto and MbedTLS as internal APIs are still being used.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Mbed-TLS/TF-PSA-Crypto#825
No description provided.