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

Enable check names component #143

Open
wants to merge 8 commits into
base: development
Choose a base branch
from

Conversation

Harry-Ramsey
Copy link
Contributor

@Harry-Ramsey Harry-Ramsey commented Jan 9, 2025

Enable check names component for TF-PSA-Crypto. Closes #52.

PR checklist

Please remove the segment/s on either side of the | symbol as appropriate, and add any relevant link/s to the end of the line.
If the provided content is part of the present PR remove the # symbol.

  • changelog provided | not required because: testing enhancement.
  • framework PR provided Mbed-TLS/mbedtls-framework: #117
  • mbedtls PR provided Mbed-TLS/mbedtls: #9915
  • tests provided | not required because:

Notes for the submitter

Please refer to the contributing guidelines, especially the
checklist for PR contributors.

Help make review efficient:

  • Multiple simple commits
    • please structure your PR into a series of small commits, each of which does one thing
  • Avoid force-push
    • please do not force-push to update your PR - just add new commit(s)
  • See our Guidelines for Contributors for more details about the review process.

@Harry-Ramsey Harry-Ramsey self-assigned this Jan 9, 2025
@Harry-Ramsey Harry-Ramsey added enhancement New feature or request size-m Estimated task size: medium (~1w) needs-review Every commit must be reviewed by at least two team members needs-reviewer This PR needs someone to pick it up for review labels Jan 9, 2025
@Harry-Ramsey
Copy link
Contributor Author

The failures reported here are to do with the test successfully running but have been propogated to TF-PSA-Crypto.

@ronald-cron-arm
Copy link
Contributor

ronald-cron-arm commented Jan 14, 2025

The failures reported here are to do with the test successfully running but have been propogated to TF-PSA-Crypto.

I am not sure to understand. What is needed for the new component tf_psa_crypto_check_names to run successfully? We cannot merge this PR in that state.

@Harry-Ramsey
Copy link
Contributor Author

The failures reported here are to do with the test successfully running but have been propogated to TF-PSA-Crypto.

I am not sure to understand. What is needed for the new component tf_psa_crypto_check_names to run successfully? We cannot merge this PR in that state.

Sorry, there was an extreme number of errors much higher than expected. I forgot to remove code from check_names.py which overwrote selected paths resulting in these errors.

@Harry-Ramsey Harry-Ramsey force-pushed the check-names branch 3 times, most recently from 41311a8 to 12a649f Compare January 15, 2025 11:07
@ronald-cron-arm
Copy link
Contributor

Regarding

#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && defined(MBEDTLS_USE_PSA_CRYPTO) && \   
    !(defined(PSA_WANT_ALG_SHA_1) || defined(PSA_WANT_ALG_SHA_256) || defined(PSA_WANT_ALG_SHA_512))
#error "MBEDTLS_SSL_PROTO_TLS1_2 defined, but not all prerequisites"            
#endif 

in ./drivers/builtin/src/check_crypto_config.h, this should rather be in mbedtls:include/mbedtls/check_config.h. No need for defined(MBEDTLS_USE_PSA_CRYPTO) as MBEDTLS_USE_PSA_CRYPTO is always on now. Thus just:

#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \   
    !(defined(PSA_WANT_ALG_SHA_1) || defined(PSA_WANT_ALG_SHA_256) || defined(PSA_WANT_ALG_SHA_512))
#error "MBEDTLS_SSL_PROTO_TLS1_2 defined, but not all prerequisites"            
#endif

@ronald-cron-arm
Copy link
Contributor

Regarding MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS in crypto_config.h and ecp.h I think we can just remove the references to MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS. Looking in ssl.h at the documentation of the TLS functions that return MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS I do not feel the need to change their documentation because of the removals of the comments in TF-PSA-Crypto.

@ronald-cron-arm
Copy link
Contributor

Regarding psa_util_internal.h:

#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
extern const mbedtls_error_pair_t psa_to_ssl_errors[7];
#endif

can be moved to library/ssl_misc.h. It is defined in library/ssl_tls.c.

@ronald-cron-arm
Copy link
Contributor

In entropy_poll.c

#if defined(MBEDTLS_TIMING_C)
#include "mbedtls/timing.h"
#endif

can just be removed it seems.

@ronald-cron-arm
Copy link
Contributor

ronald-cron-arm commented Jan 17, 2025

In crypto_config.h the note:

 * \note If MBEDTLS_TIMING_C is set - to enable the semi-portable timing
 *       interface - timing.c will include time.h on suitable platforms
 *       regardless of the setting of MBEDTLS_HAVE_TIME, unless
 *       MBEDTLS_TIMING_ALT is used. See timing.c for more information.

can be just removed. We already have the same note in MBEDTLS_TIMING_C documentation in mbedtls_config.h.

This commit adds a new check-names component to TF-PSA-Crypto.

Signed-off-by: Harry Ramsey <[email protected]>
@Harry-Ramsey
Copy link
Contributor Author

Harry-Ramsey commented Jan 20, 2025

Just need to create a Mbed TLS pull request where I add the necessary checks and this can be reviewed.

@valeriosetti valeriosetti removed the needs-reviewer This PR needs someone to pick it up for review label Jan 20, 2025
@ronald-cron-arm
Copy link
Contributor

ronald-cron-arm commented Jan 20, 2025

Regarding the MBEDTLS_SSL_MAX_... symbols in cipher.h, after some discussions with @gilles-peskine-arm, I propose to remove the comments in cipher.h and add some unit tests in test_suite_ssl that assert that MBEDTLS_SSL_MAX... >= MBEDTLS_MAX_.... A static_checks() test function similar to the one in test_suite_psa_crypto.function should do the job.

@gilles-peskine-arm
Copy link
Contributor

gilles-peskine-arm commented Jan 20, 2025

some unit tests in test_suite_ssl that assert that MBEDTLS_SSL_MAX... >= MBEDTLS_MAX_....

I'm actually not sure if those tests are still relevant. The comments date back from before MBEDTLS_USE_PSA_CRYPTO, and it's technically a bug that we didn't update it to take MBEDTLS_USE_PSA_CRYPTO into account (but I don't propose to fix a comment in an LTS branch that's about values that will never change in that branch). Since that was introduced, in theory, PSA could have defined larger values. When MBEDTLS_USE_PSA_CRYPTO is active, the cipher.h constants are not relevant. So if we wanted to do things perfectly right:

  • Pre-PSA versions of Mbed TLS should assert MBEDTLS_SSL_MAX_xxx against the constants from cipher.h.
  • Mbed TLS 2.18 (?) through 3.6 should assert MBEDTLS_SSL_MAX_xxx against the constants from cipher.h when MBEDTLS_USE_PSA_CRYPTO is disabled, and against constants from psa/crypto_sizes.h when MBEDTLS_USE_PSA_CRYPTO is enabled.
  • Mbed TLS 4.0 should assert MBEDTLS_SSL_MAX_xxx against constants from psa/crypto_sizes.h.

In practice the values defined in ssl_misc.h are very unlikely to need changing. And if they do, it'll be part of a large project where we'll know that a lot of buffer sizes need to be updated.

So I'd be ok with not adding any assertions. And I'm a bit doubtful about adding assertions to 4.0 that mention the deprecated constants from cipher.h. We shouldn't start using deprecated symbols in new code.

The PSA values to compare against would be:

MBEDTLS_SSL_MAX_BLOCK_LENGTH >= PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE
MBEDTLS_SSL_MAX_IV_LENGTH >= PSA_CIPHER_IV_MAX_SIZE
MBEDTLS_SSL_MAX_KEY_LENGTH >= no suitable macro — mind you cipher.h didn't have one either

@ronald-cron-arm
Copy link
Contributor

Do you mean: MBEDTLS_SSL_MAX_BLOCK_LENGTH >= PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE (greater or equal than)?

@gilles-peskine-arm
Copy link
Contributor

Oops, yes, I had the comparisons the wrong way round. I edited my comment.

@mpg
Copy link
Contributor

mpg commented Jan 21, 2025

I don't think those tests would be logically correct. It may very well be that in the future we'll add a cipher with variable IV length and TLS only uses a certain IV size that's smaller than the maximum, and then SSL_MAX_IV_LENGTH will be smaller than PSA_CIPHER_IV_MAX_SIZE and that would be perfectly OK. Similar thought about key length, and block size (we could have a cipher supported in PSA that's not used by any TLS ciphersuite).

So I'm actually opposed to adding those assertions.

@ronald-cron-arm
Copy link
Contributor

I don't think those tests would be logically correct. It may very well be that in the future we'll add a cipher with variable IV length and TLS only uses a certain IV size that's smaller than the maximum, and then SSL_MAX_IV_LENGTH will be smaller than PSA_CIPHER_IV_MAX_SIZE and that would be perfectly OK. Similar thought about key length, and block size (we could have a cipher supported in PSA that's not used by any TLS ciphersuite).

So I'm actually opposed to adding those assertions.

Thanks, I think I understand better the ins and outs of the MBEDTLS_SSL_MAX_ macros now. If I understand correctly, the comments in cipher.h stating that MBEDTLS_MAX_ macros should be kept in sync with the MBEDTLS_SSL_MAX_ ones in ssl_misc.h are actually at least misleading thus we are just going to remove them.

@@ -1675,7 +1665,7 @@
*
* Uncomment this macro to enable restartable ECC computations.
*/
//#define MBEDTLS_ECP_RESTARTABLE
// #define MBEDTLS_ECP_RESTARTABLE
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// #define MBEDTLS_ECP_RESTARTABLE
//#define MBEDTLS_ECP_RESTARTABLE

This commit removes macro in the crypto_config.h which relate to Mbed
TLS. In particular macros like MBEDTLS_TLS* from TF-PSA-Crypto.

Signed-off-by: Harry Ramsey <[email protected]>
This commit removes references to the macro
MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS from TF-PSA-Crypto as it is defined
more appropriately in Mbed TLS.

Signed-off-by: Harry Ramsey <[email protected]>
This commit removes references to the macro MBEDTLS_TIMING_C from
TF-PSA-Crypto as it is defined more appropriately in Mbed TLS.

Signed-off-by: Harry Ramsey <[email protected]>
This commit moves macro checks specifically for Mbed TLS from
TF-PSA-Crypto to Mbed TLS where they more approriately belong.

Signed-off-by: Harry Ramsey <[email protected]>
This commit removes MBEDTLS_SSL_TLS_C, MBEDTLS_X509_USE_C and
MBEDTLS_X509_CREATE_C from TF-PSA-Crypto to Mbed TLS where they more
appropriately belong.

Signed-off-by: Harry Ramsey <[email protected]>
This commit removes comments which are no longer accurate about keeping
IV and block lengths the same between Mbed TLS and TF-PSA-Crypto.

Signed-off-by: Harry Ramsey <[email protected]>
@valeriosetti
Copy link
Contributor

Note: as we agreed, I cherry-picked e7caf8c in #165 ;)

This commit updates the framework for check-names.py to independently
run for TF-PSA-Crypto.amework for check-names.py

Signed-off-by: Harry Ramsey <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-review Every commit must be reviewed by at least two team members size-m Estimated task size: medium (~1w)
Projects
Status: TF-PSA-Crypto all.sh 1 - basic-checks
Development

Successfully merging this pull request may close these issues.

Add name checks
5 participants