mbedtls icon indicating copy to clipboard operation
mbedtls copied to clipboard

fix test fail when seedfile not created

Open yuhaoth opened this issue 3 years ago • 3 comments

when MBEDTLS_ENTROPY_NV_SEED enabled, it depends on seedfile. This patch tests if the file exists and create it.

To reproduce the issue with follow command

scripts/config.py full && make clean && make CFLAGS="-g -Werror " -j8 && ./tests/ssl-opt.sh 

yuhaoth avatar Jun 29 '22 04:06 yuhaoth

I don't think the test programs should create the seedfile. In production, a missing seedfile would be an error. Creating a seedfile in a sample program would be definitely wrong. In a test program, it's acceptable, but suspicious.

Do you mean that's the reason why selftest create the file ?

Therefore I object to this approach. I would prefer to improve the build and test scripts instead. I'm willing to be overridden if there are compelling arguments.

Got it, I will revert it and fix it in ssl-opt.sh

yuhaoth avatar Jun 30 '22 05:06 yuhaoth

Rebased and add segment fault fail for test_suite_ssl when seedfile not created

yuhaoth avatar Jul 24 '22 04:07 yuhaoth

Rebased

yuhaoth avatar Aug 03 '22 07:08 yuhaoth

Rebase

yuhaoth avatar Oct 19 '22 02:10 yuhaoth

Can you create a seedfile in compat.sh as well, while at it?

mpg avatar Oct 19 '22 08:10 mpg

Rebase to resolve conflict

yuhaoth avatar Oct 28 '22 07:10 yuhaoth

rebase to re-trigger tests

yuhaoth avatar Dec 17 '22 10:12 yuhaoth

Switch to new coding style

yuhaoth avatar Jan 13 '23 06:01 yuhaoth

Rebase to retrigger CI tests

yuhaoth avatar Jan 30 '23 07:01 yuhaoth

Rebase to resolve conflicts

yuhaoth avatar Mar 22 '23 05:03 yuhaoth

Rebase to resolve conflict

yuhaoth avatar Mar 27 '23 07:03 yuhaoth

Revisiting this a few months later, I think I've changed my mind.

In production, a missing seedfile would be an error.

Yes. But test environments aren't production: they run production code inside a test setup. So the real question is where exactly is the boundary between the production code, and the test setup.

Creating a seedfile in a sample program would be definitely wrong.

Indeed, but that's not what this was about.

In a test program, it's acceptable, but suspicious.

That depends exactly what the test program encompasses: is it just production code plus some dispatch code to call the production code with the desired inputs? Or is it also code that simulates the setup of a platform?

ssl_client2 and ssl_server2 are more than just production code plus dispatch code. They already contain things that are specifically for testing, such as a non-cryptographic implementation of mbedtls_psa_external_get_random (which is not something that must ever get into production). So creating a seedfile in these programs is fine.

Similarly, the unit test framework could create the seedfile. Specifically in mbedtls_test_platform_setup. (In fact the reason I thought about this today is that I'm working on tests for MBEDTLS_PSA_INJECT_ENTROPY, which requires a seed file like MBEDTLS_ENTROPY_NV_SEED, but a different one that's a bit more obscure. And there I decided to create the seed file in the platform setup.)

I'm willing to be overridden if there are compelling arguments.

One argument is “I'm a developer who isn't intimately familar with the project, I'm trying to run a test specifically for the feature I'm working on, and it's failing in some mysterious way, but only in some configurations, at the line PSA_INIT() which does something that's utterly mysterious to me”. Even for people on the Mbed TLS development team, we've had times when psa_crypto_init failed and it took us some time to realize that the problem was a missing (or too small) seed file. So I'm now thinking that facilitating the life of contributors (especially occasional contributors) is a pretty compelling argument.

I would welcome more opinions on the topic.

gilles-peskine-arm avatar Apr 28 '23 22:04 gilles-peskine-arm

rebase to resolve conflicts

yuhaoth avatar May 05 '23 10:05 yuhaoth

Rebase to resolve conflict

yuhaoth avatar Nov 16 '23 09:11 yuhaoth