Skip to content

Restrict MBEDTLS_X509_RSASSA_PSS_SUPPORT #8154

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
daverodgman opened this issue Sep 1, 2023 · 6 comments · May be fixed by #10130
Open

Restrict MBEDTLS_X509_RSASSA_PSS_SUPPORT #8154

daverodgman opened this issue Sep 1, 2023 · 6 comments · May be fixed by #10130
Assignees
Labels
api-break This issue/PR breaks the API and must wait for a new major version component-crypto Crypto primitives and low-level interfaces enhancement size-s Estimated task size: small (~2d)

Comments

@daverodgman
Copy link
Contributor

daverodgman commented Sep 1, 2023

Restrict the MBEDTLS_X509_RSASSA_PSS_SUPPORT option, and corresponding code from the library, to only what PSA supports (no funny hash combination or force salt length).

@daverodgman daverodgman added enhancement component-crypto Crypto primitives and low-level interfaces api-break This issue/PR breaks the API and must wait for a new major version size-s Estimated task size: small (~2d) labels Oct 11, 2023
@mpg mpg changed the title Remove MBEDTLS_X509_RSASSA_PSS_SUPPORT Restrict MBEDTLS_X509_RSASSA_PSS_SUPPORT Nov 28, 2023
@gilles-peskine-arm gilles-peskine-arm moved this to Implementation needed in Mbed TLS 4.0 planning Jun 19, 2024
@yanesca yanesca removed this from Mbed TLS Epics Aug 27, 2024
@yanesca yanesca moved this to 4.0 - PSA Crypto always on in Mbed TLS Backlog Aug 27, 2024
@github-project-automation github-project-automation bot moved this to Mbed TLS 4.0 MUST in Backlog for Mbed TLS Aug 30, 2024
@mpg
Copy link
Contributor

mpg commented Mar 28, 2025

@valeriosetti valeriosetti self-assigned this Mar 31, 2025
@valeriosetti
Copy link
Contributor

valeriosetti commented Apr 1, 2025

See https://github.com/Mbed-TLS/mbedtls/blob/development/docs/architecture/psa-migration/psa-limitations.md#rsa-pss-parameters for context.

If I understood correctly this document explains the difference between legacy RSA and PSA for what concerns RSA-PSS signature. However this issue is about MBEDTLS_X509_RSASSA_PSS_SUPPORT and to me this means that it only concerns with X.509.
On a first read I found this section which looked related to what I should do in this issue:

Both the existing mbedtls_ API and the PSA API support only MGF1 as the generation function (and only 0xBC as the trailer field), but there are discrepancies in handling the salt length and which of the various hash algorithms can differ from each other.

Reading that document further though I found this paragraph:

Note: since X.509 parsing ensures that message hash = encoding hash, and mbedtls_pk_verify_ext() uses encoding hash = mgf1 hash, it looks like all three hash algorithms must be equal, which would be good news as it would match a limitation of the PSA API.

So albeit legacy and PSA support different options, it seems that X.509 already checks and enforces the "PSA way" (i.e. the stricter in terms of requirements). It seems to me that the only missing part that should be checked is the salt length. Am I wrong?

@mpg
Copy link
Contributor

mpg commented Apr 2, 2025

Good question, I agree it's not very clear from the issue description.

it seems that X.509 already checks and enforces the "PSA way"

Not entirely. Part of the enforcement is done on the X.509 side (message hash = encoding hash) but the other (encoding hash = mgf1 hash) is done on the PK side. We'll like everything to be enforce on the X.509 side.

Looking at the code, it actually goes a bit deeper than that: currently the X.509 code uses mbedtls_pk_rsassa_pss_options which is going away in 4.0/1.0. So we should remove that reliance. Unfortunately so far PK insists on getting passed non-NULL options for PSS.

I suggest the following course of action, trying to avoid inter-dependent crypto/x509 PRs:

  1. tf-psa-crypto: change pk_verify_ext() so that it always accepts NULL options. When the type argument is PSS, options are simply ignored and PSA is always used (that is, here we remove both the #if and the if checks, and remove the corresponding else branch - and a few lines above obviously remove the options == NULL check). (Crucially we still accept non-NULL options, so that the X.509 code keeps working unchanged, we just ignored them.)
  2. mbedtls: change the X.509 code to entirely remove signature options: that is, remove the sig_opts field from the CRT and CSR structs, as well the the argument from mbedtls_x509_get_sig_alg(). Now mbedtls_x509_get_rsassa_pss_params() has only one output parameter: *md_alg, but it does check that what's currently mgf_md would be equal to it (and ignores salt_len beyond just parsing it to ensure things are properly formatted).

Note that ensuring md_alg == mgf_md will be slightly subtle since the second is optional, defaulting to SHA-1. So we need to remember not to skip the check if optional parameters are omitted.

Note on this issue's scope: the title and description make it look like it's about X.509 but the labels say component-crypto. Given this existing inconsistency, I'm not feeling bad about suggesting a plan that involves changes on both sides :)

@gilles-peskine-arm
Copy link
Contributor

Note that ensuring md_alg == mgf_md will be slightly subtle since the second is optional, defaulting to SHA-1.

A SHA-1 default has been obsolete for a while. Maybe we should stop accepting certificates where the PSS parameters are omitted? Or would that be problematic even today, maybe for some root CA?

@valeriosetti
Copy link
Contributor

valeriosetti commented Apr 10, 2025

tf-psa-crypto: change pk_verify_ext() so that it always accepts NULL options. When the type argument is PSS, options are simply ignored and PSA is always used (that is, here we remove both the #if and the if checks, and remove the corresponding else branch - and a few lines above obviously remove the options == NULL check). (Crucially we still accept non-NULL options, so that the X.509 code keeps working unchanged, we just ignored them.)

@mpg thanks for the workflow, but I have a question. Having the 2 PRs independent from each other it means that in the tf-psa-crypto one I cannot remove struct mbedtls_pk_rsassa_pss_options, which after this issue would become unused. IMO we might need a follow-up issue (+PR) which removes things like this that would then become unused. Am I wrong?

@mpg
Copy link
Contributor

mpg commented Apr 11, 2025

Yes, that sounds correct. I think it's one of this situations where we can either have only 2 PRs but then they're inter-dependent, or we can avoid the inter-dependency but then need 3 PRs. Considering inter-dependent PRs are a pain, I think it's worth trying the 3-PR way here.

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-crypto Crypto primitives and low-level interfaces enhancement size-s Estimated task size: small (~2d)
Projects
Status: Mbed TLS 4.0 MUST
Status: Implementation needed
Status: No status
Development

Successfully merging a pull request may close this issue.

4 participants