Skip to content

Compilation issues with mbedtls_x509write_crt_set_key_identifier due to conditional dependency on MBEDTLS_MD_CAN_SHA1 #10096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
PragatiGarg-eaton opened this issue Mar 27, 2025 · 2 comments
Labels
api-break This issue/PR breaks the API and must wait for a new major version component-x509 enhancement needs-design-approval size-s Estimated task size: small (~2d)

Comments

@PragatiGarg-eaton
Copy link

Description: Under the file modules/crypto/mbedtls/library/x509write_crt.c, the function mbedtls_x509write_crt_set_key_identifier is conditionally included based on the configuration MBEDTLS_MD_CAN_SHA1. When attempting to disable the vulnerable cipher MBEDTLS_MD_CAN_SHA1, I encountered compilation issues because I need to use the mbedtls_x509write_crt_set_key_identifier function to generate certificates.

Steps to Reproduce:
Disable the configuration MBEDTLS_MD_CAN_SHA1.
Attempt to compile the code that uses mbedtls_x509write_crt_set_key_identifier.
Expected Behavior: The code should compile successfully without requiring MBEDTLS_MD_CAN_SHA1.

Actual Behavior: Compilation fails due to the conditional dependency on MBEDTLS_MD_CAN_SHA1.

Questions:
Why is there a dependency on MBEDTLS_MD_CAN_SHA1 for the mbedtls_x509write_crt_set_key_identifier function?
How can this issue be resolved to allow the use of mbedtls_x509write_crt_set_key_identifier without enabling MBEDTLS_SHA1_C?

Additional Information:
Zephyr version: 3.6.0
MbedTLS version: 3.5.2

@prayassamriya
Copy link

Some more context:
We understand that as per APIs provided, mbedtls_x509write_crt_set_key_identifier is supposed to be called only if SHA1 is supported however what is the rationale for not extending the capability to SHA256 or other secure hashing schemes. We would like to get rid of SHA1 completely however this API blocks us from removing SHA1 from the mbedtls configuration.
Note: We know that setting key identifier is optional during the certificate generation however its still nice to have for better identity management of certificate chain.

ret = mbedtls_x509write_crt_set_subject_key_identifier(&crt);

@minosgalanakis minosgalanakis added enhancement needs-design-approval component-x509 api-break This issue/PR breaks the API and must wait for a new major version labels Apr 2, 2025
@gilles-peskine-arm
Copy link
Contributor

RFC 5280 suggests SHA-1 but notes that other similar methods are ok, including using a different algorithm. Hard-coding SHA-1 made sense when this code was written, but I agree that it doesn't make sense now.

For maximum flexibility, the functions should take an extra argument to indicate which hash to use. That's an API change, which is quite a bit of work, and is disruptive in a minor release where we have to keep the old function for backward compatibility. But maybe we could live with a cheaper change in 3.6, and just add a compile-time option? But add a parameter to choose the hash algorithm in the development branch (before it's released as 4.0).

Would you be willing to submit patches if we agree on a design?

@gilles-peskine-arm gilles-peskine-arm moved this to Design needed in Mbed TLS 4.0 planning Apr 7, 2025
@gilles-peskine-arm gilles-peskine-arm added the size-s Estimated task size: small (~2d) label Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-break This issue/PR breaks the API and must wait for a new major version component-x509 enhancement needs-design-approval size-s Estimated task size: small (~2d)
Projects
Status: No status
Status: No status
Status: Design needed
Development

No branches or pull requests

4 participants