Skip to content
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

Do not perform adjustments on legacy crypto from PSA, when MBEDTLS_PSA_CRYPTO_CLIENT && !MBEDTLS_PSA_CRYPTO_C #9138

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

valeriosetti
Copy link
Contributor

@valeriosetti valeriosetti commented May 15, 2024

Description

Resolves #9126.

PR checklist

  • changelog TODO as suggested here
  • 3.6 backport TODO as soon as this PR gets to a good point.
  • 2.28 backport not required
  • tests not required

@valeriosetti valeriosetti self-assigned this May 15, 2024
@valeriosetti valeriosetti added needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review priority-high High priority - will be reviewed soon size-xs Estimated task size: extra small (a few hours at most) labels May 15, 2024
@valeriosetti valeriosetti added this to To Do in Roadmap Board for Mbed TLS via automation May 15, 2024
* (i.e. PSA_CRYPTO_CLIENT && !PSA_CRYPTO_C) if TLS/X509/PK rely on PSA APIs
* (i.e. USE_PSA_CRYPTO). */
#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) && \
defined(MBEDTLS_USE_PSA_CRYPTO)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it really mandatory to gate this with MBEDTLS_USE_PSA_CRYPTO as well? I am thinking about a use case where the client is just interested in doing Crypto, without really the need of doing TLS, so they won't care much about setting (or not setting) MBEDTLS_USE_PSA_CRYPTO. I guess it's more of a question for @gilles-peskine-arm though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it were only for crypto operations then I would agree with you, but for what concerns PK/TLS (and perhaps also MD/cipher) they might size buffers internally depending on USE_PSA or not. In other words, in a case where !USE_PSA, if legacy symbols are not set from the PSA ones, TLS/PK might under-estimate the size of some buffers.
This is just my guess though. I'm sure @gilles-peskine-arm or @mpg can provide a better answer :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Valerio's assessment. Note that in 4.0 USE_PSA will go away, and when that happens things will get simpler, but in the meantime (and in 3.6) I think we still need it to gate this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, thanks. It makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon reflection, the goal of config_adjust_legacy_from_psa.h is to ensure that if PSA wants a crypto feature then it's provided somehow, either through a PSA driver or through the a built-in implementation. This is independent of USE_PSA_CRYPTO. When PSA_CRYPTO_CLIENT && !PSA_CRYPTO_C, all PSA crypto feature come from the server, so config_adjust_legacy_from_psa.h is useless, regardless of what's using it.

they might size buffers internally depending on USE_PSA or not

That would also break driver-only configurations. So this is only a concern for mechanisms where driver-only configurations are not supported. The only mechanism for which the limitations affect basic key management (as opposed to more advanced capabilities) is RSA. The pk/x509/ssl code gates its RSA support on whether MBEDTLS_RSA_C is enabled, not on PSA_WANT_*RSA*, whether or not MBEDTLS_USE_PSA_CRYPTO is enabled. So when PSA crypto is client-server, on the client, you won't be able to use the PSA RSA if MBEDTLS_RSA_C is disabled, but there should be no undersized buffers.

This does mean that there's an incompatible change here: if you had PSA_WANT_ALG_RSA_xxx and PSA_WANT_KEY_PAIR_RSA_xxx and MBEDTLS_PSA_CRYPTO_CLIENT and !MBEDTLS_PSA_CRYPTO_C and !MBEDTLS_USE_PSA_CRYPTO in 3.6.0, then MBEDTLS_RSA_C was automatically enabled and RSA worked (through the local built-in implementation). (With the same configuration but USE_PSA_CRYPTO enabled, RSA would not work in pk/x509/TLS since the code would call PSA functions.) We can make this change, even in an LTS, because CLIENT && !C is documented as experimental, it's a weird configuration in the first place, and there's an easy workaround of explicitly requesting MBEDTLS_RSA_C. But we should document it in a changelog entry.

Therefore, I think (but I'd like @mpg's opinion on this as well) the best course of action is:

  • Don't check MBEDTLS_USE_PSA_CRYPTO here.
  • Explain the consequences of this check in a comment.
  • Add a changelog entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think (but I'd like @mpg's opinion on this as well) the best course of action is

@mpg do you agree with the plan than @gilles-peskine-arm proposed? :)

@valeriosetti valeriosetti force-pushed the issue9126 branch 2 times, most recently from da4a65d to f235d16 Compare May 15, 2024 12:04
@valeriosetti valeriosetti requested review from mpg and adeaarm May 16, 2024 12:07
@valeriosetti valeriosetti removed needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review labels May 16, 2024
@valeriosetti valeriosetti moved this from To Do to In Review in Roadmap Board for Mbed TLS May 16, 2024
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-review Every commit must be reviewed by at least two team members, priority-high High priority - will be reviewed soon size-xs Estimated task size: extra small (a few hours at most)
Projects
Development

Successfully merging this pull request may close these issues.

Do not perform adjustments on legacy crypto from PSA, when MBEDTLS_PSA_CRYPTO_CLIENT && !MBEDTLS_PSA_CRYPTO_C
4 participants