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

Create seedfile automatically in test code #3575

Open
gilles-peskine-arm opened this issue Aug 18, 2020 · 1 comment · May be fixed by #5989
Open

Create seedfile automatically in test code #3575

gilles-peskine-arm opened this issue Aug 18, 2020 · 1 comment · May be fixed by #5989
Labels
component-platform Portability layer and build scripts enhancement

Comments

@gilles-peskine-arm
Copy link
Contributor

When MBEDTLS_ENTROPY_NV_SEED is enabled, any code that calls mbedtls_entropy_init needs an existing seedfile of sufficient size.

MBEDTLS_ENTROPY_NV_SEED is disabled by default, but it is enabled in the full config.

Several of our test scripts create a seedfile, including all.sh and basic-build-test.sh. So everything just works in CI runs. But when running tests manually, this can be a gotcha.

Historically this has mostly worked invisibly because test_suite_entropy happens not to require a valid seedfile on entry and to leave a valid seedfile behind when it passes, and the other test suites that call the entropy module come after entropy in alphabetical order. But if you enable MBEDTLS_USE_PSA_CRYPTO (which config.py full does) then test_suite_cipher calls psa_crypto_init which obtains entropy and therefore requires a seedfile. Since cipher comes before entropy, if you haven't created a seedfile manually, psa_crypto_init() fails.

Another failure reason is when the seedfile is too small. The size of the seedfile is determined by
the hash that the entropy module uses. If you run tests with either MBEDTLS_SHA512_C disabled or MBEDTLS_ENTROPY_FORCE_SHA256 enabled, and then run tests with MBEDTLS_SHA512_C enabled or MBEDTLS_ENTROPY_FORCE_SHA256 disabled, and MBEDTLS_ENTROPY_NV_SEED enabled in both cases, the second test run starts with a seedfile that's too small, and again it will fail if something needs entropy before test_suite_entropy.

In production, the seedfile should contain cryptographic-quality random data. In tests, this isn't necessary. So I think we should add automatic seedfile creation to the test suite, but not to the sample programs.

The seedfile read/write functions are configurable, and if they're set to non-default values, they might not access a file via stdio. So the test startup code should only work in terms of the mbedtls_nv_seed_write and mbedtls_nv_seed_read abstractions.

@yuhaoth
Copy link
Contributor

yuhaoth commented Apr 6, 2023

#5989 can fix this

@yuhaoth yuhaoth linked a pull request Apr 6, 2023 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-platform Portability layer and build scripts enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants